You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.8 KiB
49 lines
1.8 KiB
6 years ago
|
module ExerciseQuestionsHelper
|
||
|
def get_exercise_question_info(question,exercise,ex_user,ex_answerer_id)
|
||
|
answered_content = []
|
||
|
exercise_answers = question.exercise_answers.search_exercise_answer("user_id",ex_answerer_id) #试卷用户的回答
|
||
|
if question.question_type <= 2
|
||
|
answered_content = exercise_answers.pluck(:exercise_choice_id)
|
||
|
elsif question.question_type == 3
|
||
|
exercise_answers.each do |a|
|
||
|
u_answer = {
|
||
|
"choice_id": a.exercise_choice_id,
|
||
|
"answer_text": a.answer_text
|
||
|
}
|
||
|
answered_content.push(u_answer)
|
||
|
end
|
||
|
elsif question.question_type == 4
|
||
|
answered_content = exercise_answers.pluck(:answer_text)
|
||
|
end
|
||
|
if question.question_type == 5 && ex_user.present? && ex_user.commit_status == 1 #存在实训题,且用户已提交了的,如果实训题只做了一半就关闭,则相当于不要了
|
||
|
if exercise.exercise_status == 3 #如果试卷已截止,则可以看到分数,否则不能查看分数
|
||
|
shixun_type = 2
|
||
|
else
|
||
|
shixun_type =1
|
||
|
end
|
||
|
else
|
||
|
shixun_type = 0
|
||
|
end
|
||
|
{
|
||
|
"answered_content":answered_content,
|
||
|
"shixun_type":shixun_type
|
||
|
}
|
||
|
end
|
||
|
|
||
|
def shixun_game_scores(challenge,ex_answerer,shixun_type,question_id)
|
||
|
game_score = challenge.question_score
|
||
|
game_answers = challenge.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer.id).search_shixun_answers("exercise_question_id",question_id)
|
||
|
if shixun_type == 2 && game_answers.present? #试卷已截止,用户才可以查看答案
|
||
|
s_score = game_answers.first.score
|
||
|
else
|
||
|
s_score = nil
|
||
|
end
|
||
|
games = ex_answerer.games.ch_games(challenge.challenge_id).uniq
|
||
|
{
|
||
|
"games":games,
|
||
|
"s_score":s_score,
|
||
|
"game_score":game_score
|
||
|
}
|
||
|
end
|
||
|
end
|