|
|
|
@ -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
|
|
|
|
@ -1627,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,"试卷未提交")
|
|
|
|
@ -1641,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
|
|
|
|
@ -1664,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
|
|
|
|
@ -1684,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
|
|
|
|
|