Merge branch 'sw_new_course' of http://repository.trustie.net/xianbo/trustie2 into sw_new_course

This commit is contained in:
cxt 2015-11-19 14:36:45 +08:00
commit cf4717278f
1 changed files with 38 additions and 11 deletions

View File

@ -188,15 +188,14 @@ class ExerciseController < ApplicationController
@exercise_question = ExerciseQuestion.find params[:exercise_question]
@exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
@exercise_question.question_score = params[:question_score]
################处理选项
# 处理选项
if params[:question_answer]
# @exercise_question.exercise_choices.each do |answer|
# answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
# end
# 界面需要判断选择题至少有一个选项
for i in 1..@exercise_question.exercise_choices.count
@exercise_question.exercise_choices.each do |answer|
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
end
for i in 1..params[:question_answer].count
question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1]
# answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
if question
question.exercise_choices_id = i
question.answer_text = answer
@ -265,9 +264,10 @@ class ExerciseController < ApplicationController
end
end
# 学生提交答卷
# 学生提交答卷,选着答案的课程中提交
def commit_answer
eq = ExerciseQuestion.find(params[:poll_question_id])
eq = ExerciseQuestion.find(params[:exercise_question_id])
# 已提交过的则不允许答题
if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?)
render :json => {:text => "failure"}
return
@ -369,11 +369,12 @@ class ExerciseController < ApplicationController
# 老师不需要提交
if User.current.allowed_to?(:as_teacher,@course)
redirect_to exercise_url(@exercise)
# REDO: 提示提交成功
else
# 答题过程中需要统计完成量
@uncomplete_question = get_uncomplete_question(@exercise, User.current)
# 获取改学生的考试得分
score = get_answer_score(@exercise)
score = calculate_student_score(@exercise, User.current)
if @uncomplete_question.count < 1
# 查看是否有已提交记录
eu = get_exercise_user(@exercise.id, User.current.id)
@ -395,6 +396,26 @@ class ExerciseController < ApplicationController
end
end
# 计算学生得分
def calculate_student_score(exercise, user)
score = 0
exercise_qustions = exercise.exercise_questions
exercise_qustions.each do |question|
answer = get_user_answer(question, user)
standard_answer = get_user_standard_answer(question, user)
# 问答题有多个答案
if question.question_type == 3
if standard_answer.exercise_choice_id.include?(answer.exercise_choice_id)
score = score + question.question_score
end
else
if answer.exercise_choice_id == standard_answer.exercise_choice_id
score = score + question.question_score
end
end
end
score
end
private
# ExerciseUser记录用户是否已提交问卷有对应的记录则已提交没有则新建一个
@ -419,12 +440,18 @@ class ExerciseController < ApplicationController
uncomplete_question
end
# 获取问题的答案
# 获取当前学生回答问题的答案
def get_user_answer(question,user)
user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
user_answer
end
# 获取问题的标准答案
def get_user_standard_answer(question,user)
standard_answer = question.exercise_standard_answers
standard_answer
end
# 是否完成了答题
def get_complete_question(exercise,user)
questions = exercise.exercise_questions