From d9e274b2988caa26d39534595f0a0f1a4154a1e2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:48:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/polls_controller.rb | 8 +++--- app/helpers/polls_helper.rb | 19 ++++++++----- app/models/exercise.rb | 10 +++---- app/models/poll.rb | 41 ++++++++++++++++++++++------- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 47ad365f5..e2d0ce3cd 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -88,7 +88,7 @@ class PollsController < ApplicationController @limit = params[:limit] || 15 @polls = @polls.page(@page).per(@limit) - @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) + @polls = @polls&.includes(:published_settings) else @polls = [] end @@ -965,7 +965,7 @@ class PollsController < ApplicationController if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷 @poll_current_user_status = 0 @poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生 - get_poll_answers(@poll_users_list) + get_poll_answers(@poll_users_list, @poll_list_status) if @poll_list_status == 1 @poll_course_groups =[] else @@ -977,7 +977,7 @@ class PollsController < ApplicationController end elsif @user_course_identity > Course::ASSISTANT_PROFESSOR @poll_all_users = @poll.get_poll_exercise_users - get_poll_answers(@poll_all_users) # 未答和已答的 + get_poll_answers(@poll_all_users, @poll_list_status) # 未答和已答的 @poll_course_groups = [] #当为学生的时候,不显示分班情况 @poll_current_user_status = 1 #当前用户的状态,为学生 poll_current_user = @poll_all_users.find_by_group_ids(current_user.id) #当前用户是否开始做问卷(提交/未提交/没做) @@ -988,7 +988,7 @@ class PollsController < ApplicationController end else @poll_all_users = @poll.get_poll_exercise_users - get_poll_answers(@poll_all_users) # 未答和已答的 + get_poll_answers(@poll_all_users, @poll_list_status) # 未答和已答的 @poll_current_user_status = 2 #当前用户非课堂成员 @poll_users_list = [] end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 54a9fe1f0..f6dc3fc89 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -1,10 +1,15 @@ module PollsHelper #获取试卷的已答/未答人数 - def get_poll_answers(poll_users) - @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 - course_all_members_count = poll_users.size - @poll_unanswers = (course_all_members_count - @poll_answers) + def get_poll_answers(poll_users, status) + if status == 1 + @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 + course_all_members_count = poll_users.size + @poll_unanswers = (course_all_members_count - @poll_answers) + else + @poll_answers = 0 + @poll_unanswers = 0 + end end def poll_votes_count(votes,user_ids) @@ -59,7 +64,7 @@ module PollsHelper if is_teacher_or == 1 poll_users_list = poll.all_poll_users(user.id) #当前老师所在班级的全部学生 - get_poll_answers(poll_users_list) + get_poll_answers(poll_users_list, poll_status) ex_pb_time = poll.get_poll_times(user.id,true) poll_publish_time = ex_pb_time[:publish_time] poll_end_time = ex_pb_time[:end_time] @@ -67,7 +72,7 @@ module PollsHelper lock_icon = 0 #不显示锁图标 elsif is_teacher_or == 2 poll_users_list = poll.get_poll_exercise_users - get_poll_answers(poll_users_list) # 未答和已答的 + get_poll_answers(poll_users_list, poll_status) # 未答和已答的 # get_poll_answers(poll_all_users) ex_pb_time = poll.get_poll_times(user.id,false) poll_publish_time = ex_pb_time[:publish_time] @@ -76,7 +81,7 @@ module PollsHelper lock_icon = 0 #不显示锁图标 else poll_users_list = poll.get_poll_exercise_users - get_poll_answers(poll_users_list) # 未答和已答的 + get_poll_answers(poll_users_list, poll_status) # 未答和已答的 poll_publish_time = poll.publish_time poll_end_time = poll.end_time current_status = 4 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e3a89a19a..cc7c99f1b 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -42,7 +42,7 @@ class Exercise < ApplicationRecord if unified_setting #试卷统一设置 exercise_users else - ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id) + ex_group_setting_ids = published_settings.pluck(:course_group_id) exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). where(course_members: {course_group_id: ex_group_setting_ids}) end @@ -59,15 +59,15 @@ class Exercise < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works - exercise_users = self.unified_setting ? self.exercise_users : - self.exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). - where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) + exercise_users = unified_setting ? exercise_users : + exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 def all_exercise_users user_id # member = course.course_member(user_id) - teacher_course_groups = course.teacher_course_groups.where(user_id: user_id) + teacher_course_groups = course.teacher_course_groups.get_user_groups ex_users = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? diff --git a/app/models/poll.rb b/app/models/poll.rb index a055fd656..3edc3c661 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -8,6 +8,7 @@ class Poll < ApplicationRecord has_many :poll_users, -> { where("is_delete != 1") }, :dependent => :delete_all has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 has_many :poll_group_settings, :dependent => :delete_all + has_many :published_settings, -> { poll_group_published }, class_name: "PollGroupSetting" has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all has_many :tidings, as: :container, dependent: :delete_all @@ -44,21 +45,43 @@ class Poll < ApplicationRecord if unified_setting #试卷统一设置 poll_users else - ex_group_setting_ids = poll_group_settings.poll_group_published.pluck(:course_group_id) - poll_users.where(user_id: course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id).uniq) + ex_group_setting_ids = published_settings.pluck(:course_group_id) + poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: ex_group_setting_ids}) end end - # 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 - def all_poll_users(user_id) - poll_all_users = poll_users - group_ids = poll_published_ids(user_id) - if group_ids.present? - poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id).uniq) + # 根据是否统一发布获取作业的作品列表 + def all_works + poll_users = unified_setting ? poll_users : + poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) + end + + # 分班权限的老师可见的作品列表 + def all_poll_users user_id + # member = course.course_member(user_id) + teacher_course_groups = course.teacher_course_groups.get_user_groups + poll_users = self.all_works + # 有分班权限的统计管理的分班且已发布的学生情况 + if teacher_course_groups.exists? + group_ids = teacher_course_groups.pluck(:course_group_id) + poll_users = poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: group_ids}) end - poll_all_users + poll_users end + # # 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 + # def all_poll_users(user_id) + # poll_all_users = poll_users + # group_ids = poll_published_ids(user_id) + # if group_ids.present? + # poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id).uniq) + # end + # poll_all_users + # end + #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def poll_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id)