diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 4014a91bd..2e3612b94 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -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 diff --git a/app/views/admin/_course_detail_tr.html.erb b/app/views/admin/_course_detail_tr.html.erb index 1629dda83..189cbc8f6 100644 --- a/app/views/admin/_course_detail_tr.html.erb +++ b/app/views/admin/_course_detail_tr.html.erb @@ -25,7 +25,7 @@ <%= visable_attachemnts_incourse(course).count%>