From 841ebb78468d1ec0198d03e4cd9ce05f89139feb Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 16:21:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=AE=80=E5=8D=95=E9=A2=98=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=EF=BC=8C=E6=9C=AA=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 54 ++++++++++++++++++------ app/views/exercise/_edit_MC.html.erb | 2 +- app/views/exercise/_edit_MCQ.html.erb | 4 +- app/views/exercise/_edit_single.html.erb | 2 +- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index dd4e543ff..faaae4997 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -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]) # 已提交过的则不允许答题 diff --git a/app/views/exercise/_edit_MC.html.erb b/app/views/exercise/_edit_MC.html.erb index 9c6f3c396..76bad697c 100644 --- a/app/views/exercise/_edit_MC.html.erb +++ b/app/views/exercise/_edit_MC.html.erb @@ -35,7 +35,7 @@ <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
  • - +
  • diff --git a/app/views/exercise/_edit_MCQ.html.erb b/app/views/exercise/_edit_MCQ.html.erb index 0186b3041..a3ae74324 100644 --- a/app/views/exercise/_edit_MCQ.html.erb +++ b/app/views/exercise/_edit_MCQ.html.erb @@ -9,7 +9,7 @@ $("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>" + "
  • " + "" + - "" + + "" + "" + "" + "
  • " + @@ -35,7 +35,7 @@ <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
  • - +
  • diff --git a/app/views/exercise/_edit_single.html.erb b/app/views/exercise/_edit_single.html.erb index 1048b2145..647ab02de 100644 --- a/app/views/exercise/_edit_single.html.erb +++ b/app/views/exercise/_edit_single.html.erb @@ -34,7 +34,7 @@ <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %>
  • - +
  • From f3614999da1927e565b550f79889f0ac4bebf2a6 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 16:38:46 +0800 Subject: [PATCH 2/3] gi --- app/controllers/exercise_controller.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index faaae4997..5510b1539 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -213,8 +213,19 @@ class ExerciseController < ApplicationController 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] + # 找到对应的标准答案 + question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1] + # 标准答案值 + answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1] + if question_standart + question_standart.answer_text = answer_standart + question_standart.save + else + standart_answer_option = { + :answer_text => question_standart + } + @exercise_question.exercise_standard_answers.new standart_answer_option + end end else answer_standart = @exercise_question.exercise_standard_answers.first From 02f6b636cd4f963d5bea0f985b18eafed71c4f2f Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 17:09:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 5510b1539..8561b112a 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -190,9 +190,9 @@ class ExerciseController < ApplicationController @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] @@ -229,7 +229,7 @@ class ExerciseController < ApplicationController end else answer_standart = @exercise_question.exercise_standard_answers.first - answer_standart.exercise_choice_id = params[:exercise_choice] + answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice]) answer_standart.save end @exercise_question.save