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 @@
开始时间:<%=format_time(exercise_user.start_at.to_s) %> 测验时长:<%=exercise.time %>分钟 - <% time = exercise_user.end_at - exercise_user.start_at %> - 测验用时:<%= (time % (24*60*60)) / (60*60)%> 小时 <%= ((time % (24*60*60)) % (60*60)) / 60%> 分钟 <%= ((time % (24*60*60)) % (60*60)) % 60%> 秒 -
+ <%# time = exercise_user.end_at - exercise_user.start_at %> +
<%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
@@ -32,7 +31,7 @@ <% answer = get_user_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> - <% if answer.exercise_choice_id == standard_answer.exercise_choice_id %> + <% if answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %> √ <% else %> × @@ -63,7 +62,7 @@
">

多选题

- <% mcq_question_list.each_wtih_index do |exercise_question, list_index| %> + <% mcq_question_list.each_with_index do |exercise_question, list_index| %>
@@ -71,7 +70,7 @@ <% answer = get_user_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> - <% if answer.exercise_choice_id == standard_answer.exercise_choice_id %> + <% if get_mulscore(exercise_question, User.current).to_i == standard_answer.first.exercise_choice_id %> √ <% else %> × @@ -110,7 +109,7 @@ <% answer = get_user_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> - <% if standard_answer.include?(answer.exercise_choice_id) %> + <% if standard_answer.include?(answer.first.answer_text) %> √ <% else %> ×