diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 6f08cb75f..e34e89cb7 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -27,19 +27,21 @@ class ExerciseController < ApplicationController render_403 return end - + @can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin? + @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first # 学生点击的时候即创建关联,自动保存 #eu = ExerciseUser.create(:user_id => User.current, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) # 已提交问卷的用户不能再访问该界面 if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?) - redirect_to exercise_index_url(:course_id=> @course.id) + respond_to do |format| + format.html {render :layout => 'base_courses'} + end else if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id) eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) end - @can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin? - @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first + # @percent = get_percent(@exercise,User.current) exercise_questions = @exercise.exercise_questions @exercise_questions = paginateHelper exercise_questions,5 #分页 @@ -428,6 +430,8 @@ class ExerciseController < ApplicationController redirect_to exercise_url(@exercise) # REDO: 提示提交成功 else + # 更新提交状态 + @exercise.exercise_users.first.update_attributes(:status => true) # 答题过程中需要统计完成量 @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 @@ -475,16 +479,20 @@ class ExerciseController < ApplicationController score2 = score + question.question_score unless question.question_score.nil? end else - ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) - arr = [] - ecs.each do |ec| - arr << ec.exercise_choice.choice_position - end - arr.sort - arr = arr.join("") + arr = get_mulscore(question, user) if arr.to_i == standard_answer.exercise_choice_id score3 = score + question.question_score unless question.question_score.nil? end + # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + # arr = [] + # ecs.each do |ec| + # arr << ec.exercise_choice.choice_position + # end + # arr.sort + # arr = arr.join("") + # if arr.to_i == standard_answer.exercise_choice_id + # score3 = score + question.question_score unless question.question_score.nil? + # end end end end @@ -492,6 +500,7 @@ class ExerciseController < ApplicationController end private + # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 def get_exercise_user exercise_id,user_id eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id) diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 21c0144b9..bb87f3b82 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -36,6 +36,17 @@ module ExerciseHelper end end + # 获取多选的得分 + def get_mulscore(question, user) + ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + arr = [] + ecs.each do |ec| + arr << ec.exercise_choice.choice_position + end + arr.sort + arr = arr.join("") + end + # 判断用户是否已经提交了问卷 # status 为0的时候是用户点击试卷。为1表示用户已经提交 def has_commit_exercise?(exercise_id, user_id) diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb index c6b9a251c..32cb556b3 100644 --- a/app/views/exercise/_exercise_student_result.html.erb +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -12,9 +12,8 @@