试卷题库

dev_aliyun_beta
cxt 6 years ago
parent d403789253
commit 51fe553ff9

@ -0,0 +1,2 @@
class ExerciseBankQuestionsController < ApplicationController
end

@ -1,3 +1,4 @@
#encoding: UTF-8
class ExerciseBanksController < ApplicationController
before_action :require_login
before_action :find_bank

@ -0,0 +1,2 @@
module ExerciseBankQuestionsHelper
end

@ -2,4 +2,5 @@ class ExerciseBankStandardAnswer < ApplicationRecord
belongs_to :exercise_bank_question
belongs_to :exercise_bank_choice
#attr_accessible :answer_text
scope :standard_by_ids, lambda { |s| where(exercise_bank_choice_id: s) }
end

@ -0,0 +1,69 @@
json.question_id question.id
q_positon = question.question_number
if ques_position.present?
q_positon = ques_position
end
json.q_position q_positon
json.question_title question.question_title
json.question_type question.question_type
json.question_score question.question_score.round(1).to_s
if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置
standard_answers_array = question.get_standard_answer_ids
exercise_choices = choices.order("choice_position ASC")
json.question_choices exercise_choices.each do |a|
#TODO: 旧版本来一个题只有一个标准答案的新版又做成了一个题有多个标准答案exercise_choice_id存放的是标准答案的位置..
standard_answer_b = standard_answers_array.join("").include?(a.choice_position.to_s)
choice_text = a.choice_text
if question.question_type == 2
if choice_text == "对"
choice_text = "正确"
end
if choice_text == "错"
choice_text = "错误"
end
end
json.choice_id a.id
# json.choice_text (edit_type.present? || question.question_type == 2) ? a.choice_text : "#{(index+65).chr}.#{a.choice_text}"
json.choice_text choice_text
json.choice_position a.choice_position
json.standard_boolean standard_answer_b
end
json.standard_answer standard_answers_array
if question.question_type == 2 #返回答案的文字
standard_text = standard_answers_array.first.to_i == 1 ? "正确" : "错误"
else
array_text_answer = []
standard_answers_array.each{|a| array_text_answer.push((a+64).chr)}
standard_text = array_text_answer.join("")
end
json.standard_answer_show standard_text
elsif question.question_type == 3 #当为填空题时
standard_answers_count = question.exercise_bank_standard_answers
standard_answer_ex = standard_answers_count.pluck(:exercise_bank_choice_id).uniq
json.is_ordered question.is_ordered
json.multi_count standard_answer_ex.size #有几个填空
json.standard_answer do
json.array! standard_answer_ex.each do |a|
s_answer_text = standard_answers_count.standard_by_ids(a).pluck(:answer_text)
json.choice_id a
json.answer_text s_answer_text
end
end
elsif question.question_type == 4 #简答题时
json.standard_answer question.exercise_bank_standard_answers.pluck(:answer_text)
elsif question.question_type == 5
json.shixun_id question.shixun_id
json.shixun_name question.shixun_name.present? ? question.shixun_name : ""
json.shixun_identifier question.shixun.identifier
json.shixun do
json.array! shixun_challenges do |s|
json.challenge_id s.challenge_id
json.challenge_position s.position
json.challenge_name s.challenge.subject
json.challenge_score s.question_score.round(1).to_s
end
end
end

@ -6,13 +6,10 @@ json.partial! "exercises/exercise_scores"
json.exercise_questions do
json.array! @exercise_questions do |q|
json.partial! "exercise_questions/exercise_questions",
json.partial! "exercise_bank_questions/exercise_bank_questions",
question: q,
choices:q.exercise_bank_choices,
shixun_challenges: q.exercise_bank_shixun_challenges,
exercise_type:1,
user_answer:[],
shixun_type:0,
ques_position:nil,
edit_type:nil
end

@ -0,0 +1,5 @@
class AddIsOrderedToExerciseBankQuestion < ActiveRecord::Migration[5.2]
def change
add_column :exercise_bank_questions, :is_ordered, :boolean, :default => true
end
end
Loading…
Cancel
Save