diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 5b03010d..e404c5ee 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -30,9 +30,9 @@ class HomeworkCommonController < ApplicationController @homework_type = params[:homework_type].to_i @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) if @search - @homework_commons = @course.homework_commons.where(:homework_type => @homework_type).where("homework_commons.name like '%#{@search}%'").includes(:homework_detail_manual, :homework_group_settings, :student_works) + @homework_commons = @course.homework_commons.where(:homework_type => @homework_type).where("homework_commons.name like '%#{@search}%'") else - @homework_commons = @course.homework_commons.where(:homework_type => @homework_type).includes(:homework_detail_manual, :homework_group_settings, :student_works) + @homework_commons = @course.homework_commons.where(:homework_type => @homework_type) end if @is_teacher @homework_commons = @homework_commons @@ -72,6 +72,9 @@ class HomeworkCommonController < ApplicationController @is_new = params[:is_new] @homeworks = paginateHelper @homework_commons,15 + + @homeworks = @homework_type == 4 ? @homeworks.includes(:homework_detail_manual, :homework_group_settings, [homework_commons_shixuns: :shixun]) : + @homeworks.includes(:homework_detail_manual, :homework_group_settings) #设置at已读 =begin ids = @homeworks.inject([]) do |ids, homework| diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index dd9b1bda..f0150ea4 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,16 @@ class StudentWorkController < ApplicationController @student_work_pages = Paginator.new @student_work_count, @limit, @page @offset ||= @student_work_pages.offset @stundet_works = paginateHelper @stundet_works, @limit + if @stundet_works.size != 0 + @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]) + end 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 55ebb3e7..3cedeb18 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 = "正在提交" @@ -1319,11 +1319,11 @@ module ApplicationHelper def had_commit_studentwork_count homework_common member = homework_common.course.members.where(:user_id => User.current.id).first student_works = homework_common.student_works - if member.present? && member.teacher_course_groups.count > 0 + if member.present? && member.teacher_course_groups.size > 0 group_students = homework_common.course.members.where(:course_group_id => member.teacher_course_groups.pluck(:course_group_id)).map(&:user_id) student_works = student_works.where(:user_id => group_students) end - student_works.where("work_status !=?", 0).count + student_works.where("work_status !=?", 0).size end # 实训作业的有效作品数 @@ -1359,11 +1359,11 @@ module ApplicationHelper def had_uncommit_studentwork_count homework_common member = homework_common.course.members.where(:user_id => User.current.id).first student_works = homework_common.student_works - if member.present? && member.teacher_course_groups.count > 0 + if member.present? && member.teacher_course_groups.size > 0 group_students = homework_common.course.members.where(:course_group_id => member.teacher_course_groups.pluck(:course_group_id)).map(&:user_id) student_works = student_works.where(:user_id => group_students) end - student_works.where("work_status =?", 0).count + student_works.where("work_status =?", 0).size end # 未评阅 @@ -1371,12 +1371,12 @@ module ApplicationHelper #count = StudentWorksScore.find_by_sql("SELECT count(distinct student_work_id) as count FROM student_works_scores sws, student_works sw, homework_commons hc where hc.id =#{homework_common.id} and sw.homework_common_id=hc.id and sw.is_delete = 0 and sws.student_work_id = sw.id and sws.user_id=#{User.current.id};").first.try(:count).to_i member = homework_common.course.members.where(:user_id => User.current.id).first student_works = homework_common.student_works - if member.present? && member.teacher_course_groups.count > 0 + if member.present? && member.teacher_course_groups.size > 0 group_students = homework_common.course.members.where(:course_group_id => member.teacher_course_groups.pluck(:course_group_id)).map(&:user_id) student_works = student_works.where(:user_id => group_students) end - has_comment = StudentWorksScore.where(:student_work_id => student_works.map(&:id), :reviewer_role => [1, 2]).group_by(&:student_work_id).count - student_count = student_works.count + has_comment = StudentWorksScore.where(:student_work_id => student_works.map(&:id), :reviewer_role => [1, 2]).group_by(&:student_work_id).size + student_count = student_works.size return student_count - has_comment end @@ -6570,7 +6570,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)) @@ -6580,7 +6580,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 @@ -7222,8 +7222,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/models/homework_common.rb b/app/models/homework_common.rb index abe09e08..af466de3 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -150,7 +150,7 @@ class HomeworkCommon < ActiveRecord::Base # 作业的实训 def shixun - Shixun.find(self.homework_commons_shixuns.try(:shixun_id)) + homework_commons_shixuns.shixun end # 作业实训过关的数目 diff --git a/app/views/homework_common/_homework_index_list.html.erb b/app/views/homework_common/_homework_index_list.html.erb index 865f7adf..884fd0b9 100644 --- a/app/views/homework_common/_homework_index_list.html.erb +++ b/app/views/homework_common/_homework_index_list.html.erb @@ -61,22 +61,22 @@ <% end %> <% end %> <%# elsif homework_common.homework_type != 4 %> - <% else %> - <% if had_commit_studentwork_count(homework_common) > 0 %> - - <%= link_to had_commit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %> - 已交 - + <%# else %> + <%# if had_commit_studentwork_count(homework_common) > 0 %> + + <%#= link_to had_commit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %> + + <%# if homework_common.homework_type == 4 %> <%# end %> - - <%= link_to had_uncommit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %> - 未交 - - <% end %> + + <%#= link_to had_uncommit_studentwork_count(homework_common), student_work_index_path(:homework => homework_common.id), :class => 'color-orange03 mr5', :target => '_blank' %> + + + <%# end %> <%# elsif homework_common.homework_type == 4 && homework_common.homework_commons_shixuns.shixun %> <%# had_passed_count = had_passed_changllenge_count(homework_common.homework_commons_shixuns.shixun, User.current) %> <%# challenge_count = homework_common.homework_commons_shixuns.shixun.challenges.count %> @@ -129,7 +129,7 @@ <%= link_to "创建项目", new_project_path(:host=>Setting.host_name, :course_id => homework_common.course_id), :class => 'white-btn orange-btn fr mr10 mt8', :target => "_blank" %> <% end %> <% elsif homework_common.homework_type == 4 && homework_common.homework_commons_shixuns.shixun %> - <%= link_to "实训详情", shixun_path(Shixun.find(homework_common.homework_commons_shixuns.shixun_id)), :target => "_blank", :class => 'white-btn orange-btn fr mr10 mt8' %> + <%= link_to "实训详情", shixun_path(homework_common.homework_commons_shixuns.shixun.try(:identifier)), :target => "_blank", :class => 'white-btn orange-btn fr mr10 mt8' %> <% end %> <% if @is_teacher %> @@ -148,7 +148,7 @@
  • <%= link_to '立即发布', publish_notice_homework_common_path(homework_common), :remote => true %>
  • - <% elsif (homework_common.homework_detail_manual.try(:comment_status) == 1 || homework_common.homework_detail_manual.try(:comment_status) == 2) && homework_common.end_time > Time.now %> + <% elsif (homework_common.homework_detail_manual.try(:comment_status) == 1 || homework_common.homework_detail_manual.try(:comment_status) == 2) && homework_common.end_time && homework_common.end_time > Time.now %>
  • <%= link_to '立即截止', end_notice_homework_common_path(homework_common), :remote => true %>
  • diff --git a/app/views/layouts/_board_children_list.html.erb b/app/views/layouts/_board_children_list.html.erb index 779b900a..3871098e 100644 --- a/app/views/layouts/_board_children_list.html.erb +++ b/app/views/layouts/_board_children_list.html.erb @@ -13,9 +13,9 @@ <% unless course_board.children.empty? %>