开始回答页面的修改

dev_forum
SylorHuang 6 years ago
parent d29f9e830d
commit c3ef9c9bd8

@ -47,7 +47,7 @@ class ExerciseQuestionsController < ApplicationController
if @exercise_question.save if @exercise_question.save
#为选择题(包括单选和多选)的时候,创建问题选项 #为选择题(包括单选和多选)的时候,创建问题选项
ques_type = @exercise_question.question_type ques_type = @exercise_question.question_type
if ques_type <= 1 if ques_type <= Exercise::MULTIPLE
choices_array = params[:question_choices] choices_array = params[:question_choices]
choices_count= choices_array.count choices_count= choices_array.count
standard_answer = params[:standard_answers] #为数组格式,因为可能会有单选和多选,标准答案,已提前判断不能为空, standard_answer = params[:standard_answers] #为数组格式,因为可能会有单选和多选,标准答案,已提前判断不能为空,

@ -1005,19 +1005,6 @@ class ExercisesController < ApplicationController
@exercise_user_current.update_attribute("start_at",Time.now) @exercise_user_current.update_attribute("start_at",Time.now)
end end
end end
# ex_time = @exercise.time
# if ex_time > 0
# time_mill = ex_time * 60 #转为秒
# exercise_end_time = @exercise.end_time.present? ? @exercise.end_time.to_i : 0
# exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0
# if (exercise_user_start + time_mill) > exercise_end_time
# time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
# end
# exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间
# @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
# end
@t_user_exercise_status = @exercise.get_exercise_status(current_user) @t_user_exercise_status = @exercise.get_exercise_status(current_user)
@user_left_time = nil @user_left_time = nil
@ -1029,10 +1016,7 @@ class ExercisesController < ApplicationController
@user_exercise_status = 0 #可编辑 @user_exercise_status = 0 #可编辑
end end
@exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges, @exercise_questions = @exercise.exercise_questions
:exercise_shixun_answers,
:exercise_answers,
:exercise_standard_answers)
if @exercise.question_random if @exercise.question_random
@exercise_questions = @exercise_questions.order("RAND()") @exercise_questions = @exercise_questions.order("RAND()")
@ -1040,7 +1024,10 @@ class ExercisesController < ApplicationController
@exercise_questions = @exercise_questions.order("question_number ASC") @exercise_questions = @exercise_questions.order("question_number ASC")
end end
# 判断问题是否已回答还是未回答 # 判断问题是否已回答还是未回答
@exercise_questions = @exercise_questions.includes(:exercise_stand_answers,:exercise_answers,:exercise_shixun_answers) @exercise_questions = @exercise_questions.includes(:exercise_shixun_challenges,
:exercise_shixun_answers,
:exercise_answers,
:exercise_standard_answers)
if @t_user_exercise_status == 3 if @t_user_exercise_status == 3
get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id)
@ -1127,14 +1114,14 @@ class ExercisesController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
# 1 老师权限0 学生权限 # 1 老师权限0 学生权限
@is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0 @is_teacher_or = (@user_course_identity < Course::STUDENT) ? 1 : 0
@student_status = 2 @student_status = 2
# @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者
@exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC") @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC")
@question_status = [] @question_status = []
get_exercise_status = @exercise.get_exercise_status(current_user) get_exercise_status = @exercise.get_exercise_status(current_user) #当前用户的试卷状态
@ex_answer_status = @exercise.get_exercise_status(@ex_user) #当前试卷用户的试卷状态
if @ex_user.present? && @is_teacher_or == 0 if @ex_user.present? && @is_teacher_or == 0
if get_exercise_status == 2 #当前用户已提交,且试卷未截止 if get_exercise_status == Exercise::PUBLISHED #当前用户已提交,且试卷未截止
if @ex_user.commit_status == 0 #学生未提交,且当前为学生 if @ex_user.commit_status == 0 #学生未提交,且当前为学生
@student_status = 0 @student_status = 0
else else
@ -1627,7 +1614,7 @@ class ExercisesController < ApplicationController
ex_status = @exercise.get_exercise_status(current_user) ex_status = @exercise.get_exercise_status(current_user)
@ex_user = @exercise.exercise_users.find_by(user_id:@exercise_current_user_id) #该试卷的回答者 @ex_user = @exercise.exercise_users.find_by(user_id:@exercise_current_user_id) #该试卷的回答者
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
if ex_status == 1 if ex_status == Exercise::UNPUBLISHED
normal_status(-1,"试卷未发布") normal_status(-1,"试卷未发布")
elsif @ex_user.present? && @ex_user.commit_status == 0 elsif @ex_user.present? && @ex_user.commit_status == 0
normal_status(-1,"试卷未提交") normal_status(-1,"试卷未提交")
@ -1641,7 +1628,7 @@ class ExercisesController < ApplicationController
def check_exercise_public def check_exercise_public
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交
ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first
unless @exercise.get_exercise_status(current_user) == 3 && ex_user.present? && ex_user.commit_status == 1 && unless @exercise.get_exercise_status(current_user) == Exercise::ENDED && ex_user.present? && ex_user.commit_status == 1 &&
@exercise.show_statistic @exercise.show_statistic
normal_status(-1,"学生暂不能查看") normal_status(-1,"学生暂不能查看")
end end
@ -1664,19 +1651,19 @@ class ExercisesController < ApplicationController
ex_question_random = exercise.question_random ex_question_random = exercise.question_random
question_answered = 0 question_answered = 0
exercise_questions.each_with_index do |q,index| exercise_questions.each_with_index do |q,index|
if ex_question_random && exercise_user_status != 3 if ex_question_random && exercise_user_status != Exercise::ENDED
ques_number = index + 1 ques_number = index + 1
else else
ques_number = q.question_number ques_number = q.question_number
end end
if q.question_type != 5 if q.question_type != Exercise::PRACTICAL
ques_vote = q.exercise_answers.search_exercise_answer("user_id",user_id) ques_vote = q.exercise_answers.search_exercise_answer("user_id",user_id)
else else
ques_vote = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) ques_vote = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id)
end end
ques_status = 0 ques_status = 0
if ques_vote.present? if ques_vote.present?
if q.question_type == 5 if q.question_type == Exercise::PRACTICAL
if ques_vote.pluck(:exercise_shixun_challenge_id).sort == q.exercise_shixun_challenges.pluck(:id).sort #用户的总得分等于问题的分数 if ques_vote.pluck(:exercise_shixun_challenge_id).sort == q.exercise_shixun_challenges.pluck(:id).sort #用户的总得分等于问题的分数
ques_status = 1 #全部回答了,才算已答 ques_status = 1 #全部回答了,才算已答
question_answered += 1 question_answered += 1
@ -1684,12 +1671,12 @@ class ExercisesController < ApplicationController
else #其他题目,需回答的有内容,才会为已答,否则如内容为空,视为未答 else #其他题目,需回答的有内容,才会为已答,否则如内容为空,视为未答
vote_answer_id = ques_vote.pluck(:exercise_choice_id).reject(&:blank?) vote_answer_id = ques_vote.pluck(:exercise_choice_id).reject(&:blank?)
vote_text_count = ques_vote.pluck(:answer_text).reject(&:blank?).size vote_text_count = ques_vote.pluck(:answer_text).reject(&:blank?).size
if q.question_type <= 2 #选择题和判断题的时候,需要有选项,才算回答 if q.question_type <= Exercise::JUDGMENT #选择题和判断题的时候,需要有选项,才算回答
if vote_answer_id.size > 0 if vote_answer_id.size > 0
ques_status = 1 ques_status = 1
question_answered += 1 question_answered += 1
end end
elsif q.question_type == 3 #填空题的时候,需要有选项和内容,才算回答 elsif q.question_type == Exercise::COMPLETION #填空题的时候,需要有选项和内容,才算回答
if vote_answer_id.uniq.sort == q.exercise_standard_answers.pluck(:exercise_choice_id).uniq.sort if vote_answer_id.uniq.sort == q.exercise_standard_answers.pluck(:exercise_choice_id).uniq.sort
ques_status = 1 ques_status = 1
question_answered += 1 question_answered += 1

