|
|
|
@ -98,13 +98,8 @@ class Exercise < ApplicationRecord
|
|
|
|
|
#判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间
|
|
|
|
|
def get_exercise_status(user_id)
|
|
|
|
|
user_group = course.course_members.find_by(user_id: user_id)
|
|
|
|
|
if user_group.present?
|
|
|
|
|
if user_group.role == "STUDENT" #为学生
|
|
|
|
|
is_teacher = false
|
|
|
|
|
else
|
|
|
|
|
is_teacher = true
|
|
|
|
|
end
|
|
|
|
|
ex_time = get_exercise_times(user_id,is_teacher)
|
|
|
|
|
if user_group.present? && user_group.role == "STUDENT" #当为学生的时候,需根据分班来判断试卷状态
|
|
|
|
|
ex_time = get_exercise_times(user_id,false)
|
|
|
|
|
|
|
|
|
|
pb_time = ex_time[:publish_time]
|
|
|
|
|
ed_time = ex_time[:end_time]
|
|
|
|
@ -117,28 +112,63 @@ class Exercise < ApplicationRecord
|
|
|
|
|
status = 1
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
status = exercise_status
|
|
|
|
|
end
|
|
|
|
|
Rails.logger.info("#################__________status___________####################{status}")
|
|
|
|
|
status = exercise_status #当为老师的时候,则为试卷的总状态
|
|
|
|
|
end
|
|
|
|
|
# if user_group.present?
|
|
|
|
|
# if user_group.role == "STUDENT" #为学生
|
|
|
|
|
# is_teacher = false
|
|
|
|
|
# else
|
|
|
|
|
# is_teacher = true
|
|
|
|
|
# end
|
|
|
|
|
# ex_time = get_exercise_times(user_id,is_teacher)
|
|
|
|
|
#
|
|
|
|
|
# pb_time = ex_time[:publish_time]
|
|
|
|
|
# ed_time = ex_time[:end_time]
|
|
|
|
|
#
|
|
|
|
|
# if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now
|
|
|
|
|
# status = 2
|
|
|
|
|
# elsif ed_time.present? && ed_time <= Time.now
|
|
|
|
|
# status = 3
|
|
|
|
|
# else
|
|
|
|
|
# status = 1
|
|
|
|
|
# end
|
|
|
|
|
# else
|
|
|
|
|
# status = exercise_status
|
|
|
|
|
# end
|
|
|
|
|
status
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#获取试卷的发布时间和截止时间。teacher 为boolean,当为true时,表示的是当前为老师
|
|
|
|
|
def get_exercise_times(user_id,teacher)
|
|
|
|
|
if unified_setting
|
|
|
|
|
if unified_setting || teacher #当试卷为统一设置或当前为老师的时候
|
|
|
|
|
pb_time = publish_time
|
|
|
|
|
en_time = end_time
|
|
|
|
|
|
|
|
|
|
if end_time <= Time.now && exercise_status != 3
|
|
|
|
|
update_column("exercise_status",3)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
ex_group_setting = exercise_group_settings
|
|
|
|
|
if teacher #当前为老师,为设置组的最大值和最小值
|
|
|
|
|
user_group = course.teacher_course_groups.get_user_groups(user_id)
|
|
|
|
|
user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id)
|
|
|
|
|
user_ex_group_settings = ex_group_setting.find_in_exercise_group("course_group_id",user_group_ids)
|
|
|
|
|
pb_time_min = user_ex_group_settings.publish_time_no_null.map(&:publish_time)
|
|
|
|
|
en_time_max = user_ex_group_settings.end_time_no_null.map(&:end_time)
|
|
|
|
|
pb_time = pb_time_min.size > 0 ? pb_time_min.min : nil
|
|
|
|
|
en_time = en_time_max.size > 0 ? en_time_max.max : nil
|
|
|
|
|
else
|
|
|
|
|
# if teacher #当前为老师,为设置组的最大值和最小值
|
|
|
|
|
# user_group = course.teacher_course_groups.get_user_groups(user_id)
|
|
|
|
|
# user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id)
|
|
|
|
|
# user_ex_group_settings = ex_group_setting.find_in_exercise_group("course_group_id",user_group_ids)
|
|
|
|
|
# pb_time_min = user_ex_group_settings.publish_time_no_null.map(&:publish_time)
|
|
|
|
|
# en_time_max = user_ex_group_settings.end_time_no_null.map(&:end_time)
|
|
|
|
|
# pb_time = pb_time_min.size > 0 ? pb_time_min.min : nil
|
|
|
|
|
# en_time = en_time_max.size > 0 ? en_time_max.max : nil
|
|
|
|
|
# else
|
|
|
|
|
# user_group = course.students.course_find_by_ids("user_id",user_id)
|
|
|
|
|
# if user_group.present?
|
|
|
|
|
# user_group_id = user_group.first.course_group_id
|
|
|
|
|
# user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id)
|
|
|
|
|
# pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil
|
|
|
|
|
# en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil
|
|
|
|
|
# else
|
|
|
|
|
# pb_time = nil
|
|
|
|
|
# en_time = nil
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
user_group = course.students.course_find_by_ids("user_id",user_id)
|
|
|
|
|
if user_group.present?
|
|
|
|
|
user_group_id = user_group.first.course_group_id
|
|
|
|
@ -150,7 +180,7 @@ class Exercise < ApplicationRecord
|
|
|
|
|
en_time = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"publish_time":pb_time,
|
|
|
|
|
"end_time":en_time
|
|
|
|
|