老师查看学生的答卷结果

This commit is contained in:
cxt 2015-11-27 15:19:13 +08:00
parent 1f2675020b
commit f7ac2b0ef5
10 changed files with 50 additions and 25 deletions

View File

@ -1,7 +1,7 @@
class ExerciseController < ApplicationController class ExerciseController < ApplicationController
layout "base_courses" layout "base_courses"
before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise] before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise,:show_student_result]
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list] before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
include ExerciseHelper include ExerciseHelper
@ -34,7 +34,7 @@ class ExerciseController < ApplicationController
render_403 render_403
return return
end end
exercise_end = Time.parse(format_time(@exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S") exercise_end = @exercise.end_time > Time.now
if @exercise.time == -1 if @exercise.time == -1
@can_edit_excercise = exercise_end @can_edit_excercise = exercise_end
else else
@ -59,6 +59,9 @@ class ExerciseController < ApplicationController
# @percent = get_percent(@exercise,User.current) # @percent = get_percent(@exercise,User.current)
exercise_questions = @exercise.exercise_questions exercise_questions = @exercise.exercise_questions
@exercise_questions = paginateHelper exercise_questions,5 #分页 @exercise_questions = paginateHelper exercise_questions,5 #分页
score = calculate_student_score(@exercise, User.current)
eu = get_exercise_user(@exercise.id, User.current.id)
eu.update_attributes(:score => score)
respond_to do |format| respond_to do |format|
format.html {render :layout => 'base_courses'} format.html {render :layout => 'base_courses'}
end end
@ -342,10 +345,10 @@ class ExerciseController < ApplicationController
@exercise = Exercise.find params[:id] @exercise = Exercise.find params[:id]
@all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc") @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc")
@exercise_count = @exercise.exercise_users.where('score is not NULL').count @exercise_count = @exercise.exercise_users.where('score is not NULL').count
if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") <= Time.now.strftime("%Y-%m-%d-%H-%M-%S")) if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now)
@exercise_users_list = @exercise.exercise_users.where('score is not NULL') @exercise_users_list = @exercise.exercise_users.where('score is not NULL')
@show_all = true; @show_all = true;
elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") > Time.now.strftime("%Y-%m-%d-%H-%M-%S") elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now
@exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id)
else else
@exercise_users_list = [] @exercise_users_list = []
@ -359,7 +362,7 @@ class ExerciseController < ApplicationController
def commit_answer def commit_answer
eq = ExerciseQuestion.find(params[:exercise_question_id]) eq = ExerciseQuestion.find(params[:exercise_question_id])
# 已提交过的且是限时的则不允许答题 # 已提交过的且是限时的则不允许答题
if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || Time.parse(format_time(@exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") < Time.now.strftime("%Y-%m-%d %H:%M:%S") if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now
render :json => {:text => "failure"} render :json => {:text => "failure"}
return return
end end
@ -483,7 +486,7 @@ class ExerciseController < ApplicationController
@exercise.update_attributes(:publish_time => Time.now) @exercise.update_attributes(:publish_time => Time.now)
redirect_to exercise_url(@exercise) redirect_to exercise_url(@exercise)
return return
elsif Time.parse(@exercise.publish_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") > Time.now.strftime("%Y-%m-%d-%H-%M-%S") elsif @exercise.publish_time > Time.now
@exercise.update_attributes(:show_result => params[:show_result]) @exercise.update_attributes(:show_result => params[:show_result])
redirect_to exercise_url(@exercise) redirect_to exercise_url(@exercise)
return return
@ -521,6 +524,20 @@ class ExerciseController < ApplicationController
end end
end end
#查看学生的答卷情况
def show_student_result
@user = User.find params[:user_id]
@can_edit_excercise = false
@exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first
@exercise_questions = @exercise.exercise_questions
score = calculate_student_score(@exercise, @user)
eu = get_exercise_user(@exercise.id, @user.id)
eu.update_attributes(:score => score)
respond_to do |format|
format.html {render :layout => 'base_courses'}
end
end
# 计算学生得分 # 计算学生得分
def calculate_student_score(exercise, user) def calculate_student_score(exercise, user)
score = 0 score = 0

View File

@ -30,10 +30,11 @@
<script type="text/javascript"> <script type="text/javascript">
function resetHead() function resetHead()
{ {
$("#exercise_name").val("<%=@exercise.exercise_name%>"); $("#exercise_name").val("<%=exercise.exercise_name%>");
$("#exercise_end_time").val("<%= Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d") if exercise.end_time %>"); $("#exercise_end_time").val("<%= Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d") if exercise.end_time %>");
$("#exercise_time").val("<%=exercise.time if exercise.time!= -1 %>"); $("#exercise_time").val("<%=exercise.time if exercise.time!= -1 %>");
$("#exercise_publish_time").val("<%= Time.parse(format_time(exercise.publish_time)).strftime("%Y-%m-%d") if !exercise.publish_time.nil?%>"); $("#exercise_publish_time").val("<%= Time.parse(format_time(exercise.publish_time)).strftime("%Y-%m-%d") if !exercise.publish_time.nil?%>");
$("#exercise_description").val("<%=exercise.exercise_description %>"); /*$("#exercise_description").text("<%#=exercise.exercise_description.html_safe %>");*/
document.getElementById("exercise_description").innerText = <%=exercise.exercise_description.html_safe %>;
} }
</script> </script>

View File

@ -9,7 +9,7 @@
var popWindow ; //弹出框的引用 var popWindow ; //弹出框的引用
var importPollPopWindow; //选择导入的弹出框引用 var importPollPopWindow; //选择导入的弹出框引用
function edit_head(){ function edit_head(){
$("#polls_description").val($("#polls_description_div").html()); $("#exercise_description").val($("#exercise_description_div").html());
} }
$(function(){ $(function(){
//点击空白处 //点击空白处

View File

@ -32,8 +32,8 @@
<div> <div>
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %>&nbsp;&nbsp;(<%= exercise_question.question_score %>分) <div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %>&nbsp;&nbsp;(<%= exercise_question.question_score %>分)
<span class="ml15 c_red"> <span class="ml15 c_red">
<% answer = get_user_answer(exercise_question, User.current)%> <% answer = get_user_answer(exercise_question, user)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, user)%>
<% if !answer.empty? && !standard_answer.empty? && answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %> <% if !answer.empty? && !standard_answer.empty? && answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %>
<% else %> <% else %>
@ -49,7 +49,7 @@
<tr> <tr>
<td> <td>
<label> <label>
<%= radio_button "exercise",exercise_question.id.to_s+"exercise_choice_id",exercise_choice.id,:class=>"ur_radio",:checked => answer_be_selected?(exercise_choice,User.current),:disabled => !@can_edit_excercise %> <%= radio_button "exercise",exercise_question.id.to_s+"exercise_choice_id",exercise_choice.id,:class=>"ur_radio",:checked => answer_be_selected?(exercise_choice,user),:disabled => !@can_edit_excercise %>
<%= convert_to_char((index+1).to_s)%>&nbsp;&nbsp;<%= exercise_choice.choice_text%> <%= convert_to_char((index+1).to_s)%>&nbsp;&nbsp;<%= exercise_choice.choice_text%>
</label> </label>
</td> </td>
@ -71,9 +71,9 @@
<div> <div>
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %>&nbsp;&nbsp;(<%= exercise_question.question_score %>分) <div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %>&nbsp;&nbsp;(<%= exercise_question.question_score %>分)
<span class="ml15 c_red"> <span class="ml15 c_red">
<% answer = get_user_answer(exercise_question, User.current)%> <% answer = get_user_answer(exercise_question, user)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, user)%>
<% if !standard_answer.empty? && get_mulscore(exercise_question, User.current).to_i == standard_answer.first.exercise_choice_id %> <% if !standard_answer.empty? && get_mulscore(exercise_question, user).to_i == standard_answer.first.exercise_choice_id %>
<% else %> <% else %>
× ×
@ -88,7 +88,7 @@
<tr> <tr>
<td> <td>
<label> <label>
<input class="ur_radio" type="checkbox" <%= answer_be_selected?(exercise_choice,User.current) ? "checked":"" %> <%= @can_edit_poll?"":"disabled=disabled" %> > <input class="ur_radio" type="checkbox" <%= answer_be_selected?(exercise_choice,user) ? "checked":"" %> <%= @can_edit_excercise?"":"disabled=disabled" %> >
<%= convert_to_char((index+1).to_s)%>&nbsp;&nbsp;<%= exercise_choice.choice_text%> <%= convert_to_char((index+1).to_s)%>&nbsp;&nbsp;<%= exercise_choice.choice_text%>
</label> </label>
</td> </td>
@ -110,8 +110,8 @@
<div> <div>
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %>&nbsp;&nbsp;(<%= exercise_question.question_score %>分) <div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %>&nbsp;&nbsp;(<%= exercise_question.question_score %>分)
<span class="ml15 c_red"> <span class="ml15 c_red">
<% answer = get_user_answer(exercise_question, User.current)%> <% answer = get_user_answer(exercise_question, user)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, user)%>
<% if !answer.empty? && !standard_answer.empty? && standard_answer.include?(answer.first.answer_text) %> <% if !answer.empty? && !standard_answer.empty? && standard_answer.include?(answer.first.answer_text) %>
<% else %> <% else %>
@ -126,7 +126,7 @@
<% end %> <% end %>
</div> </div>
<div> <div>
<input class="fillInput" placeholder="在此填入答案" type="text" value="<%= get_anwser_vote_text(exercise_question.id,User.current.id).html_safe %>" <%= @can_edit_poll?"":"disabled=disabled" %>> <input class="fillInput" placeholder="在此填入答案" type="text" value="<%= get_anwser_vote_text(exercise_question.id,user.id).html_safe %>" <%= @can_edit_excercise?"":"disabled=disabled" %>>
</div> </div>
</div> </div>
</div> </div>

View File

@ -11,7 +11,6 @@
<span>测验时长:<%= exercise.time %>分钟</span> <span>测验时长:<%= exercise.time %>分钟</span>
<% end %> <% end %>
</div> </div>
<div class="testDesEdit mt5"><%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%></div> <pre class="fontGrey2 font_cus"><%= exercise.exercise_description.nil? ? "" :exercise.exercise_description.html_safe%></pre>
<div class="cl"></div>
<div class="cl"></div> <div class="cl"></div>
</div> </div>

View File

@ -44,7 +44,13 @@
<li> <li>
<ul class="mt10 fl"> <ul class="mt10 fl">
<li class="hworkStName mr15 mt16" title="姓名"> <li class="hworkStName mr15 mt16" title="姓名">
<%= exercise.user.show_name%> <% name = exercise.user.show_name %>
<% if Time.parse(h(@exercise.end_time)).strftime("%Y-%m-%d-%H-%M-%S") <= Time.now.strftime("%Y-%m-%d-%H-%M-%S") %>
<%= link_to name,show_student_result_exercise_path(@exercise,:user_id => exercise.user.id) %>
<% else %>
<span title="截止日期未到,暂不能查看学生答题结果。"><%=name%></span>
<%#= link_to name,'',:title=>"截止日期未到,暂不能查看学生答题结果。" %>
<% end %>
</li> </li>
<li class="hworkStID mr10 mt16" title="学号"> <li class="hworkStID mr10 mt16" title="学号">
<%= exercise.user.user_extensions.nil? ? "--" : exercise.user.user_extensions.student_id%> <%= exercise.user.user_extensions.nil? ? "--" : exercise.user.user_extensions.student_id%>

View File

@ -5,6 +5,6 @@
<% if @can_edit_excercise %> <% if @can_edit_excercise %>
<%=render :partial => 'exercise_student', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user} %> <%=render :partial => 'exercise_student', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user} %>
<% else %> <% else %>
<%=render :partial => 'exercise_student_result', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user} %> <%=render :partial => 'exercise_student_result', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user,:user=>User.current} %>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -0,0 +1 @@
<%=render :partial => 'exercise_student_result', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user,:user =>@user} %>