@ -36,10 +36,10 @@ elsif student_status == 1
json.question_status question_status json.question_status question_status
end end
exercise_status = exercise.get_exercise_status(ex_answerer) # exercise_status = exercise.get_exercise_status(ex_answerer)
#当前为老师,或为学生,但在试卷截止后且答案选择公开的 #当前为老师,或为学生,但在试卷截止后且答案选择公开的
if is_teacher_or == 1 || (exercise_status == 3 && exercise.answer_open) if is_teacher_or == 1 || (ex_answer_status == Exercise::ENDED && exercise.answer_open)
ex_type = 4 ex_type = 4
else else
ex_type = 3 ex_type = 3
@ -47,7 +47,7 @@ end
json.exercise_questions do json.exercise_questions do
json.array! exercise_questions do |q| json.array! exercise_questions do |q|
user_ques_answers = user_question_answers(q,ex_answerer.id,student_status,is_teacher_or,exercise_status,q.question_type,ex_type) user_ques_answers = user_question_answers(q,ex_answerer.id,student_status,is_teacher_or,ex_answer_status,q.question_type,ex_type)
user_ques_comments = user_ques_answers[:question_comment] user_ques_comments = user_ques_answers[:question_comment]
if all_question_status.size > 0 if all_question_status.size > 0
this_ques_status = all_question_status.detect {|f| f[:q_id] == q.id} this_ques_status = all_question_status.detect {|f| f[:q_id] == q.id}

