|
|
|
@ -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)
|
|
|
|
|