|
|
|
@ -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)
|
|
|
|
|