class ExerciseBankQuestion < ApplicationRecord
  belongs_to :exercise_bank
  belongs_to :shixun, optional: true
  has_many :exercise_bank_shixun_challenges,:dependent => :destroy
  has_many :exercise_bank_choices, :dependent => :destroy
  has_many :exercise_bank_standard_answers, :dependent => :destroy
  #attr_accessible :question_number, :question_score, :question_title, :question_type

  scope :insert_question_ex, lambda {|k| where("question_number > ?",k)}
  scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)}  #根据传入的参数查找问题
  scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)}  #根据传入的参数查找问题
  scope :find_objective_questions, -> {where("question_type != ?",4)}  #查找全部客观题

  def question_type_name
    case self.question_type
    when 0
      "单选题"
    when 1
      "多选题"
    when 2
      "判断题"
    when 3
      "填空题"
    when 4
      "简答题"
    when 5
      "实训题"
    end
  end


  #获取问题的全部标准答案
  def get_standard_answer_ids
    exercise_bank_standard_answers.pluck(:exercise_bank_choice_id)
  end

  def get_standard_answer_text
    exercise_bank_standard_answers.pluck(:answer_text)
  end
end