|
|
|
@ -74,21 +74,17 @@ class ExerciseController < ApplicationController
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
|
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
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?
|
|
|
|
|
@exercise_user.update_attributes(:start_at => Time.now)
|
|
|
|
|
end
|
|
|
|
|
if @exercise.exercise_level_settings.where("num != exercise_questions_count").count > 0
|
|
|
|
|
@exercise.create_user_question_list(@exercise_user.id)
|
|
|
|
|
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
|
|
|
|
@ -119,6 +115,8 @@ class ExerciseController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@exercise_questions = @exercise.user_question_list @exercise_user.id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @percent = get_percent(@exercise,User.current)
|
|
|
|
|
#@exercise_questions = @exercise.exercise_questions
|
|
|
|
|