|
|
|
@ -124,6 +124,7 @@ class ExerciseBankQuestionsController < ApplicationController
|
|
|
|
|
@exercise_question.update_attributes(:question_score => question_score, :shixun_name=> shixun_name)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
normal_status("创建成功")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception("试卷问题创建失败!")
|
|
|
|
@ -185,7 +186,6 @@ class ExerciseBankQuestionsController < ApplicationController
|
|
|
|
|
if @exercise_question.question_type <= Exercise::JUDGMENT #选择题/判断题,标准答案为一个或多个
|
|
|
|
|
exercise_standard_choices = @exercise_answers_array.pluck(:exercise_bank_choice_id) #问题以前的全部标准答案选项位置
|
|
|
|
|
if exercise_standard_choices.sort != standard_answer.sort #表示答案有更改的
|
|
|
|
|
standard_answer_change = true
|
|
|
|
|
common_standard_choices = standard_answer & exercise_standard_choices # 传入的标准答案的选项位置和以前的并集,即表示不用做更改的
|
|
|
|
|
old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉
|
|
|
|
|
new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建
|
|
|
|
@ -216,7 +216,6 @@ class ExerciseBankQuestionsController < ApplicationController
|
|
|
|
|
if old_ex_answer_choice_texts != new_ex_answer_choice_texts #填空题标准答案有更改时,才会更新标准答案
|
|
|
|
|
new_ex_answer_choice_ids = standard_answer.map {|a| a[:choice_id]}.uniq #新传入的答案数组序号
|
|
|
|
|
old_ex_answer_choice_ids = old_ex_answer.pluck(:exercise_bank_choice_id).uniq #全部的答案数组序号
|
|
|
|
|
standard_answer_change = true
|
|
|
|
|
#删除多余的选项
|
|
|
|
|
if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空
|
|
|
|
|
delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids
|
|
|
|
@ -300,7 +299,7 @@ class ExerciseBankQuestionsController < ApplicationController
|
|
|
|
|
elsif @exercise_question.question_type == Exercise::PRACTICAL
|
|
|
|
|
question_score = 0
|
|
|
|
|
shixun_name = params[:shixun_name] || @exercise_question.shixun_name
|
|
|
|
|
@exercise_question.exercise_shixun_challenges.each_with_index do |challenge, index|
|
|
|
|
|
@exercise_question.exercise_bank_shixun_challenges.each_with_index do |challenge, index|
|
|
|
|
|
challenge.question_score = params[:question_scores][index].to_f.round(1)
|
|
|
|
|
challenge.save
|
|
|
|
|
question_score += params[:question_scores][index].to_f.round(1)
|
|
|
|
@ -309,32 +308,63 @@ class ExerciseBankQuestionsController < ApplicationController
|
|
|
|
|
@exercise_question.shixun_name = shixun_name
|
|
|
|
|
@exercise_question.save
|
|
|
|
|
end
|
|
|
|
|
normal_status(0,"试卷更新成功")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception("页面调用失败!")
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数.
|
|
|
|
|
|
|
|
|
|
if standard_answer_change && @exercise.exercise_status >= Exercise::PUBLISHED
|
|
|
|
|
# ex_users_committed = @exercise.exercise_users.exercise_user_committed
|
|
|
|
|
# if ex_users_committed.size > 0
|
|
|
|
|
# ex_users_committed.each do |ex_user|
|
|
|
|
|
# update_objective_score = update_single_score(@exercise_question,ex_user.user_id,standard_answer)
|
|
|
|
|
# if update_objective_score != 0
|
|
|
|
|
# objective_score = ex_user.objective_score
|
|
|
|
|
# new_objective_score = objective_score + update_objective_score
|
|
|
|
|
# total_score = ex_user.score + update_objective_score
|
|
|
|
|
# total_score = total_score < 0.0 ? 0.0 : total_score
|
|
|
|
|
# ex_user.update_attributes(objective_score:new_objective_score,score:total_score)
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
normal_status(3,"修改了标准答案\n是否重新计算学生答题的成绩?")
|
|
|
|
|
def up_down
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
opr = params[:opr]
|
|
|
|
|
current_q_p = @exercise_question.question_number.to_i #问题的当前位置
|
|
|
|
|
if opr.present?
|
|
|
|
|
if opr.to_s == "up"
|
|
|
|
|
last_q_p = @exercise.exercise_bank_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题
|
|
|
|
|
if last_q_p.present?
|
|
|
|
|
@exercise_question.update_attribute('question_number', (current_q_p - 1))
|
|
|
|
|
last_q_p.update_attribute('question_number', current_q_p) # 重新获取当前问题的位置
|
|
|
|
|
normal_status(0, "问题上移成功!")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1, "移动失败,已经是第一个问题了!")
|
|
|
|
|
end
|
|
|
|
|
elsif opr.to_s == "down"
|
|
|
|
|
next_q_p = @exercise.exercise_bank_questions.find_by(question_number: (current_q_p + 1)) # 当前问题的前一个问题
|
|
|
|
|
if next_q_p.present?
|
|
|
|
|
@exercise_question.update_attribute('question_number', (current_q_p + 1))
|
|
|
|
|
next_q_p.update_attribute('question_number', current_q_p)
|
|
|
|
|
normal_status(0, "问题下移成功!")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1, "移动失败,已经是最后一个问题了!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
normal_status(0,"试卷更新成功!")
|
|
|
|
|
normal_status(-1, "移动失败,请输入参数")
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception("问题移动失败!")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#试卷问题的删除
|
|
|
|
|
def destroy
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
question_d_id = @exercise_question.question_number.to_i #问题的当前位置
|
|
|
|
|
exercise_questions = @exercise.exercise_bank_questions
|
|
|
|
|
left_questions = exercise_questions.where("question_number > ?", question_d_id)
|
|
|
|
|
left_questions.update_all("question_number = question_number - 1") if left_questions
|
|
|
|
|
@exercise_question.destroy
|
|
|
|
|
normal_status(0, "删除成功")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception("页面调用失败!")
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
tip_exception("删除失败")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|