# encoding: utf-8 module ExerciseHelper # 单选 def sigle_selection_standard_answer(params) size = params.ord - 96 if size > 0 # 小写字母答案 answer = params.ord - 96 else answer = params.ord - 64 end end # 多选 def multiselect_standard_answer(params) size = params.ord - 96 answer = "" if size > 0 # 小写字母答案 for i in 0..(params.length-1) answer += (params[i].ord - 96).to_s end else for i in 0..(params.length-1) answer += (params[i].ord - 64).to_s end end answer.to_i end def fill_standart_answer(params, standart_answer) params.each do |param| standart_answer.answer_text = param.value standart_answer.save end end #判断用户是否已经提交了问卷 def has_commit_exercise?(exercise_id, user_id) pu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id, user_id) if pu.nil? false else true end end def convert_to_char(str) result = "" length = str.length unless str.nil? if length === 1 result += (str.to_i + 64).chr return result elsif length > 1 for i in 0...length result += (str[i].to_i + 64).chr end return result end end return result end def get_current_score exercise score = 0 unless exercise.nil? exercise.exercise_questions.each do |exercise_question| score += exercise_question.question_score end return score end return score end end