|
|
|
@ -76,28 +76,30 @@ class ExerciseController < ApplicationController
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
|
|
|
|
|
|
|
unless @is_teacher
|
|
|
|
|
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
|
|
|
|
|
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.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.id)
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
|
|
|
|
|
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").size > 0
|
|
|
|
|
@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").size > 0
|
|
|
|
|
@exercise.create_user_question_list(@exercise_user.id)
|
|
|
|
|
end
|
|
|
|
|
@exercise_user.update_attributes(:start_at => Time.now)
|
|
|
|
|
end
|
|
|
|
|
@exercise_user.update_attributes(:start_at => Time.now)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@can_edit_excercise = can_edit_exercise @exercise, @exercise_user
|
|
|
|
|
if !@can_edit_excercise && !@exercise_user.status
|
|
|
|
|
time = (@exercise_user.start_at.to_i + @exercise.time.to_i * 60) > @exercise.end_time.to_i ? @exercise.end_time : Time.at(@exercise_user.start_at.to_i + @exercise.time.to_i * 60)
|
|
|
|
|
@exercise_user.update_attributes(:status => true, :end_at => time, :commit_status => 1)
|
|
|
|
|
s_score = calculate_student_score(@exercise, @exercise_user.user)
|
|
|
|
|
@exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (@exercise_user.subjective_score && @exercise_user.subjective_score > 0 ? @exercise_user.subjective_score : 0)))
|
|
|
|
|
if @exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
|
|
|
|
|
@exercise_user.update_attributes(:subjective_score => 0)
|
|
|
|
|
@can_edit_excercise = can_edit_exercise @exercise, @exercise_user
|
|
|
|
|
if !@can_edit_excercise && !@exercise_user.status
|
|
|
|
|
time = (@exercise_user.start_at.to_i + @exercise.time.to_i * 60) > @exercise.end_time.to_i ? @exercise.end_time : Time.at(@exercise_user.start_at.to_i + @exercise.time.to_i * 60)
|
|
|
|
|
@exercise_user.update_attributes(:status => true, :end_at => time, :commit_status => 1)
|
|
|
|
|
s_score = calculate_student_score(@exercise, @exercise_user.user)
|
|
|
|
|
@exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (@exercise_user.subjective_score && @exercise_user.subjective_score > 0 ? @exercise_user.subjective_score : 0)))
|
|
|
|
|
if @exercise_user.user.exercise_answer.where(:exercise_question_id => @exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty?
|
|
|
|
|
@exercise_user.update_attributes(:subjective_score => 0)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|