@ -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 :exercise_questions , :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 :course_acts , class_name : 'CourseActivity' , as : :course_act , :dependent = > :delete_all
@ -41,8 +43,8 @@ class Exercise < ApplicationRecord
exercise_users
else
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 . where ( user_id : course_user_ids )
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
end
@ -55,22 +57,45 @@ class Exercise < ApplicationRecord
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 . where ( user_id : course . students . where ( course_group_id : group_ids ) . select ( :user_id ) . pluck ( :user_id ) )
# 根据是否统一发布获取作业的作品列表
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 ) } )
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 = 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
# #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
# 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的交集
def common_published_ids ( user_id )
current_user_groups = course . teacher_course_ids ( user_id )
if unified_setting
un_group_ids = ( course . none_group_count > 0 ) ? [ 0 ] : [ ]
published_group_ids = ( current_user_groups + un_group_ids ) . uniq #统一设置时, 为当前用户的分班id及未分班
# un_group_ids = (course.none_group_count > 0) ? [0] : []
# published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时, 为当前用户的分班id及未分班
published_group_ids = current_user_groups
else
ex_group_setting = exercise_group_settings . select ( :course_group_id ) . pluck ( " course_group_id " ) . uniq
common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时, 为当前用户有权限的且已发布分班的id