diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 93bb1d9e9..9c39c526b 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -417,7 +417,7 @@ class BidsController < ApplicationController @homework = HomeworkAttach.new #@homework_list = @bid.homeworks #增加作业按评分排序, - @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC') + @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC") if params[:student_id].present? @temp = [] @homework_list.each do |pro| diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index b1a245dd1..808df65dc 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -1,6 +1,6 @@ class ZipdownController < ApplicationController #查找项目(课程) - before_filter :find_project_by_bid_id, :only => [:assort,:download_user_homework] + before_filter :find_project_by_bid_id, :only => [:assort] #检查权限 #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 924e19447..eef630996 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -138,46 +138,33 @@ module CoursesHelper end #判断制定用户是不是当前课程的老师 def is_course_teacher (user,course) - #people = [] - #course.members.includes(:roles, :user).each do |member| - # role_id = member.roles.first.id - # if TeacherRoles.include? role_id - # people << member.user + course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{user.id}", {:role_id => TeacherRoles}).count != 0 + #修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师 + #is_teacher = false + #@membership = user.memberships.all(:conditions => Project.visible_condition(User.current)) + #@membership.each do |membership| + # unless(membership.project.project_type==0) + # if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) + # is_teacher = true + # end # end #end - #people.include?(user) - #修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师 - is_teacher = false - @membership = user.memberships.all(:conditions => Project.visible_condition(User.current)) - @membership.each do |membership| - unless(membership.project.project_type==0) - if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) - is_teacher = true - end - end - end - is_teacher + #is_teacher end #当前用户是不是指定课程的学生 - def is_cur_course_student? course - #people = [] - #course.members.includes(:roles, :user).each do |member| - # if StudentRoles.include? member.roles.first.id - # people << member.user + def is_cur_course_student course + course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{User.current.id}", {:role_id => StudentRoles}).count != 0 + #修改:能新建占位且不能新建任务的角色判定为学生 + #is_student = false + #@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + #@membership.each do |membership| + # unless(membership.project.project_type==0) + # if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false) + # is_student = true + # end # end #end - #people.include?(User.current) - #修改:能新建占位且不能新建任务的角色判定为学生 - is_student = false - @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) - @membership.each do |membership| - unless(membership.project.project_type==0) - if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false) - is_student = true - end - end - end - is_student + #is_student end #获取当前用户在指定作业下提交的作业的集合 def cur_user_homework_for_bid bid @@ -190,15 +177,4 @@ module CoursesHelper seem_count = homework.rates(:quality).where("rater_id = ?",User.current).count seem_count > 0 end - - #获取指定作业的平均评分 - def homework_score homework - stars_reates = homework.rates(:quality) - sum = 0 - stars_reates.each do |star_reates| - sum = sum + star_reates.stars - end - stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count - format("%.2f", sum * 1.0 / stars_reates_count) - end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 4415b996d..436646196 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -1,9 +1,8 @@ -<% is_student = is_cur_course_student? @bid.courses.first %> +<% is_student = is_cur_course_student(@bid.courses.first) %> <% is_teacher = is_course_teacher User.current,@bid.courses.first %> <% is_evaluation = @bid.is_evaluation == 1 || @bid.is_evaluation == nil %> - <%= form_tag(:controller => 'bids', :action => "show_project", :method => :get) do %>