diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index a97f75f1..ba707e67 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, :delete_shixun_question] + :update_shixun_block, :delete_shixun_question, :delete_choose_shixun] 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, :delete_shixun_question] + :choose_shixuns, :shixun_question, :update_shixun_block, :delete_shixun_question, :delete_choose_shixun] before_filter :require_login, :only => [:student_exercise_list, :show] include ExerciseHelper include ApplicationHelper @@ -76,12 +76,12 @@ class ExerciseController < ApplicationController if @exercise_user.nil? @exercise_user = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false, :commit_status => 0) if @exercise.exercise_level_settings.where("num != exercise_questions_count").count > 0 - @exercise.create_user_question_list(@exercise_user) + @exercise.create_user_question_list(@exercise_user.id) end # @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first elsif @exercise_user.start_at.nil? if @exercise.exercise_level_settings.where("num != exercise_questions_count").count > 0 - @exercise.create_user_question_list(@exercise_user) + @exercise.create_user_question_list(@exercise_user.id) end @exercise_user.update_attributes(:start_at => Time.now) end @@ -112,7 +112,7 @@ class ExerciseController < ApplicationController @can_edit_excercise = false end - @exercise_questions = user_question_list @exercise_user.id + @exercise_questions = @exercise.user_question_list @exercise_user.id # @percent = get_percent(@exercise,User.current) #@exercise_questions = @exercise.exercise_questions @@ -221,6 +221,10 @@ class ExerciseController < ApplicationController @exercise.exercise_level_settings.destroy_all end + def delete_choose_shixun + @exercise.exercise_questions.where(question_type: 5, exercise_level_setting_id: 0).destroy_all + end + def create if params[:exercise] exercise = Exercise.new @@ -1315,7 +1319,7 @@ class ExerciseController < ApplicationController if @is_teacher || (User.current.member_of_course?(@exercise.course) && @exercise.exercise_status > 2) @user = User.find params[:user_id] @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first - @exercise_questions = @exercise.user_question_list @exercise_user.id + @exercise_questions = (@exercise.user_question_list @exercise_user.id).reorder("question_number = 0 asc, question_number asc") respond_to do |format| if params[:pdf] format.html { render :layout => "pdf" } diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index ea5eae8f..28ebf46f 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -314,7 +314,7 @@ module ExerciseHelper all_questions = questions.where("question_type = 5") uncomplete_shixun = [] all_questions.each do |question| - myshixun = Myshixun.where(:shixun_id => question.shixun_id, :user_id => user.id).first + myshixun = Myshixun.where(:shixun_id => question.shixun_id, :user_id => exercise_user.user_id).first unless myshixun && myshixun.is_complete? uncomplete_shixun << question end diff --git a/app/models/exercise.rb b/app/models/exercise.rb index af81e7e9..f0343311 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -31,14 +31,12 @@ class Exercise < ActiveRecord::Base def create_user_question_list exercise_user_id self.exercise_questions.where("question_type != 5").each do |question| - self.exercise_user_questions << ExerciseUserQuestion.new(exercise_user_id: exercise_user_id, - exercise_question_id: question) + ExerciseUserQuestion.create(exercise_id: self.id, exercise_user_id: exercise_user_id, exercise_question_id: question.id) end self.exercise_level_settings.each do |setting| # 每个级别中随机挑选num个实训题 setting.exercise_questions.pluck(:id).sample(setting.num).each do |question_id| - self.exercise_user_questions << ExerciseUserQuestion.new(exercise_user_id: exercise_user_id, - exercise_question_id: question_id) + ExerciseUserQuestion.create(exercise_id: self.id, exercise_user_id: exercise_user_id, exercise_question_id: question_id) end end end diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 63d9cdf9..e7e34146 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -6,11 +6,11 @@ class ExerciseQuestion < ActiveRecord::Base belongs_to :exercise belongs_to :shixun has_many :exercise_shixun_challenges, :order => "#{ExerciseShixunChallenge.table_name}.position",:dependent => :destroy - has_many :exercise_shixun_answers, :dependent => :destroy + has_many :exercise_shixun_answers has_many :exercise_choices, :dependent => :destroy - has_many :exercise_answers, :dependent => :destroy - has_many :exercise_answer_comments, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_answers + has_many :exercise_answer_comments + has_many :exercise_standard_answers belongs_to :exercise_level_setting, counter_cache: true has_many :exercise_user_questions, :dependent => :destroy @@ -29,4 +29,12 @@ class ExerciseQuestion < ActiveRecord::Base "实训题" end end + + def ques_number index + question_number = self.question_number + if self.question_type == 5 + question_number = exercise.exercise_questions.where("question_type != 5").count + index + end + question_number + end end diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index b5962dd1..984be1c0 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ActiveRecord::Base belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status end diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index 5d12c301..a61d745c 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -161,9 +161,9 @@
<% end %> - <% if exercise_question.question_type == 5 %> -<%= exercise_question.shixun.name %>
- <% end %> + <%# if exercise_question.question_type == 5 %> + + <%# end %>第<%= exercise_question.question_number %> +
第<%= index + 1 %> 题:[<%= exercise_question.question_type_name %> ]<%= exercise_question.question_score %> 分<%= question_commit_status exercise_question, @exercise_user.user %> diff --git a/app/views/exercise/_new_shixun.html.erb b/app/views/exercise/_new_shixun.html.erb index 5bb0e405..e4e26db9 100644 --- a/app/views/exercise/_new_shixun.html.erb +++ b/app/views/exercise/_new_shixun.html.erb @@ -1,5 +1,5 @@ <% if @exercise.id %> -
- 保存 - 取消 + 保存 + 取消 温馨提示:[实训题]属于客观题将由系统自动评分 @@ -114,13 +114,14 @@ diff --git a/app/views/exercise/_show_shixun.html.erb b/app/views/exercise/_show_shixun.html.erb index f42f2da5..eb014d99 100644 --- a/app/views/exercise/_show_shixun.html.erb +++ b/app/views/exercise/_show_shixun.html.erb @@ -1,5 +1,6 @@ -
第<%= exercise_question.question_number %> @@ -328,19 +328,59 @@ });