diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 43d12cadf..68e7f5590 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3190,8 +3190,8 @@ class UsersController < ApplicationController # @courses = @user.courses.visible.where("is_delete =?", 0).order("#{sort_name} #{sort_type}") #@courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") - courses = @user.courses.visible.where("is_delete =?", 0) - syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + @courses = @user.courses.visible.where("is_delete =?", 0) + syllabus_ids = @courses.empty? ? '(-1)' : "(" + @courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" @syllabus = Syllabus.where("id in #{syllabus_ids} or user_id = #{User.current.id}").order("#{sort_name} #{sort_type}") #根据 作业+资源数排序 @@ -3204,11 +3204,12 @@ class UsersController < ApplicationController # end # end @syllabus.each do |syllabus| - syllabus[:infocount] = 0 - courses = courses.select("syllabus_id = #{syllabus.id}") + count = 0 + courses = @courses.select("syllabus_id = #{syllabus.id}") courses.each do |c| - syllabus[:infocount] += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count) + count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count) end + syllabus[:infocount] = count end @c_sort == 1 ? (@syllabus = @syllabus.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabus = @syllabus.sort{|x,y| y[:infocount] <=> x[:infocount]}) @syllabus = sortby_time_countcommon_nosticky @syllabus,sort_name diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index fd3be1369..dd3abe3a8 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -789,6 +789,15 @@ module CoursesHelper result end + def visable_course_homework course + if User.current.admin? || User.current.allowed_to?(:as_teacher,course) + homework_num = course.homework_commons.count + else + homework_num = course.homework_commons.where("publish_time <= '#{Date.today}'").count + end + homework_num + end + def zh_course_role role if role == "TeachingAsistant" result = l(:label_TA) diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 4b618bef1..8f4f443c0 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -1,11 +1,8 @@ <%# course_model %> <% course_file_num = visable_attachemnts_incourse(@course).count%> <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> -<% if User.current.admin? || User.current.allowed_to?(:as_teacher,@course) %> - <% homework_num = @course.homework_commons.count %> -<% else %> - <% homework_num = @course.homework_commons.where("publish_time <= '#{Date.today}'").count %> -<% end %> +<% homework_num = visable_course_homework @course %> +
diff --git a/app/views/users/_user_syllabus_list.html.erb b/app/views/users/_user_syllabus_list.html.erb index 4613e9e18..dbf7e301a 100644 --- a/app/views/users/_user_syllabus_list.html.erb +++ b/app/views/users/_user_syllabus_list.html.erb @@ -19,17 +19,53 @@更新时间:2016-05-05创建老师:豆蔻
+ <%=link_to '', syllabus_path(syllabus.id), :class => 'icons_sy_setting fr', :title => '管理课程' %> +更新时间:<%=format_date syllabus.updated_at %> + 创建老师:<%=syllabus.user.show_name %> + 班级:<%=courses.count %> +
<%=course.name %>
+ 主讲老师:<%=course.teacher.show_name %> + +更新:<%=course.time %>学期:<%=current_time_and_term(course) %>
+<%=studentCount course %>学生|<%=visable_course_homework course %>作业|<%=visable_attachemnts_incourse(@course).count %>资源
+ +