json.question_id question.id q_positon = question.question_number if ques_position.present? q_positon = ques_position end json.q_position q_positon json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置 standard_answers_array = question.get_standard_answer_ids ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱 if ex_choice_random_boolean exercise_choices = choices.order("RAND()") else exercise_choices = choices.order("choice_position ASC") end json.question_choices do json.array! exercise_choices.each_with_index.to_a do |a,index| standard_answer_b = standard_answers_array.include?(a.choice_position) user_answer_b = user_answer.include?(a.id) json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现 json.choice_id a.id json.choice_text "#{(index+65).chr}.#{a.choice_text}" json.choice_position a.choice_position if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题,2为空白试卷,即标准答案和用户答案都不显示,3为用户开始答题的显示,4为老师评阅试卷或学生在截止后查看试卷 json.standard_boolean standard_answer_b end if exercise_type == 3 || exercise_type == 4 json.user_answer_boolean user_answer_b end end end if exercise_type == 1 || exercise_type == 4 #1为老师,4为试卷截止且答案公开的情况 json.standard_answer standard_answers_array end if exercise_type == 3 || exercise_type == 4 json.user_answer user_answer end elsif question.question_type == 3 #当为填空题时 standard_answers_count = question.exercise_standard_answers standard_answer_ex = standard_answers_count.pluck(:exercise_choice_id).uniq json.is_ordered question.is_ordered json.multi_count standard_answer_ex.size #有几个填空 if exercise_type == 1 || exercise_type == 4 #1为老师,4为试卷截止且答案公开的情况 json.standard_answer do json.array! standard_answer_ex.each do |a| s_answer_text = standard_answers_count.standard_by_ids(a).pluck(:answer_text) json.choice_id a json.answer_text s_answer_text end end end if exercise_type == 3 || exercise_type == 4 json.user_answer do json.array! user_answer.each do |e| json.choice_id e[:choice_id] json.answer_text e[:answer_text] end end end elsif question.question_type == 4 #简答题时 if exercise_type == 1 || exercise_type == 4 json.standard_answer question.exercise_standard_answers.pluck(:answer_text) end if exercise_type == 3 || exercise_type == 4 json.user_answer user_answer end elsif question.question_type == 5 json.shixun_id question.shixun_id json.shixun_name question.shixun_name.present? ? question.shixun_name : "" json.shixun_identifier question.shixun.identifier if exercise_type == 1 || exercise_type == 2 || (shixun_type.present? && shixun_type == 0) #教师预览/新建/编辑以及导出空白试卷时,以及学生开始答题,但是还未回答实训题时 json.shixun do json.array! shixun_challenges do |s| json.challenge_id s.challenge_id json.challenge_position s.position json.challenge_name s.challenge.subject json.challenge_score s.question_score.round(1).to_s end end end if (exercise_type == 3 || exercise_type == 4) && (shixun_type.present? && shixun_type > 0 ) #教师评阅/试卷截止后,答案公开/试卷未截止,但学生已做了实训题 json.shixun_details do json.array! shixun_challenges do |s| games_score = shixun_game_scores(s,ex_answerer,shixun_type,question.id) user_get_score = games_score[:s_score].present? ? games_score[:s_score] : 0.0 json.shixun_challenge_id s.id if games_score[:games].count > 0 json.partial! "exercises/shixun_details",games: games_score[:games], user_score: user_get_score,game_score: games_score[:game_score],shixun_challenge:s else json.partial! "exercises/shixun_undo",games: [s], user_score: user_get_score ,game_score: s.question_score end end end end end