|
|
|
@ -8,10 +8,12 @@ class ExerciseController < ApplicationController
|
|
|
|
|
:student_exercise_list, :update_question_num, :cancel_publish,
|
|
|
|
|
: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]
|
|
|
|
|
:choose_student, :redo_exercise, :cancel_commit_confirm, :cancel_commit,
|
|
|
|
|
:update_shixun_block]
|
|
|
|
|
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]
|
|
|
|
|
: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]
|
|
|
|
|
before_filter :require_login, :only => [:student_exercise_list, :show]
|
|
|
|
|
include ExerciseHelper
|
|
|
|
|
include ApplicationHelper
|
|
|
|
@ -161,7 +163,35 @@ class ExerciseController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def shixun_question
|
|
|
|
|
@shixun = Shixun.find params[:shixun_exercise]
|
|
|
|
|
@shixuns = Shixun.where(id: params[:shixun_exercise])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update_shixun_block
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
if params[:shixun_ids] && params[:shixun_ids].length > 0 && params[:ques_nums] && params[:ques_nums].length == 4 &&
|
|
|
|
|
params[:ques_scores] && params[:ques_scores].length == 4
|
|
|
|
|
shixuns = Shixun.where(id: params[:shixun_ids], status: 2, challenges_count: 1)
|
|
|
|
|
params[:ques_nums].each_with_index do |ques_num, index|
|
|
|
|
|
level_setting = @exercise.exercise_level_settings.where(level: index + 1).first ||
|
|
|
|
|
ExerciseLevelSetting.create(exercise_id: @exercise.id)
|
|
|
|
|
level_setting.update_attributes(score: params[:ques_scores][index], num: ques_num)
|
|
|
|
|
shixuns.where(trainee: index + 1).each do |shixun|
|
|
|
|
|
ex_question = @exercise.exercise_questions.where(shixun_id: shixun.id).first
|
|
|
|
|
if ex_question.present?
|
|
|
|
|
ex_question.update_attributes(question_score: params[:ques_scores][index])
|
|
|
|
|
else
|
|
|
|
|
ex_question = ExerciseQuestion.create(exercise_id: @exercise.id, question_score: arams[:ques_scores][index],
|
|
|
|
|
shixun_id: shixun.id, question_title: shixun.name, question_type: 5, question_number: 0)
|
|
|
|
|
shixun.challenges.each_with_index do |challenge, index|
|
|
|
|
|
ex_shixun_challenge = ExerciseShixunChallenge.new(challenge_id: challenge.id, shixun_id: shixun.id, exercise_question_id: ex_question.id,
|
|
|
|
|
question_score: params[:ques_scores][index], position: index + 1)
|
|
|
|
|
ex_shixun_challenge.save
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
@ -385,7 +415,7 @@ class ExerciseController < ApplicationController
|
|
|
|
|
option = {
|
|
|
|
|
:question_title => question_title,
|
|
|
|
|
:question_type => params[:question_type] || 1,
|
|
|
|
|
:question_number => @exercise.exercise_questions.count + 1,
|
|
|
|
|
:question_number => @exercise.exercise_questions.where("question_type != 5").count + 1,
|
|
|
|
|
:question_score => params[:question_score],
|
|
|
|
|
:shixun_id => params[:shixun]
|
|
|
|
|
}
|
|
|
|
@ -579,7 +609,7 @@ class ExerciseController < ApplicationController
|
|
|
|
|
#题目上移/下移
|
|
|
|
|
def update_question_num
|
|
|
|
|
@exercise_question = ExerciseQuestion.find params[:ques_id]
|
|
|
|
|
exercise_questions = @exercise.exercise_questions
|
|
|
|
|
exercise_questions = @exercise.exercise_questions.where("question_type != 5")
|
|
|
|
|
if @exercise_question
|
|
|
|
|
if params[:opr] == 'up' && @exercise_question.question_number > 1
|
|
|
|
|
@before_que = exercise_questions.where("question_number = #{@exercise_question.question_number - 1}").first
|
|
|
|
|