Merge branch 'sw_new_course' of http://repository.trustie.net/xianbo/trustie2 into sw_new_course
This commit is contained in:
commit
0405d4eee6
|
@ -3,7 +3,7 @@ class ExerciseController < ApplicationController
|
|||
|
||||
before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show]
|
||||
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
|
||||
helper :Exercise
|
||||
include ExerciseHelper
|
||||
|
||||
include ExerciseHelper
|
||||
def index
|
||||
|
@ -30,8 +30,8 @@ class ExerciseController < ApplicationController
|
|||
if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?)
|
||||
redirect_to exercise_index_url(:course_id=> @course.id)
|
||||
else
|
||||
@can_edit_poll = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin?
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
@can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin?
|
||||
# @percent = get_percent(@exercise,User.current)
|
||||
exercise_questions = @exercise.exercise_questions
|
||||
@exercise_questions = paginateHelper exercise_questions,5 #分页
|
||||
respond_to do |format|
|
||||
|
@ -146,7 +146,7 @@ class ExerciseController < ApplicationController
|
|||
if @exercise_questions.save
|
||||
standart_answer = ExerciseStandardAnswer.new
|
||||
standart_answer.exercise_question_id = @exercise_questions.id
|
||||
@exercise_questions.question_type == 3 ? standart_answer.answer_text = params[:exercise_choice] : standart_answer.exercise_choice_id = params[:exercise_choice]
|
||||
@exercise_questions.question_type == 3 ? standart_answer.answer_text = translate_standard_answer(params[:exercise_choice]) : standart_answer.exercise_choice_id = translate_standard_answer(params[:exercise_choice])
|
||||
standart_answer.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
@ -240,6 +240,35 @@ class ExerciseController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
# 获取问题的答案
|
||||
def get_user_answer(question,user)
|
||||
user_answer = question.poll_votes.where("#{PollVote.table_name}.user_id = #{user.id}")
|
||||
user_answer
|
||||
end
|
||||
|
||||
# 是否完成了答题
|
||||
def get_complete_question(exercise,user)
|
||||
questions = exercise.exercise_questions
|
||||
complete_question = []
|
||||
questions.each do |question|
|
||||
answers = get_user_answer(question,user)
|
||||
if !(answers.nil? || answers.count < 1)
|
||||
complete_question << question
|
||||
end
|
||||
end
|
||||
complete_question
|
||||
end
|
||||
|
||||
|
||||
def get_percent exercise,user
|
||||
complete_count = get_complete_question(exercise,user).count
|
||||
if exercise.exercise_questions.count == 0
|
||||
return 0
|
||||
else
|
||||
return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100
|
||||
end
|
||||
end
|
||||
|
||||
def remove_invalid_exercise(course)
|
||||
exercises = course.exercises.where("exercise_name=?","")
|
||||
unless exercises.empty?
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
# encoding: utf-8
|
||||
module ExerciseHelper
|
||||
|
||||
# 单选
|
||||
def translate_standard_answer(params)
|
||||
answer = params.ord - 64
|
||||
end
|
||||
|
||||
#判断用户是否已经提交了问卷
|
||||
def has_commit_exercise?(exercise_id, user_id)
|
||||
pu = ExerciseUser.find_by_excercise_id_and_user_id(exercise_id, user_id)
|
||||
|
|
Loading…
Reference in New Issue