You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/models/item_bank.rb

53 lines
1.4 KiB

class ItemBank < ApplicationRecord
# difficulty: 1 简单 2 适中 3 困难
5 years ago
enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
# item_type: 0 单选 1 多选 2 判断 3 填空 4 简答 5 实训 6 编程
belongs_to :user
belongs_to :sub_discipline, optional: true
has_one :item_analysis, dependent: :destroy
has_many :item_choices, dependent: :destroy
has_many :item_baskets, dependent: :destroy
5 years ago
has_many :tag_discipline_containers, as: :container, dependent: :destroy
has_many :tag_disciplines, through: :tag_discipline_containers
5 years ago
5 years ago
belongs_to :container, polymorphic: true, optional: true
5 years ago
def analysis
5 years ago
item_analysis&.analysis
end
5 years ago
def type_string
result = case item_type
when "SINGLE"
"单选题"
when "MULTIPLE"
"多选题"
when "JUDGMENT"
"判断题"
when "COMPLETION"
"填空题"
when "SUBJECTIVE"
"简答题"
when "PRACTICAL"
"实训题"
when "PROGRAM"
"编程题"
end
result
end
def difficulty_string
result = case difficulty
when 1
"简单"
when 2
"适中"
when 3
"困难"
end
result
end
end