View File

@ -168,6 +168,7 @@ RedmineApp::Application.routes.draw do
get 'export_exercise' get 'export_exercise'
get 'publish_exercise' get 'publish_exercise'
get 'republish_exercise' get 'republish_exercise'
get 'show_student_result'
post 'create_exercise_question' post 'create_exercise_question'
post 'commit_answer' post 'commit_answer'
post 'commit_exercise' post 'commit_exercise'

View File

@ -1166,5 +1166,5 @@ a:hover.testEdit{ background:url(images/icons.png) -21px -272px no-repeat;}
.questionEditContainer {border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px; margin-top:10px;} .questionEditContainer {border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px; margin-top:10px;}
.fillInput {border:1px solid #cbcbcb; padding-left:5px; background-color:#ffffff; width:693px; height:30px; color:#888888;} .fillInput {border:1px solid #cbcbcb; padding-left:5px; background-color:#ffffff; width:693px; height:30px; color:#888888;}
.mr130 {margin-right:130px;} .mr130 {margin-right:130px;}
.mr100 {margin-right:100px;}
.ur_button_submit{ display:block; width:106px; height:31px; margin:0 auto; background:#15bccf; color:#fff; font-size:16px; text-align:center; padding-top:4px; margin-bottom:10px; } .ur_button_submit{ display:block; width:106px; height:31px; margin:0 auto; background:#15bccf; color:#fff; font-size:16px; text-align:center; padding-top:4px; margin-bottom:10px; }
.font_cus {font-family: "微软雅黑","宋体"; font-size: 12px; line-height: 1.5;}