@ -8,5 +8,6 @@ json.partial! "exercises/user_exercise_info",locals:{exercise:@exercise,
ex_sub_array:@ex_sub_array, ex_sub_array:@ex_sub_array,
exercise_questions:@exercise_questions, exercise_questions:@exercise_questions,
student_status:@student_status, student_status:@student_status,
question_status:@question_status question_status:@question_status,
ex_answer_status:@ex_answer_status
} }

@ -1,18 +0,0 @@
json.total_counts @total_exercise_counts
json.total_user_exercises do
json.array! @all_exercise_stu_array do |a|
json.student_exercise do
json.partial! "exercises/user_exercise_info",locals:{exercise:@exercise,
is_teacher_or:a[:is_teacher],
ex_answerer:a[:ex_answerer],
exercise_user:a[:ex_user],
ex_obj_array:a[:ex_obj_array],
ex_sub_array:a[:ex_sub_array],
exercise_questions:@exercise_questions,
student_status:@student_status,
question_status:@question_status
}
end
end
end

@ -28,7 +28,7 @@
<div style="width: 598px; background:#fff; margin:20px auto; font-size:14px; "> <div style="width: 598px; background:#fff; margin:20px auto; font-size:14px; ">
<div style="height:50px; width: 578px; background:#46484c; padding:9px 10px 6px;border:1px solid #ddd; border-bottom:none;"> <div style="height:50px; width: 578px; background:#46484c; padding:9px 10px 6px;border:1px solid #ddd; border-bottom:none;">
<a href="https://www.educoder.net"> <a href="https://www.educoder.net">
<img src="/images/educoder/headNavLogo.png" width="36" style="float:left; margin-top: 8px;" > <img src="https://www.educoder.net/images/educoder/headNavLogo.png" width="36" style="float:left; margin-top: 8px;" >
</a> </a>
<div style="clear:both; overflow:hidden;"></div> <div style="clear:both; overflow:hidden;"></div>
</div> </div>

Loading…
Cancel
Save