|
|
@ -7,6 +7,8 @@ class Exercise < ApplicationRecord
|
|
|
|
has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser"
|
|
|
|
has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser"
|
|
|
|
has_many :exercise_questions, :dependent => :delete_all
|
|
|
|
has_many :exercise_questions, :dependent => :delete_all
|
|
|
|
has_many :exercise_group_settings, :dependent => :delete_all
|
|
|
|
has_many :exercise_group_settings, :dependent => :delete_all
|
|
|
|
|
|
|
|
has_many :published_settings, -> { exercise_group_published }, class_name: "ExerciseGroupSetting"
|
|
|
|
|
|
|
|
|
|
|
|
has_many :tidings, as: :container
|
|
|
|
has_many :tidings, as: :container
|
|
|
|
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all
|
|
|
|
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all
|
|
|
|
|
|
|
|
|
|
|
@ -41,8 +43,8 @@ class Exercise < ApplicationRecord
|
|
|
|
exercise_users
|
|
|
|
exercise_users
|
|
|
|
else
|
|
|
|
else
|
|
|
|
ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id)
|
|
|
|
ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id)
|
|
|
|
course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id)
|
|
|
|
exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
|
|
|
|
exercise_users.where(user_id:course_user_ids)
|
|
|
|
where(course_members: {course_group_id: ex_group_setting_ids})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -55,17 +57,38 @@ class Exercise < ApplicationRecord
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
|
|
|
|
# 根据是否统一发布获取作业的作品列表
|
|
|
|
def all_exercise_users(user_id)
|
|
|
|
def all_works
|
|
|
|
ex_users = exercise_users
|
|
|
|
exercise_users = self.unified_setting ? self.exercise_users :
|
|
|
|
group_ids = common_published_ids(user_id)
|
|
|
|
self.exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
|
|
|
|
if group_ids.present?
|
|
|
|
where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)})
|
|
|
|
ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_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)
|
|
|
|
|
|
|
|
ex_users = self.all_works
|
|
|
|
|
|
|
|
# 有分班权限的统计管理的分班且已发布的学生情况
|
|
|
|
|
|
|
|
if teacher_course_groups.exists?
|
|
|
|
|
|
|
|
group_ids = teacher_course_groups.pluck(:course_group_id)
|
|
|
|
|
|
|
|
ex_users = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id").
|
|
|
|
where(course_members: {course_group_id: group_ids})
|
|
|
|
where(course_members: {course_group_id: group_ids})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ex_users
|
|
|
|
ex_users
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
|
|
|
|
|
|
|
|
# def all_exercise_users(user_id)
|
|
|
|
|
|
|
|
# ex_users = exercise_users
|
|
|
|
|
|
|
|
# group_ids = common_published_ids(user_id)
|
|
|
|
|
|
|
|
# if group_ids.present?
|
|
|
|
|
|
|
|
# ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id").
|
|
|
|
|
|
|
|
# where(course_members: {course_group_id: group_ids})
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
# ex_users
|
|
|
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
|
|
#当前用户已发布的班级id和试卷分组已发布的班级id的交集
|
|
|
|
#当前用户已发布的班级id和试卷分组已发布的班级id的交集
|
|
|
|
def common_published_ids(user_id)
|
|
|
|
def common_published_ids(user_id)
|
|
|
|
current_user_groups = course.teacher_course_ids(user_id)
|
|
|
|
current_user_groups = course.teacher_course_ids(user_id)
|
|
|
|