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.
63 lines
2.0 KiB
63 lines
2.0 KiB
class ExaminationBanks::SendToCourseService < ApplicationService
|
|
attr_reader :exam, :exercise
|
|
|
|
def initialize(exam, exercise)
|
|
@exam = exam
|
|
@exercise = exercise
|
|
end
|
|
|
|
def call
|
|
ActiveRecord::Base.transaction do
|
|
exercise.exercise_name = exam.name
|
|
exercise.time = exam.duration.present? ? exam.duration : -1
|
|
exercise.is_md = false
|
|
exercise.save!
|
|
|
|
exam.examination_items.each_with_index do |item, index|
|
|
question = exercise.exercise_questions.new
|
|
question.question_type = question_type item.item_type
|
|
question.question_title = item.name
|
|
question.question_number = index + 1
|
|
question.question_score = item.score
|
|
|
|
if item.item_type == "PROGRAM"
|
|
new_hack = item.container.fork
|
|
question.hack_id = new_hack.id
|
|
question.save!
|
|
else
|
|
question.save!
|
|
ExerciseQuestionAnalysis.new(analysis: item.analysis, exercise_question_id: question.id)
|
|
item.item_choices.each_with_index do |choice, position|
|
|
question.exercise_choices << ExerciseChoice.new(choice_text: choice.choice_text, choice_position: position+1)
|
|
if choice.is_answer
|
|
question.exercise_standard_answers << ExerciseStandardAnswer.new(exercise_choice_id: position+1)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
exam.increment!(:quotes)
|
|
end
|
|
exercise
|
|
end
|
|
|
|
def question_type item_type
|
|
question_type = case item_type
|
|
when 'SINGLE'
|
|
Exercise::SINGLE
|
|
when 'MULTIPLE'
|
|
Exercise::MULTIPLE
|
|
when 'JUDGMENT'
|
|
Exercise::JUDGMENT
|
|
when 'COMPLETION'
|
|
Exercise::COMPLETION
|
|
when 'SUBJECTIVE'
|
|
Exercise::SUBJECTIVE
|
|
when 'PRACTICAL'
|
|
Exercise::PRACTICAL
|
|
when 'PROGRAM'
|
|
Exercise::PROGRAM
|
|
end
|
|
question_type
|
|
end
|
|
end |