|
|
|
@ -59,7 +59,8 @@ class ExerciseController < ApplicationController
|
|
|
|
|
:end_time => "",
|
|
|
|
|
:publish_time => "",
|
|
|
|
|
:exercise_description => "",
|
|
|
|
|
:show_result => ""
|
|
|
|
|
:show_result => "",
|
|
|
|
|
:show_result => 1
|
|
|
|
|
}
|
|
|
|
|
@exercise = Exercise.create option
|
|
|
|
|
if @exercise
|
|
|
|
@ -141,7 +142,9 @@ class ExerciseController < ApplicationController
|
|
|
|
|
option = {
|
|
|
|
|
:question_title => question_title,
|
|
|
|
|
:question_type => params[:question_type] || 1,
|
|
|
|
|
:question_number => @exercise.exercise_questions.count + 1,
|
|
|
|
|
:question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 :
|
|
|
|
|
(params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) :
|
|
|
|
|
@exercise.exercise_questions.where("question_type = 3").count + 1),
|
|
|
|
|
:question_score => params[:question_score]
|
|
|
|
|
}
|
|
|
|
|
@exercise_questions = @exercise.exercise_questions.new option
|
|
|
|
@ -159,7 +162,14 @@ class ExerciseController < ApplicationController
|
|
|
|
|
# 如果是插入的话,那么从插入的这个id以后的question_num都将要+1
|
|
|
|
|
if params[:quest_id]
|
|
|
|
|
@is_insert = true
|
|
|
|
|
@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1")
|
|
|
|
|
if @exercise_questions.question_type == 1
|
|
|
|
|
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1")
|
|
|
|
|
#@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
|
|
|
|
|
elsif @exercise_questions.question_type == 2
|
|
|
|
|
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1")
|
|
|
|
|
else
|
|
|
|
|
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1")
|
|
|
|
|
end
|
|
|
|
|
# @exercise_question_num = params[:quest_num].to_i
|
|
|
|
|
@exercise_questions.question_number = params[:quest_num].to_i + 1
|
|
|
|
|
end
|
|
|
|
@ -344,7 +354,7 @@ class ExerciseController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
elsif eq.question_type == 2
|
|
|
|
|
#多选题
|
|
|
|
|
ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id)
|
|
|
|
|
ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id)
|
|
|
|
|
if ea.nil?
|
|
|
|
|
#尚未答该题,添加答案
|
|
|
|
|
ea = ExerciseAnswer.new
|
|
|
|
@ -359,7 +369,7 @@ class ExerciseController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
#pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案
|
|
|
|
|
if pv.delete
|
|
|
|
|
if ea.delete
|
|
|
|
|
@percent = get_percent(@exercise, User.current)
|
|
|
|
|
render :json => {:text => "false" ,:percent => format("%.2f" , @percent)}
|
|
|
|
|
else
|
|
|
|
@ -419,7 +429,7 @@ class ExerciseController < ApplicationController
|
|
|
|
|
def commit_exercise
|
|
|
|
|
# 老师不需要提交
|
|
|
|
|
if User.current.allowed_to?(:as_teacher,@course)
|
|
|
|
|
|
|
|
|
|
@exercise.update_attributes(:show_result => params[:exercise][:show_result])
|
|
|
|
|
redirect_to exercise_url(@exercise)
|
|
|
|
|
# REDO: 提示提交成功
|
|
|
|
|
else
|
|
|
|
|