修改show逻辑

提交问卷后学生页面显示
This commit is contained in:
huang 2015-11-20 18:01:50 +08:00
parent 431d1d886c
commit 97485ca221
2 changed files with 39 additions and 21 deletions

View File

@ -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 #分页
@ -433,6 +435,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)
# 获取改学生的考试得分
@ -480,16 +484,17 @@ 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("")
if arr.to_i == standard_answer.exercise_choice_id
score3 = score + question.question_score unless question.question_score.nil?
end
get_mulscore(question, user, standard_answer)
# 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
@ -497,6 +502,20 @@ class ExerciseController < ApplicationController
end
private
# 获取多选的得分
def get_mulscore(question, user, standard_answer)
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
# ExerciseUser记录用户是否已提交问卷有对应的记录则已提交没有则新建一个
def get_exercise_user exercise_id,user_id
eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id)

View File

@ -12,9 +12,8 @@
<div class="fontGrey2">
<span class="mr130">开始时间:<%=format_time(exercise_user.start_at.to_s) %></span>
<span class="mr130">测验时长:<%=exercise.time %>分钟</span>
<% time = exercise_user.end_at - exercise_user.start_at %>
<span class="fr">测验用时:<span class="c_red"><%= (time % (24*60*60)) / (60*60)%></span>&nbsp;小时&nbsp;<span class="c_red"><%= ((time % (24*60*60)) % (60*60)) / 60%></span>&nbsp;分钟&nbsp;<span class="c_red"><%= ((time % (24*60*60)) % (60*60)) % 60%></span>&nbsp;秒</span>
</div>
<%# time = exercise_user.end_at - exercise_user.start_at %>
</div>
<div class="testDesEdit mt5"><%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%></div>
<div class="cl"></div>
</div>
@ -32,7 +31,7 @@
<span class="ml15 c_red">
<% 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 @@
</div>
<div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>">
<h3 class="fontGrey3">多选题</h3>
<% mcq_question_list.each_wtih_index do |exercise_question, list_index| %>
<% mcq_question_list.each_with_index do |exercise_question, list_index| %>
<div id="poll_questions_<%= exercise_question.id%>">
<div id="show_poll_questions_<%= exercise_question.id %>">
<div>
@ -71,7 +70,7 @@
<span class="ml15 c_red">
<% 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_id == standard_answer.first.exercise_choice_id %>
<% else %>
×
@ -110,7 +109,7 @@
<span class="ml15 c_red">
<% 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 %>
×