From b73e55d1d87ec22558876640a8f6f0a9b417b3db Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 18 Apr 2019 09:30:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 8 +- app/models/exercise.rb | 20 ++++ app/models/exercise_level_setting.rb | 2 +- app/views/exercise/_edit_shixun.html.erb | 2 +- app/views/exercise/_exercise_content.html.erb | 16 +-- app/views/exercise/_new_question.html.erb | 2 +- app/views/exercise/_new_shixun.html.erb | 15 ++- app/views/exercise/_show_MC.html.erb | 2 +- app/views/exercise/_show_MCQ.html.erb | 2 +- app/views/exercise/_show_multi.html.erb | 2 +- app/views/exercise/_show_shixun.html.erb | 101 +++++++----------- app/views/exercise/_show_single.html.erb | 2 +- .../exercise/_total_questions_score.html.erb | 29 +++-- .../exercise/delete_shixun_question.js.erb | 2 + app/views/exercise/shixun_question.js.erb | 4 +- config/routes.rb | 1 + 16 files changed, 107 insertions(+), 103 deletions(-) create mode 100644 app/views/exercise/delete_shixun_question.js.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 24bee1f8..a97f75f1 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -9,11 +9,11 @@ class ExerciseController < ApplicationController :send_to_course, :get_student_uncomplete_question, :edit_question_score, :setting, :set_public, :ex_setting, :add_to_exercise_bank, :choose_shixuns, :shixun_question, :back_to_answer, :export_blank_exercise, :export_student_result, :choose_student, :redo_exercise, :cancel_commit_confirm, :cancel_commit, - :update_shixun_block] + :update_shixun_block, :delete_shixun_question] before_filter :find_course, :only => [:index,:new,:create] before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :create_exercise_question, :publish_exercise, :publish_notice, :end_exercise, :cancel_publish, :update_question_num, :send_to_course, :edit_question_score, :set_public, :ex_setting, :export_blank_exercise, :export_student_result, - :choose_shixuns, :shixun_question, :update_shixun_block] + :choose_shixuns, :shixun_question, :update_shixun_block, :delete_shixun_question] before_filter :require_login, :only => [:student_exercise_list, :show] include ExerciseHelper include ApplicationHelper @@ -217,6 +217,10 @@ class ExerciseController < ApplicationController redirect_to edit_exercise_path(@exercise) end + def delete_shixun_question + @exercise.exercise_level_settings.destroy_all + end + def create if params[:exercise] exercise = Exercise.new diff --git a/app/models/exercise.rb b/app/models/exercise.rb index c5992382..af81e7e9 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -55,4 +55,24 @@ class Exercise < ActiveRecord::Base def level_setting level self.exercise_level_settings.where(level: level).first end + + def shixun_question_count + self.exercise_level_settings.sum(:num) + end + + def shixun_question_score + score = 0 + self.exercise_level_settings.each do |setting| + score += setting.num * setting.score.to_i + end + score + end + + def has_shixun_questions? + self.exercise_questions.where("question_type = 5 and exercise_level_setting_id != 0").count > 0 + end + + def exercise_question_size + self.exercise_questions.where("question_type != 5").count + self.shixun_question_count + end end diff --git a/app/models/exercise_level_setting.rb b/app/models/exercise_level_setting.rb index 3e687d8c..72ea225b 100644 --- a/app/models/exercise_level_setting.rb +++ b/app/models/exercise_level_setting.rb @@ -1,5 +1,5 @@ class ExerciseLevelSetting < ActiveRecord::Base belongs_to :exercise - has_many :exercise_questions + has_many :exercise_questions, :dependent => :destroy # attr_accessible :level, :num, :score end diff --git a/app/views/exercise/_edit_shixun.html.erb b/app/views/exercise/_edit_shixun.html.erb index 6a84fe17..ebd77574 100644 --- a/app/views/exercise/_edit_shixun.html.erb +++ b/app/views/exercise/_edit_shixun.html.erb @@ -28,7 +28,7 @@ - + diff --git a/app/views/exercise/_exercise_content.html.erb b/app/views/exercise/_exercise_content.html.erb index e9915c5b..2c1b2afd 100644 --- a/app/views/exercise/_exercise_content.html.erb +++ b/app/views/exercise/_exercise_content.html.erb @@ -29,13 +29,13 @@
- <% when 5 %> -第<%= exercise_question.question_number%>题:[填空题]<%= exercise_question.question_score %>分
<% if @exercise.exercise_status == 1 %>- <% if exercise_question.question_number < @exercise.exercise_questions.count %> + <% if exercise_question.question_number < @exercise.exercise_questions.where("question_type != 5").count %> <% end %> <% unless exercise_question.question_number == 1 %> diff --git a/app/views/exercise/_total_questions_score.html.erb b/app/views/exercise/_total_questions_score.html.erb index d812fad1..9a6b4e17 100644 --- a/app/views/exercise/_total_questions_score.html.erb +++ b/app/views/exercise/_total_questions_score.html.erb @@ -2,23 +2,30 @@
<% exercise_questions = @exercise.exercise_questions %> - <% if exercise_questions.select{|e| e.question_type==1}.count > 0 %> - 单选题 <%= exercise_questions.select{|e| e.question_type==1}.count %> 题,共 <%= current_score[1] %> 分 + <% mc_count = exercise_questions.select{|e| e.question_type==1}.count %> + <% mcq_count = exercise_questions.select{|e| e.question_type==2}.count %> + <% single_count = exercise_questions.select{|e| e.question_type==3}.count %> + <% multi_count = exercise_questions.select{|e| e.question_type==4}.count %> + + <% if mc_count > 0 %> + 单选题 <%= mc_count %> 题,共 <%= current_score[1] %> 分 <% end %> - <% if exercise_questions.select{|e| e.question_type==2}.count > 0 %> - 多选题 <%= exercise_questions.select{|e| e.question_type==2}.count %> 题,共 <%= current_score[2] %> 分 + <% if mcq_count > 0 %> + 多选题 <%= mcq_count %> 题,共 <%= current_score[2] %> 分 <% end %> - <% if exercise_questions.select{|e| e.question_type==3}.count > 0 %> - 填空题 <%= exercise_questions.select{|e| e.question_type==3}.count %> 题,共 <%= current_score[3] %> 分 + <% if single_count > 0 %> + 填空题 <%= single_count %> 题,共 <%= current_score[3] %> 分 <% end %> - <% if exercise_questions.select{|e| e.question_type==4}.count > 0 %> - 简答题 <%= exercise_questions.select{|e| e.question_type==4}.count %> 题,共 <%= current_score[4] %> 分 + <% if multi_count > 0 %> + 简答题 <%= multi_count %> 题,共 <%= current_score[4] %> 分 <% end %> - <% if exercise_questions.select{|e| e.question_type==5}.count > 0 %> - 实训题 <%= exercise_questions.select{|e| e.question_type==5}.count %> 题,共 <%= current_score[5] %> 分 + <% if @exercise.shixun_question_count > 0 %> + 实训题 <%= @exercise.shixun_question_count %> 题,共 <%= @exercise.shixun_question_score %> 分 <% end %>
- 合计 <%= @exercise.exercise_questions.size %> 题,共 <%= current_score[0] %> 分 + <% count = mc_count + mcq_count + single_count + multi_count + @exercise.shixun_question_count %> + <% score = current_score[1] + current_score[2] + current_score[3] + current_score[4] + @exercise.shixun_question_score %> + 合计 <%= count %> 题,共 <%= score %> 分