|
|
|
@ -1005,19 +1005,6 @@ class ExercisesController < ApplicationController
|
|
|
|
|
@exercise_user_current.update_attribute("start_at",Time.now)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# ex_time = @exercise.time
|
|
|
|
|
# if ex_time > 0
|
|
|
|
|
# time_mill = ex_time * 60 #转为秒
|
|
|
|
|
# exercise_end_time = @exercise.end_time.present? ? @exercise.end_time.to_i : 0
|
|
|
|
|
# exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0
|
|
|
|
|
# if (exercise_user_start + time_mill) > exercise_end_time
|
|
|
|
|
# time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
|
|
|
|
|
# end
|
|
|
|
|
# exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间
|
|
|
|
|
# @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
@t_user_exercise_status = @exercise.get_exercise_status(current_user)
|
|
|
|
|
|
|
|
|
|
@user_left_time = nil
|
|
|
|
@ -1029,10 +1016,7 @@ class ExercisesController < ApplicationController
|
|
|
|
|
@user_exercise_status = 0 #可编辑
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,
|
|
|
|
|
:exercise_shixun_answers,
|
|
|
|
|
:exercise_answers,
|
|
|
|
|
:exercise_standard_answers)
|
|
|
|
|
@exercise_questions = @exercise.exercise_questions
|
|
|
|
|
|
|
|
|
|
if @exercise.question_random
|
|
|
|
|
@exercise_questions = @exercise_questions.order("RAND()")
|
|
|
|
@ -1040,7 +1024,10 @@ class ExercisesController < ApplicationController
|
|
|
|
|
@exercise_questions = @exercise_questions.order("question_number ASC")
|
|
|
|
|
end
|
|
|
|
|
# 判断问题是否已回答还是未回答
|
|
|
|
|
@exercise_questions = @exercise_questions.includes(:exercise_stand_answers,:exercise_answers,:exercise_shixun_answers)
|
|
|
|
|
@exercise_questions = @exercise_questions.includes(:exercise_shixun_challenges,
|
|
|
|
|
:exercise_shixun_answers,
|
|
|
|
|
:exercise_answers,
|
|
|
|
|
:exercise_standard_answers)
|
|
|
|
|
|
|
|
|
|
if @t_user_exercise_status == 3
|
|
|
|
|
get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id)
|
|
|
|
@ -1127,14 +1114,14 @@ class ExercisesController < ApplicationController
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
# 1 老师权限,0 学生权限
|
|
|
|
|
@is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0
|
|
|
|
|
@is_teacher_or = (@user_course_identity < Course::STUDENT) ? 1 : 0
|
|
|
|
|
@student_status = 2
|
|
|
|
|
# @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者
|
|
|
|
|
@exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC")
|
|
|
|
|
@question_status = []
|
|
|
|
|
get_exercise_status = @exercise.get_exercise_status(current_user)
|
|
|
|
|
get_exercise_status = @exercise.get_exercise_status(current_user) #当前用户的试卷状态
|
|
|
|
|
@ex_answer_status = @exercise.get_exercise_status(@ex_user) #当前试卷用户的试卷状态
|
|
|
|
|
if @ex_user.present? && @is_teacher_or == 0
|
|
|
|
|
if get_exercise_status == 2 #当前用户已提交,且试卷未截止
|
|
|
|
|
if get_exercise_status == Exercise::PUBLISHED #当前用户已提交,且试卷未截止
|
|
|
|
|
if @ex_user.commit_status == 0 #学生未提交,且当前为学生
|
|
|
|
|
@student_status = 0
|
|
|
|
|
else
|
|
|
|
@ -1164,69 +1151,65 @@ class ExercisesController < ApplicationController
|
|
|
|
|
@course_all_members = @course.students
|
|
|
|
|
@c_group_counts = @course.course_groups_count
|
|
|
|
|
question_types = @exercise.exercise_questions.pluck(:question_type).uniq
|
|
|
|
|
@exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断是否有已发布的分班
|
|
|
|
|
@exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断是否有未发布的分班
|
|
|
|
|
@exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).count #判断是否有已发布的分班
|
|
|
|
|
@exercise_unpublish_count = get_user_permission_course(exercise_ids,Exercise::UNPUBLISHED).count #判断是否有未发布的分班
|
|
|
|
|
|
|
|
|
|
if (question_types.size > 1) && question_types.include?(4) #是否包含主观题,或者是否大于1
|
|
|
|
|
if (question_types.size > 1) && question_types.include?(Exercise::SUBJECTIVE) #是否包含主观题,或者是否大于1
|
|
|
|
|
@subjective_type = 1
|
|
|
|
|
else
|
|
|
|
|
@subjective_type = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#初始化值
|
|
|
|
|
@exercise_users_list = [] #答题用户列表
|
|
|
|
|
@exercise_course_groups = [] #当前用户有权限的班级
|
|
|
|
|
@exercise_unanswers = 0 # 未答用户数
|
|
|
|
|
@exercise_answers = 0 #已答用户数
|
|
|
|
|
@exercise_users_count = 0 #全部用户数
|
|
|
|
|
@teacher_review_count = 0 #已评数
|
|
|
|
|
@teacher_unreview_count = 0 #未评数
|
|
|
|
|
|
|
|
|
|
#试卷的答题列表页的显示用户
|
|
|
|
|
if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的试卷
|
|
|
|
|
@exercise_current_user_status = 0
|
|
|
|
|
if @exercise_status == 1
|
|
|
|
|
@exercise_users_list = []
|
|
|
|
|
@exercise_course_groups = []
|
|
|
|
|
@exercise_unanswers = 0
|
|
|
|
|
@exercise_answers = 0
|
|
|
|
|
else
|
|
|
|
|
unless @exercise_status == 1
|
|
|
|
|
ex_common_ids = @exercise.common_published_ids(current_user.id)
|
|
|
|
|
@exercise_course_groups = @course.get_ex_published_course(ex_common_ids)
|
|
|
|
|
@exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生
|
|
|
|
|
get_exercise_answers(@exercise_users_list, @exercise_status)
|
|
|
|
|
end
|
|
|
|
|
elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交)
|
|
|
|
|
else #当前为学生或者有过答题的
|
|
|
|
|
@ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间
|
|
|
|
|
@exercise_all_users = @exercise.get_stu_exercise_users
|
|
|
|
|
get_exercise_answers(@exercise_all_users, @exercise_status) # 未答和已答的
|
|
|
|
|
exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做)
|
|
|
|
|
if exercise_current_user.present?
|
|
|
|
|
@exercise_current_user_status = 1 #当前用户的状态,为学生
|
|
|
|
|
if @exercise.score_open && @exercise_status == 3 && exercise_current_user.present? #勾选了成绩公开且试卷已截止的
|
|
|
|
|
exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id)
|
|
|
|
|
if exercise_current_user.exists? #表示为课堂学生或已回答的
|
|
|
|
|
@exercise_current_user_status = 1
|
|
|
|
|
if @exercise.score_open && @exercise_status == 3 #勾选了成绩公开且试卷已截止的
|
|
|
|
|
all_user_ids = @exercise_all_users.pluck(:user_id)
|
|
|
|
|
all_user_ids.delete(current_user.id) #删除了当前用户的ID
|
|
|
|
|
@exercise_users_list = @exercise_all_users.exercise_commit_users(all_user_ids).distinct
|
|
|
|
|
@current_user_ex_answers = exercise_current_user #当前用户的回答
|
|
|
|
|
else
|
|
|
|
|
@exercise_users_list = exercise_current_user.present? ? exercise_current_user.distinct : []
|
|
|
|
|
@exercise_users_list = exercise_current_user
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
@exercise_all_users = @exercise.get_stu_exercise_users
|
|
|
|
|
get_exercise_answers(@exercise_all_users, @exercise_status) # 未答和已答的
|
|
|
|
|
else #表示为未回答的,或未非课堂成员的
|
|
|
|
|
@exercise_current_user_status = 2 #当前用户非课堂成员
|
|
|
|
|
@exercise_users_list = []
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if @exercise_users_list.present? && @exercise_users_list.count > 0
|
|
|
|
|
@exercise_users_count = @exercise_users_list.count #当前显示的全部成员数量
|
|
|
|
|
else
|
|
|
|
|
@exercise_users_count = 0
|
|
|
|
|
end
|
|
|
|
|
if @exercise_unanswers < 0
|
|
|
|
|
@exercise_unanswers = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@teacher_review_count = 0
|
|
|
|
|
@teacher_unreview_count = 0
|
|
|
|
|
#筛选/分类,排序
|
|
|
|
|
order = params[:order]
|
|
|
|
|
if @exercise_users_list.present? && @exercise_users_list.size > 0
|
|
|
|
|
if @exercise_users_list.exists? && @exercise_users_list.size > 0
|
|
|
|
|
@exercise_users_count = @exercise_users_list.size #当前显示的全部成员数量
|
|
|
|
|
teacher_reviews = @exercise_users_list.exercise_review
|
|
|
|
|
teacher_unreviews = @exercise_users_list.exercise_unreview
|
|
|
|
|
@teacher_review_count = teacher_reviews.count #已评阅
|
|
|
|
|
@teacher_unreview_count = teacher_unreviews.count #未评阅
|
|
|
|
|
@teacher_review_count = teacher_reviews.size #已评阅
|
|
|
|
|
@teacher_unreview_count = teacher_unreviews.size #未评阅
|
|
|
|
|
|
|
|
|
|
#是否评阅
|
|
|
|
|
if params[:review].present?
|
|
|
|
@ -1284,7 +1267,7 @@ class ExercisesController < ApplicationController
|
|
|
|
|
if params[:format] == "xlsx"
|
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR
|
|
|
|
|
tip_exception(403,"无权限操作")
|
|
|
|
|
elsif @exercise_status == 1
|
|
|
|
|
elsif @exercise_status == Exercise::UNPUBLISHED
|
|
|
|
|
normal_status(-1,"试卷未发布")
|
|
|
|
|
elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0)
|
|
|
|
|
normal_status(-1,"暂无用户提交")
|
|
|
|
@ -1530,30 +1513,22 @@ class ExercisesController < ApplicationController
|
|
|
|
|
def get_user_permission_course(exercise_ids,status)
|
|
|
|
|
exercise_status = status.to_i #传入的试卷发布状态
|
|
|
|
|
unpublish_group = []
|
|
|
|
|
# g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq #当前用户有权限的分班
|
|
|
|
|
# #用户的班级,理论上用户的班级要大于等于试卷设置的班级
|
|
|
|
|
# if g_course_ids.blank? || g_course_ids.include?(0)
|
|
|
|
|
# user_groups_id = @course.course_groups.pluck(:id)
|
|
|
|
|
# else
|
|
|
|
|
# user_groups_id = g_course_ids
|
|
|
|
|
# end
|
|
|
|
|
course_groups = []
|
|
|
|
|
user_groups_id = @course.charge_group_ids(current_user)
|
|
|
|
|
exercises_all = Exercise.where(id:exercise_ids)
|
|
|
|
|
exercises_all = Exercise.includes(:exercise_group_settings).where(id:exercise_ids)
|
|
|
|
|
exercises_all.each do |exercise|
|
|
|
|
|
if exercise.present?
|
|
|
|
|
if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止
|
|
|
|
|
exercise_user_status = exercise.get_exercise_status(current_user) #当前用户的能看到的试卷
|
|
|
|
|
if (exercise_user_status == exercise_status) || exercise_status == 3 #未发布的情况
|
|
|
|
|
if (exercise_user_status == exercise_status) || exercise_status == Exercise::ENDED #未发布的情况
|
|
|
|
|
unpublish_group = unpublish_group + user_groups_id
|
|
|
|
|
else
|
|
|
|
|
unpublish_group = []
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
ex_all_group_settings = exercise.exercise_group_settings
|
|
|
|
|
ex_group_settings = ex_all_group_settings.exercise_group_published.pluck(:course_group_id).uniq #问卷设置的班级
|
|
|
|
|
if exercise_status == 1
|
|
|
|
|
if exercise_status == Exercise::UNPUBLISHED
|
|
|
|
|
unpublish_group = user_groups_id - ex_group_settings
|
|
|
|
|
elsif exercise_status == 3
|
|
|
|
|
elsif exercise_status == Exercise::ENDED
|
|
|
|
|
ex_ended_groups = ex_all_group_settings.exercise_group_ended.pluck(:course_group_id).uniq
|
|
|
|
|
ex_and_user = user_groups_id & ex_group_settings #用户已设置的分班
|
|
|
|
|
unpublish_group = unpublish_group + ex_and_user - ex_ended_groups #已发布的全部班级减去截止的全部班级
|
|
|
|
@ -1567,8 +1542,6 @@ class ExercisesController < ApplicationController
|
|
|
|
|
unpublish_group = unpublish_group.uniq
|
|
|
|
|
if unpublish_group.count > 0
|
|
|
|
|
course_groups = CourseGroup.by_group_ids(unpublish_group)
|
|
|
|
|
else
|
|
|
|
|
course_groups = []
|
|
|
|
|
end
|
|
|
|
|
course_groups
|
|
|
|
|
end
|
|
|
|
@ -1641,7 +1614,7 @@ class ExercisesController < ApplicationController
|
|
|
|
|
ex_status = @exercise.get_exercise_status(current_user)
|
|
|
|
|
@ex_user = @exercise.exercise_users.find_by(user_id:@exercise_current_user_id) #该试卷的回答者
|
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR
|
|
|
|
|
if ex_status == 1
|
|
|
|
|
if ex_status == Exercise::UNPUBLISHED
|
|
|
|
|
normal_status(-1,"试卷未发布")
|
|
|
|
|
elsif @ex_user.present? && @ex_user.commit_status == 0
|
|
|
|
|
normal_status(-1,"试卷未提交")
|
|
|
|
@ -1655,7 +1628,7 @@ class ExercisesController < ApplicationController
|
|
|
|
|
def check_exercise_public
|
|
|
|
|
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交
|
|
|
|
|
ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first
|
|
|
|
|
unless @exercise.get_exercise_status(current_user) == 3 && ex_user.present? && ex_user.commit_status == 1 &&
|
|
|
|
|
unless @exercise.get_exercise_status(current_user) == Exercise::ENDED && ex_user.present? && ex_user.commit_status == 1 &&
|
|
|
|
|
@exercise.show_statistic
|
|
|
|
|
normal_status(-1,"学生暂不能查看")
|
|
|
|
|
end
|
|
|
|
@ -1678,19 +1651,19 @@ class ExercisesController < ApplicationController
|
|
|
|
|
ex_question_random = exercise.question_random
|
|
|
|
|
question_answered = 0
|
|
|
|
|
exercise_questions.each_with_index do |q,index|
|
|
|
|
|
if ex_question_random && exercise_user_status != 3
|
|
|
|
|
if ex_question_random && exercise_user_status != Exercise::ENDED
|
|
|
|
|
ques_number = index + 1
|
|
|
|
|
else
|
|
|
|
|
ques_number = q.question_number
|
|
|
|
|
end
|
|
|
|
|
if q.question_type != 5
|
|
|
|
|
if q.question_type != Exercise::PRACTICAL
|
|
|
|
|
ques_vote = q.exercise_answers.search_exercise_answer("user_id",user_id)
|
|
|
|
|
else
|
|
|
|
|
ques_vote = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id)
|
|
|
|
|
end
|
|
|
|
|
ques_status = 0
|
|
|
|
|
if ques_vote.present?
|
|
|
|
|
if q.question_type == 5
|
|
|
|
|
if q.question_type == Exercise::PRACTICAL
|
|
|
|
|
if ques_vote.pluck(:exercise_shixun_challenge_id).sort == q.exercise_shixun_challenges.pluck(:id).sort #用户的总得分等于问题的分数
|
|
|
|
|
ques_status = 1 #全部回答了,才算已答
|
|
|
|
|
question_answered += 1
|
|
|
|
@ -1698,12 +1671,12 @@ class ExercisesController < ApplicationController
|
|
|
|
|
else #其他题目,需回答的有内容,才会为已答,否则如内容为空,视为未答
|
|
|
|
|
vote_answer_id = ques_vote.pluck(:exercise_choice_id).reject(&:blank?)
|
|
|
|
|
vote_text_count = ques_vote.pluck(:answer_text).reject(&:blank?).size
|
|
|
|
|
if q.question_type <= 2 #选择题和判断题的时候,需要有选项,才算回答
|
|
|
|
|
if q.question_type <= Exercise::JUDGMENT #选择题和判断题的时候,需要有选项,才算回答
|
|
|
|
|
if vote_answer_id.size > 0
|
|
|
|
|
ques_status = 1
|
|
|
|
|
question_answered += 1
|
|
|
|
|
end
|
|
|
|
|
elsif q.question_type == 3 #填空题的时候,需要有选项和内容,才算回答
|
|
|
|
|
elsif q.question_type == Exercise::COMPLETION #填空题的时候,需要有选项和内容,才算回答
|
|
|
|
|
if vote_answer_id.uniq.sort == q.exercise_standard_answers.pluck(:exercise_choice_id).uniq.sort
|
|
|
|
|
ques_status = 1
|
|
|
|
|
question_answered += 1
|
|
|
|
|