2015-11-13 16:40:39 +08:00
|
|
|
|
# encoding: utf-8
|
|
|
|
|
module ExerciseHelper
|
2015-11-17 11:25:17 +08:00
|
|
|
|
|
2015-11-18 13:55:42 +08:00
|
|
|
|
# 单选
|
2015-11-18 14:31:35 +08:00
|
|
|
|
def sigle_selection_standard_answer(params)
|
2015-11-18 14:50:03 +08:00
|
|
|
|
size = params.ord - 96
|
2015-11-18 16:06:34 +08:00
|
|
|
|
if size > 0 # 小写字母答案
|
2015-11-18 14:31:35 +08:00
|
|
|
|
answer = params.ord - 96
|
|
|
|
|
else
|
2015-11-18 14:50:03 +08:00
|
|
|
|
answer = params.ord - 64
|
2015-11-18 14:31:35 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 多选
|
|
|
|
|
def multiselect_standard_answer(params)
|
2015-11-18 16:06:34 +08:00
|
|
|
|
size = params.ord - 96
|
2015-11-20 10:05:34 +08:00
|
|
|
|
answer = []
|
2015-11-18 16:06:34 +08:00
|
|
|
|
if size > 0 # 小写字母答案
|
|
|
|
|
for i in 0..(params.length-1)
|
2015-11-20 10:05:34 +08:00
|
|
|
|
answer << (params[i].ord - 96).to_s
|
2015-11-18 16:06:34 +08:00
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
for i in 0..(params.length-1)
|
2015-11-20 10:05:34 +08:00
|
|
|
|
answer << (params[i].ord - 64)
|
2015-11-18 16:06:34 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-11-20 10:05:34 +08:00
|
|
|
|
answer = answer.sort
|
|
|
|
|
answer.join("")
|
2015-11-18 13:55:42 +08:00
|
|
|
|
end
|
|
|
|
|
|
2015-11-18 19:58:00 +08:00
|
|
|
|
def fill_standart_answer(params, standart_answer)
|
|
|
|
|
params.each do |param|
|
|
|
|
|
standart_answer.answer_text = param.value
|
|
|
|
|
standart_answer.save
|
|
|
|
|
end
|
2015-11-18 18:28:17 +08:00
|
|
|
|
end
|
|
|
|
|
|
2015-11-20 11:08:47 +08:00
|
|
|
|
# 判断用户是否已经提交了问卷
|
|
|
|
|
# status 为0的时候是用户点击试卷。为1表示用户已经提交
|
2015-11-17 15:20:59 +08:00
|
|
|
|
def has_commit_exercise?(exercise_id, user_id)
|
2015-11-20 11:08:47 +08:00
|
|
|
|
pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, true)
|
|
|
|
|
if pu.empty?
|
|
|
|
|
false
|
|
|
|
|
else
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 判断学生是否点击过问卷,点击则为他保存一个记录,记录start_at
|
|
|
|
|
def has_click_exercise?(exercise_id, user_id)
|
|
|
|
|
pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, false)
|
|
|
|
|
if pu.empty?
|
2015-11-17 11:25:17 +08:00
|
|
|
|
false
|
|
|
|
|
else
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-18 10:49:57 +08:00
|
|
|
|
def convert_to_char(str)
|
|
|
|
|
result = ""
|
2015-11-18 14:05:29 +08:00
|
|
|
|
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
|
2015-11-18 10:49:57 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-11-18 14:05:29 +08:00
|
|
|
|
return result
|
2015-11-18 10:49:57 +08:00
|
|
|
|
end
|
|
|
|
|
|
2015-11-18 15:30:39 +08:00
|
|
|
|
def get_current_score exercise
|
|
|
|
|
score = 0
|
|
|
|
|
unless exercise.nil?
|
|
|
|
|
exercise.exercise_questions.each do |exercise_question|
|
2015-11-19 21:21:02 +08:00
|
|
|
|
unless exercise_question.question_score.nil?
|
|
|
|
|
score += exercise_question.question_score
|
|
|
|
|
end
|
2015-11-18 15:30:39 +08:00
|
|
|
|
end
|
|
|
|
|
return score
|
|
|
|
|
end
|
|
|
|
|
return score
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-19 21:19:18 +08:00
|
|
|
|
def answer_be_selected?(answer,user)
|
|
|
|
|
pv = answer.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id} ")
|
|
|
|
|
if !pv.nil? && pv.count > 0
|
|
|
|
|
true
|
|
|
|
|
else
|
|
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#获取文本题答案
|
|
|
|
|
def get_anwser_vote_text(question_id,user_id)
|
|
|
|
|
pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id)
|
|
|
|
|
if pv.nil?
|
|
|
|
|
''
|
|
|
|
|
else
|
|
|
|
|
pv.answer_text
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-13 16:40:39 +08:00
|
|
|
|
end
|