diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index dd9b1bda..88123b23 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -586,9 +586,9 @@ class StudentWorkController < ApplicationController if @stundet_works.size != 0 if @order == "student_id" - @stundet_works = @stundet_works.includes(:user => {:user_extensions => []}, :project => {}, :student_works_scores => {}).order("user_extensions.student_id #{@b_sort}") + @stundet_works = @stundet_works.includes(:user => {:user_extensions => []}).order("user_extensions.student_id #{@b_sort}") else - @stundet_works = @stundet_works.includes(:user => {:user_extensions => []}, :project => {}, :student_works_scores => {}).order("#{@order} #{@b_sort}") + @stundet_works = @stundet_works.order("#{@order} #{@b_sort}") end end @@ -609,6 +609,14 @@ class StudentWorkController < ApplicationController @student_work_pages = Paginator.new @student_work_count, @limit, @page @offset ||= @student_work_pages.offset @stundet_works = paginateHelper @stundet_works, @limit + @stundet_works = if @homework.homework_type == 1 + @stundet_works.includes(:student_works_scores, [user: :user_extensions]) + elsif @homework.homework_type == 3 + @stundet_works.includes(:student_works_scores, [project: :project_score], [user: :user_extensions]) + elsif @homework.homework_type == 4 + @stundet_works.includes(:student_works_scores, [myshixun: :games], [user: :user_extensions]) + end + @members = @course.members.where(user_id: @stundet_works.pluck(:user_id)).select([:user_id, :course_group_id]) respond_to do |format| format.js format.html { render :layout => 'base_edu'} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4261a406..01a08d95 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -191,7 +191,7 @@ module ApplicationHelper # 分班 def member_group_name members, user_id - member = members.where(:user_id => user_id).first + member = members.find_by_user_id(user_id) group_name = member.try(:course_group_id).to_i == 0 ? '未分班' : member.course_group.name end @@ -269,12 +269,12 @@ module ApplicationHelper end # 实训作品列表的提交状态 - def list_work_status work, homework, member + def list_work_status work, homework, course_group_id if work.work_status == 0 str = "未提交" else if work.compelete_status == 0 - setting_time = homework_group_setting homework, member.try(:course_group_id) + setting_time = homework_group_setting homework, course_group_id end_time = setting_time.end_time.present? ? setting_time.end_time : homework.end_time if end_time > Time.now || (homework.allow_late && !homework.course.is_end) str = "正在提交" @@ -6568,7 +6568,7 @@ def update_shixun_work_status homework else setting = homework.homework_group_settings.where("publish_time < '#{Time.now}'") if setting.blank? - student_works = student_works.where("0=1") + student_works = student_works.none else users = homework.course.members.where(:course_group_id => setting.map(&:course_group_id)) student_works = student_works.where(:user_id => users.map(&:user_id)) @@ -6578,7 +6578,7 @@ def update_shixun_work_status homework myshixuns = Myshixun.where(:shixun_id => shixun.id, :user_id => student_works.map(&:user_id)) myshixuns.each do |myshixun| work = student_works.where(:user_id => myshixun.user_id).first - member = Member.find_by_sql("select course_group_id from members where course_id = #{homework.course_id} and user_id = #{work.user_id}").first + member = homework.course.members.find_by(:user_id => work.user_id) setting_time = homework_group_setting homework, member.try(:course_group_id) games = myshixun.games.where(:challenge_id => challeng_ids) myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil @@ -7220,8 +7220,8 @@ def search_work_member works,name select_works = works else name = name.downcase - select_works = works.select{ |work| work.user.user_extensions[:student_id].to_s.downcase.include?(name) || (work.user[:lastname].to_s.downcase + work.user[:firstname].to_s.downcase).include?(name) - } + select_works = works.joins(user: :user_extensions).where("concat(lastname, firstname) like ? + or student_id like ?", "%#{name}%", "%#{name}%") end select_works end diff --git a/app/views/student_work/_evaluation_un_common_title.html.erb b/app/views/student_work/_evaluation_un_common_title.html.erb index 93b1dd1d..20c85456 100644 --- a/app/views/student_work/_evaluation_un_common_title.html.erb +++ b/app/views/student_work/_evaluation_un_common_title.html.erb @@ -28,7 +28,8 @@ <%= student_work.user.show_real_name %> - <% group_name = new_member_group_name @course.id, student_work.user_id %> + <% group_id = @members.select{|m|m.user_id==student_work.user_id}.first.try(:course_group_id) %> + <% group_name = group_id.to_i == 0 ? '未分班' : @course.course_groups.find_by_id(group_id).name %> <%= group_name %> diff --git a/app/views/student_work/_evaluation_un_group_title.html.erb b/app/views/student_work/_evaluation_un_group_title.html.erb index 0d2842c6..9bc44e9b 100644 --- a/app/views/student_work/_evaluation_un_group_title.html.erb +++ b/app/views/student_work/_evaluation_un_group_title.html.erb @@ -33,7 +33,8 @@ <%= student_work.user.show_real_name %> - <% group_name = member_group_name @homework.course.members, student_work.user_id %> + <% group_id = @members.select{|m|m.user_id==student_work.user_id}.first.try(:course_group_id) %> + <% group_name = group_id.to_i == 0 ? '未分班' : @course.course_groups.find_by_id(group_id).name %> <%= group_name %> diff --git a/app/views/student_work/_evaluation_un_shixun_title.html.erb b/app/views/student_work/_evaluation_un_shixun_title.html.erb index 1666939e..d732fcf7 100644 --- a/app/views/student_work/_evaluation_un_shixun_title.html.erb +++ b/app/views/student_work/_evaluation_un_shixun_title.html.erb @@ -25,8 +25,8 @@ <%= student_work.user.show_real_name %> - <% member = Member.find_by_sql("select course_group_id from members where course_id = #{@homework.course_id} and user_id = #{student_work.user_id}").first %> - <% group_name = member.try(:course_group_id).to_i == 0 ? '未分班' : member.course_group.name %> + <% group_id = @members.select{|m|m.user_id==student_work.user_id}.first.try(:course_group_id) %> + <% group_name = group_id.to_i == 0 ? '未分班' : @course.course_groups.find_by_id(group_id).name %> <%= group_name %> @@ -35,7 +35,7 @@ <%= student_id %> - <% status = list_work_status student_work, @homework, member %> + <% status = list_work_status student_work, @homework, group_id %> <%= status %> diff --git a/app/views/student_work/index.html.erb b/app/views/student_work/index.html.erb index f48bf0b2..9221db7c 100644 --- a/app/views/student_work/index.html.erb +++ b/app/views/student_work/index.html.erb @@ -71,7 +71,7 @@ 参考答案 <% end %> - <% if @is_teacher && @homework.homework_type == 4 && @homework.homework_group_reviews.count > 0 %> + <% if @is_teacher && @homework.homework_type == 4 && @homework.homework_group_reviews.size > 0 %>
  • 查重结果 @@ -100,16 +100,16 @@ <% end %> <%= link_to "导出成绩", student_work_index_path(:homework => @homework.id, :order => @order, :sort => @b_sort, :name => @name, :group => @group, :comment => @comment, :status => @status, :format => 'xls'), :class => 'fr mt3 ml15 white-btn orange-btn', :id => "export_student_work" %> - <% if @homework.homework_detail_manual.try(:comment_status) == 0 || @homework.homework_group_settings.where("publish_time is null or publish_time > '#{Time.now}'").count > 0 %> + <% if @homework.homework_detail_manual.try(:comment_status) == 0 || @homework.homework_group_settings.where("publish_time is null or publish_time > '#{Time.now}'").size > 0 %> <%= link_to '立即发布', publish_notice_homework_common_path(@homework), :remote => true, :class => "white-btn orange-btn fr ml15 mt3" %> <% end %> - <% if (@homework.homework_detail_manual.try(:comment_status) == 1 && @homework.end_time > Time.now) || @homework.homework_group_settings.where("publish_time < '#{Time.now}' and end_time > '#{Time.now}'").count > 0 %> + <% if (@homework.homework_detail_manual.try(:comment_status) == 1 && @homework.end_time > Time.now) || @homework.homework_group_settings.where("publish_time < '#{Time.now}' and end_time > '#{Time.now}'").size > 0 %> <%= link_to '立即截止', end_notice_homework_common_path(@homework), :remote => true, :class => "white-btn orange-btn fr ml15 mt3" %> <% end %> <% if @homework.publish_time.present? && @homework.publish_time < Time.now && @homework.end_time > Time.now && (@homework.homework_type == 1 || @homework.homework_type == 3) %> 撤销发布 <% end %> - <% if @homework.homework_type == 4 && @homework.publish_time.present? && @homework.publish_time < Time.now && @homework.homework_group_reviews.count == 0 %> + <% if @homework.homework_type == 4 && @homework.publish_time.present? && @homework.publish_time < Time.now && @homework.homework_group_reviews.size == 0 %> 代码查重 <% end %> @@ -185,7 +185,7 @@ 不限 - <% has_comment = StudentWorksScore.where(:student_work_id => student_works.map(&:id), :reviewer_role => [1, 2]).group_by(&:student_work_id).count %> + <% has_comment = StudentWorksScore.where(:student_work_id => student_works.map(&:id), :reviewer_role => [1, 2]).group_by(&:student_work_id).size %> > > @@ -198,11 +198,11 @@ 不限 > - + > - + > - +
  • 分班情况: @@ -210,9 +210,9 @@ 不限

    - <% groups.each do |group| %> + <% groups.includes(:members).each do |group| %> > - + <% end %> <% if !@group_teacher %> @@ -255,7 +255,7 @@ <% my_work = cur_user_works_for_homework @homework %> <% if @homework.homework_detail_manual.comment_status == 3 %> <% unless my_work.nil? %> - <% if my_work.user.student_works_evaluation_distributions.where(:student_work_id => @homework.student_works.map(&:id)).count != 0 %> + <% if my_work.user.student_works_evaluation_distributions.where(:student_work_id => @homework.student_works.map(&:id)).size != 0 %> 你在匿评开启之前提交了作品,你的作品正在匿评中 <% else %> 你在匿评开启之后才提交作品,你的作品没有参与匿评 @@ -278,8 +278,8 @@ <% end %>

    - <%= @homework.student_works.where("work_status != 0").count %> 已交 - <%= @homework.course.student.count - @homework.student_works.where("work_status != 0").size %> + <%= @homework.student_works.where("work_status != 0").size %> 已交 + <%= @homework.course.student.size - @homework.student_works.where("work_status != 0").size %> 未交 <% if @homework.homework_detail_manual %> <% if @homework.homework_detail_manual.comment_status == 1 %> diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index 5f521117..d5a9e1e7 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -37,7 +37,7 @@ <% if comment_status == 0 || activity.homework_group_settings.where("publish_time is null or publish_time > '#{Time.now}'").count > 0 %>

  • <%= link_to '立即发布', publish_notice_homework_common_path(activity), :remote => true %>
  • <% end %> - <% if (comment_status == 1 && activity.end_time > Time.now) || activity.homework_group_settings.where("publish_time < '#{Time.now}' and end_time > '#{Time.now}'").count > 0 %> + <% if (comment_status == 1 && activity.end_time && activity.end_time > Time.now) || activity.homework_group_settings.where("publish_time < '#{Time.now}' and end_time > '#{Time.now}'").count > 0 %>
  • <%= link_to '立即截止', end_notice_homework_common_path(activity), :remote => true %>
  • <% end %>
  • <%= link_to "导出成绩", student_work_index_path(:homework => activity, :format => 'xls'), :id => "export_student_work" %>