学生答题未完成时可保存试卷

This commit is contained in:
cxt 2015-11-27 10:15:25 +08:00
parent cc0ff6bbc0
commit 1f2675020b
5 changed files with 66 additions and 25 deletions

View File

@ -359,7 +359,7 @@ class ExerciseController < ApplicationController
def commit_answer
eq = ExerciseQuestion.find(params[:exercise_question_id])
# 已提交过的且是限时的则不允许答题
if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1
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")
render :json => {:text => "failure"}
return
end
@ -376,8 +376,14 @@ class ExerciseController < ApplicationController
ea.exercise_choice_id = params[:exercise_choice_id]
if ea.save
# 保存成功返回成功信息及当前以答题百分比
uncomplete_question = get_uncomplete_question(@exercise, User.current)
if uncomplete_question.count < 1
complete = 1;
else
complete = 0;
end
@percent = get_percent(@exercise,User.current)
render :json => {:text => "ok" ,:percent => format("%.2f" ,@percent)}
render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)}
else
#返回失败信息
render :json => {:text => "failure"}
@ -392,8 +398,14 @@ class ExerciseController < ApplicationController
ea.exercise_question_id = params[:exercise_question_id]
ea.exercise_choice_id = params[:exercise_choice_id]
if ea.save
uncomplete_question = get_uncomplete_question(@exercise, User.current)
if uncomplete_question.count < 1
complete = 1;
else
complete = 0;
end
@percent = get_percent(@exercise,User.current)
render :json => {:text => "ok",:percent => format("%.2f" ,@percent)}
render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)}
else
render :json => {:text => "failure"}
end
@ -422,8 +434,14 @@ class ExerciseController < ApplicationController
ea.exercise_question_id = params[:exercise_question_id]
ea.answer_text = params[:answer_text]
if ea.save
uncomplete_question = get_uncomplete_question(@exercise, User.current)
if uncomplete_question.count < 1
complete = 1;
else
complete = 0;
end
@percent = get_percent(@exercise,User.current)
render :json => {:text => ea.answer_text,:percent => format("%.2f",@percent)}
render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)}
else
render :json => {:text => "failure"}
end
@ -513,7 +531,7 @@ class ExerciseController < ApplicationController
exercise_qustions.each do |question|
answer = get_user_answer(question, user)
standard_answer = get_user_standard_answer(question, user)
unless answer.nil?
unless answer.empty?
# 问答题有多个答案
if question.question_type == 3
if standard_answer.include?(answer.first.answer_text)
@ -555,19 +573,6 @@ class ExerciseController < ApplicationController
eu
end
#获取未完成的题目
def get_uncomplete_question exercise,user
all_questions = exercise.exercise_questions
uncomplete_question = []
all_questions.each do |question|
answers = get_user_answer(question, user)
if answers.nil?
uncomplete_question << question
end
end
uncomplete_question
end
# 获取当前学生回答问题的答案
def get_user_answer(question,user)
# user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first
@ -586,7 +591,8 @@ class ExerciseController < ApplicationController
standard_answer = question.exercise_standard_answers.first
end
standard_answer
end # 是否完成了答题
end
# 是否完成了答题
def get_complete_question(exercise,user)
questions = exercise.exercise_questions
complete_question = []

View File

@ -107,6 +107,19 @@ module ExerciseHelper
end
end
#获取未完成的题目
def get_uncomplete_question exercise,user
all_questions = exercise.exercise_questions
uncomplete_question = []
all_questions.each do |question|
answers = get_user_answer(question, user)
if answers.empty?
uncomplete_question << question
end
end
uncomplete_question
end
#获取文本题答案
def get_anwser_vote_text(question_id,user_id)
pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id)

View File

@ -5,9 +5,12 @@
<% elsif status == 0 && Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S") %>
<h3 style="font-weight: normal;color: green">提交成功!</h3>
<%= link_to "确定", exercise_index_path(:course_id => @course.id),:class => 'commit'%>
<% elsif status == 1 %>
<h3 style="font-weight: normal;color: red">您还有尚未作答的题目请完成后再提交!</h3>
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>
<% elsif status == 1 && Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S")%>
<h3 style="font-weight: normal;color: red">保存成功!</h3>
<%= link_to "确定",exercise_index_path(:course_id => @course.id),:class => 'commit'%>
<% elsif status == 1 && Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") <= Time.now.strftime("%Y-%m-%d %H:%M:%S")%>
<h3 style="font-weight: normal;color: red">时间已到!</h3>
<%= link_to "确定", exercise_path(),:class => 'commit'%>
<% elsif status == 2 %>
<h3 style="font-weight: normal;color: red">发生未知错误,请检查您的网络。</h3>
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>

View File

@ -3,7 +3,11 @@
$("#RSide").removeAttr("id");
$("#homework_page_right").css("min-height",$("#LSide").height()-30);
$("#Container").css("width","1000px");
end_time = <%=exercise.end_time.to_i%>
<%uncomplete_question =get_uncomplete_question(exercise, User.current) %>;
<% if (uncomplete_question.count < 1) %>
$("#exercise_submit_btn").html("提交");
<% end %>
var end_time = <%=exercise.end_time.to_i%>;
getTime(end_time);
/*start_time = new Date();
start_time.setFullYear(<%#=exercise_user.start_at.year%>);
@ -100,6 +104,11 @@
{
obj.checked = false;
}
if(dataObj.complete == 1) {
$("#exercise_submit_btn").html("提交");
} else {
$("#exercise_submit_btn").html("保存");
}
}
});
}
@ -154,6 +163,11 @@
{
obj.checked = false;
}
if(dataObj.complete == 1) {
$("#exercise_submit_btn").html("提交");
} else {
$("#exercise_submit_btn").html("保存");
}
}
});
}
@ -196,6 +210,11 @@
success: function (data) {
var dataObj = eval(data);
obj.value = dataObj.text;
if(dataObj.complete == 1) {
$("#exercise_submit_btn").html("提交");
} else {
$("#exercise_submit_btn").html("保存");
}
}
});
@ -209,7 +228,7 @@
<% end %>
</div>
<div class="ur_buttons">
<%= link_to l(:button_submit),commit_exercise_exercise_path(exercise),:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %>
<%= link_to "保存",commit_exercise_exercise_path(exercise),:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %>
</div>
<div class="cl"></div>
<!--contentbox end-->

View File

@ -96,7 +96,7 @@
<div>
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %>&nbsp;&nbsp;(<%= exercise_question.question_score %>分)
<br />
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) if exercise_question.exercise_standard_answers.first%>
</div>
<div class="cl"></div>
<div>