dev_jupyter
cxt 5 years ago
parent d2385d0802
commit f5609c987b

@ -26,12 +26,14 @@ class ExaminationBanksController < ApplicationController
if item.present?
new_item = ExaminationItem.new(examination_bank: exam, item_bank: item, name: item.name, item_type: item.item_type,
difficulty: item.difficulty, score: basket.score, position: basket.position)
if new_item.save!
item.increment!(:quotes)
if item.item_choices.present?
item.item_choices.each do |choice|
new_item.examination_item_choices << ExaminationItemChoice.new(choice_text: choice.choice_text, is_answer: choice.is_answer)
end
new_item.save!
item.increment!(:quotes)
if item.item_type == "PROGRAM"
new_hack = item.container.fork
new_item.update_attributes!(container: new_hack)
elsif item.item_choices.present?
item.item_choices.each do |choice|
new_item.examination_item_choices << ExaminationItemChoice.new(choice_text: choice.choice_text, is_answer: choice.is_answer)
end
end
end

@ -1,6 +1,10 @@
class ExaminationItem < ApplicationRecord
enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
belongs_to :examination_bank, touch: true
belongs_to :item_bank, optional: true
has_many :examination_item_choices, dependent: :destroy
belongs_to :container, polymorphic: true, optional: true
end

@ -22,6 +22,7 @@ class Hack < ApplicationRecord
belongs_to :sub_discipline
has_one :item_bank, as: :container, dependent: :destroy
has_one :examination_bank, as: :container, dependent: :destroy
scope :published, -> { where(status: 1) }
scope :unpublish, -> { where(status: 0) }
@ -56,4 +57,31 @@ class Hack < ApplicationRecord
user_id == user.id || user.admin_or_business?
end
# 复制fork
def fork
new_hack = Hack.new
new_hack.attributes = self.attributes.dup.except("id", "user_id", "status", "identifier", "comments_count", "praises_count",
"pass_num", "created_at", "updated_at", "hack_user_lastest_codes_count",
"open_or_not", "submit_num")
new_hack.user_id = User.current.id
new_hack.identifier = Util::UUID.generate_identifier(Hack, 8)
new_hack.fork_id = self.id
new_hack.save!
# 创建测试集与代码
hack_sets.each do |set|
new_hack.hack_sets.create!(input: set.input, output: set.output, position: set.position)
end
# 新建知识点
tag_discipline_containers.each do |tag|
new_hack.tag_discipline_containers.create!(tag_discipline_id: tag.tag_discipline_id)
end
hack_codes.each do |code|
new_hack.hack_codes.create!(code: code.code, language: code.language, modify_time: Time.now)
end
new_hack
end
end

@ -30,9 +30,9 @@ class ItemBaskets::SaveItemBasketService < ApplicationService
else
score =
case item_type
when 0, 1, 2
when "SINGLE", "MULTIPLE", "JUDGMENT"
5
when 6
when "PROGRAM"
10
else
5

@ -0,0 +1,7 @@
class AddForkIdToHacks < ActiveRecord::Migration[5.2]
def change
add_column :hacks, :fork_id, :integer, default: 0
add_column :examination_items, :container_id, :integer
add_column :examination_items, :container_type, :string
end
end
Loading…
Cancel
Save