|
|
|
@ -188,30 +188,43 @@ class ExerciseController < ApplicationController
|
|
|
|
|
@exercise_question = ExerciseQuestion.find params[:exercise_question]
|
|
|
|
|
@exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
|
|
|
|
|
@exercise_question.question_score = params[:question_score]
|
|
|
|
|
# 处理选项
|
|
|
|
|
# 处理选项:如果选了某个选项,那么则要删除之前的选项
|
|
|
|
|
if params[:question_answer]
|
|
|
|
|
@exercise_question.exercise_choices.each do |answer|
|
|
|
|
|
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
|
|
|
|
|
end
|
|
|
|
|
# @exercise_question.exercise_choices.each do |answer|
|
|
|
|
|
# answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
|
|
|
|
|
# end
|
|
|
|
|
for i in 1..params[:question_answer].count
|
|
|
|
|
question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1]
|
|
|
|
|
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
|
|
|
|
|
if question
|
|
|
|
|
question.exercise_choices_id = i
|
|
|
|
|
question.answer_text = answer
|
|
|
|
|
question.choice_position = i
|
|
|
|
|
question.choice_text = answer
|
|
|
|
|
question.save
|
|
|
|
|
else
|
|
|
|
|
question_option = {
|
|
|
|
|
:exercise_choice_id => i,
|
|
|
|
|
:answer_text => answer
|
|
|
|
|
:choice_position => i,
|
|
|
|
|
:choice_text => answer
|
|
|
|
|
}
|
|
|
|
|
@exercise_question.exercise_answers.new question_option
|
|
|
|
|
@exercise_question.exercise_choices.new question_option
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@exercise_question.save
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
# 更新标准答案
|
|
|
|
|
if params[:exercise_choice]
|
|
|
|
|
if @exercise_question.question_type == 3
|
|
|
|
|
for i in 1..params[:exercise_choice].count
|
|
|
|
|
question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i]
|
|
|
|
|
answer_standart = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
answer_standart = @exercise_question.exercise_standard_answers.first
|
|
|
|
|
answer_standart.exercise_choice_id = params[:exercise_choice]
|
|
|
|
|
answer_standart.save
|
|
|
|
|
end
|
|
|
|
|
@exercise_question.save
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -231,7 +244,7 @@ class ExerciseController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#发布问卷
|
|
|
|
|
# 发布试卷
|
|
|
|
|
def publish_excercise
|
|
|
|
|
@exercise.exercise_status = 2
|
|
|
|
|
@exercise.publish_time = Time.now
|
|
|
|
@ -246,6 +259,19 @@ class ExerciseController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 重新发布试卷
|
|
|
|
|
def republish_excercise
|
|
|
|
|
@exercise.exercise_questions.each do |exercise_question|
|
|
|
|
|
exercise_question.exercise_ansers.destroy_all
|
|
|
|
|
end
|
|
|
|
|
# @poll.poll_users.destroy_all
|
|
|
|
|
# @poll.polls_status = 1
|
|
|
|
|
# @poll.save
|
|
|
|
|
# respond_to do |format|
|
|
|
|
|
# format.js
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def student_exercise_list
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
|
|
@exercise = Exercise.find params[:id]
|
|
|
|
@ -264,7 +290,7 @@ class ExerciseController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 学生提交答卷,选着答案的课程中提交
|
|
|
|
|
# 学生提交答卷,选中答案的过程中提交
|
|
|
|
|
def commit_answer
|
|
|
|
|
eq = ExerciseQuestion.find(params[:exercise_question_id])
|
|
|
|
|
# 已提交过的则不允许答题
|
|
|
|
|