diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c02bdccec..f80327ad1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1119,7 +1119,7 @@ class ExercisesController < ApplicationController @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) #当前用户的试卷状态 - @ex_answer_status = @exercise.get_exercise_status(@ex_user) #当前试卷用户的试卷状态 + @ex_answer_status = @exercise.get_exercise_status(@ex_user&.user) #当前试卷用户的试卷状态 if @ex_user.present? && @is_teacher_or == 0 if get_exercise_status == Exercise::PUBLISHED #当前用户已提交,且试卷未截止 if @ex_user.commit_status == 0 #学生未提交,且当前为学生 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 71a520cef..eb3802d94 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -8,13 +8,14 @@ module ExercisesHelper exercise_obj_status = exercise_questions.find_objective_questions @ex_obj_array = [] exercise_obj_status.each do |q| - if q.question_type == 5 + q_type = q.question_type + if q_type == Exercise::PRACTICAL answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else answers_content = q.exercise_answers.search_answer_users("user_id",user_id) end - if q.question_type <= 2 + if q_type <= Exercise::JUDGMENT if answers_content.present? #学生有回答时 answer_choice_array = [] answers_content.each do |a| @@ -52,7 +53,7 @@ module ExercisesHelper } @ex_obj_array.push(ques_option) end - exercise_sub_status = exercise_questions.find_by_custom("question_type",4) #主观题 + exercise_sub_status = exercise_questions.find_by_custom("question_type",Exercise::SUBJECTIVE) #主观题 @ex_sub_array = [] #主观题的已答/未答 exercise_sub_status.each do |s| sub_answer = s.exercise_answers.search_answer_users("user_id",user_id) #主观题只有一个回答 @@ -63,7 +64,6 @@ module ExercisesHelper else stand_status = 2 end - # stand_status = 1 sub_answer_score = sub_answer.first.score else stand_status = 0 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 10c7ab6d1..79701767f 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,6 +127,7 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) + return Exercise::UNPUBLISHED if user.nil? if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 ex_time = get_exercise_times(user_id,false) pb_time = ex_time[:publish_time]