修改精品课程下-全部课程下 除序列、主讲老师和课程名外的所有列进行排序!

This commit is contained in:
daiao 2016-06-30 11:32:14 +08:00
parent cb11cac506
commit 2eb7aa7c38
3 changed files with 48 additions and 16 deletions

View File

@ -72,10 +72,42 @@ class AdminController < ApplicationController
courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) #{params[:sort]}, c.id desc")
@order = params[:order]
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'time')
courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY time #{params[:sort]},id desc")
courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY time #{params[:sort]}, id desc")
@order = params[:order]
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'post')
courses = Course.find_by_sql("SELECT c.*, count(m.id) count FROM boards b, courses c, messages m WHERE m.board_id = b.id AND b.course_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count #{params[:sort]}, c.id desc")
@order = params[:order]
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'res')
courses = Course.find_by_sql("SELECT c.*, count(at.container_id) cat FROM attachments at, courses c WHERE at.container_type = 'Course' AND at.container_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY cat #{params[:sort]}, id desc")
@order = params[:order]
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'works')
courses = Course.find_by_sql("SELECT c.*, count(hc.id) chc FROM courses c, homework_commons hc,student_works sw WHERE c.id = hc.course_id AND sw.homework_common_id = hc.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY chc #{params[:sort]}, id desc")
@order = params[:order]
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'homework')
courses = Course.find_by_sql("SELECT c.*, count(sw.id) csw FROM student_works sw, courses c, homework_commons hc WHERE c.id = hc.course_id AND sw.id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY csw #{params[:sort]}, id desc")
@order = params[:order]
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'std')
courses = Course.find_by_sql("SELECT c.*, count(sfc.id) sfc FROM courses c, students_for_courses sfc WHERE sfc.course_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY sfc #{params[:sort]}, id desc")
@order = params[:order]
@sort = params[:sort]
elsif params[:sort] && (params[:order] == 'open')
courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY is_public #{params[:sort]},id desc")
@order = params[:order]
@sort = params[:sort]
else
courses = Course.like(name).order('created_at desc')
end

View File

@ -25,7 +25,7 @@
<%= visable_attachemnts_incourse(course).count%>
</td>
<td class="center">
<%= course.boards.first.topics.count + Message.where("board_id =? and parent_id is not ?", course.boards.first.id, nil).count %>
<%= Message.where("board_id =?", course.boards.first.id).count %>
</td>
<td class="center">
<%= course.course_activities.count%>

View File

@ -30,32 +30,32 @@
<th style="width: 105px;">
课程名
</th>
<th style="width: 35px;">
公开
<th style="width: 35px;" class = "<%= @order == 'open' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%= link_to '公开', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'open') %>
</th>
<th style="width: 35px;">
主讲老师
</th>
<th style="width: 30px;">
学生数
<th style="width: 30px;" class = "<%= @order == 'std' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%= link_to '学生数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'std') %>
</th>
<th style="width: 30px;">
作业数
<th style="width: 30px;" class = "<%= @order == 'homework' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%= link_to '作业数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'homework') %>
</th>
<th style="width: 30px;">
作品数
<th style="width: 30px;" class = "<%= @order == 'works' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%= link_to '作品数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'works') %>
</th>
<th style="width: 30px;">
资源数
<th style="width: 30px;" class = "<%= @order == 'res' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%= link_to '资源数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'res') %>
</th>
<th style="width: 30px;">
帖子数
<th style="width: 30px;" class = "<%= @order == 'post' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%= link_to '帖子数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'post') %>
</th>
<th style="width: 40px;" class = "<%= @order == 'act' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%=link_to '动态数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'act') %>
<%= link_to '动态数', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'act') %>
</th>
<th style="width: 40px;" class = "<%= @order == 'time' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
<%=link_to '开课学期', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'time') %>
<%= link_to '开课学期', excellent_all_courses_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'time') %>
</th>
<th style="width: 40px;">
</tr>