app/controllers/questionnaires_controller.rb
# clones the contents of a questionnaire, including the questions and associated advice
clones the contents of a questionnaire, including the questions and associated advice
clones the contents of a questionnaire including the questions and associated advice
def copy_questionnaire_details(questions, orig_questionnaire)
    @questionnaire.instructor_id = assign_instructor_id
    @questionnaire.name = 'Copy of ' + orig_questionnaire.name
    begin
      @questionnaire.created_at = Time.now
      @questionnaire.save!
      questions.each do |question|
        new_question = question.dup
        new_question.questionnaire_id = @questionnaire.id
        new_question.size = '50,3' if (new_question.is_a? Criterion or new_question.is_a? TextResponse) and new_question.size.nil?
        new_question.save!
        advices = QuestionAdvice.where(question_id: question.id)
        next if advices.empty?
        advices.each do |advice|
          new_advice = advice.dup
          new_advice.question_id = new_question.id
          new_advice.save!
        end
      end
      pFolder = TreeFolder.find_by(name: @questionnaire.display_type)
      parent = FolderNode.find_by(node_object_id: pFolder.id)
      QuestionnaireNode.find_or_create_by(parent_id: parent.id, node_object_id: @questionnaire.id)
      undo_link("Copy of questionnaire #{orig_questionnaire.name} has been created successfully.")
      redirect_to controller: 'questionnaires', action: 'view', id: @questionnaire.id
    rescue StandardError
      flash[:error] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO
      redirect_to action: 'list', controller: 'tree_display'
    end
  end
def copy_questionnaire_details ( questions , orig_questionnaire ) @questionnaire . instructor_id = assign_instructor_id @questionnaire . name = 'Copy of ' + orig_questionnaire . name begin @questionnaire . created_at = Time . now @questionnaire . save! questions . each do | question | new_question = question . dup new_question . questionnaire_id = @questionnaire . id new_question . size = '50,3' if ( new_question . is_a? Criterion or new_question . is_a? TextResponse ) and new_question . size . nil? new_question . save! advices = QuestionAdvice . where ( question_id : question . id ) next if advices . empty? advices . each do | advice | new_advice = advice . dup new_advice . question_id = new_question . id new_advice . save! end end pFolder = TreeFolder . find_by ( name : @questionnaire . display_type ) parent = FolderNode . find_by ( node_object_id : pFolder . id ) QuestionnaireNode . find_or_create_by ( parent_id : parent . id , node_object_id : @questionnaire . id ) undo_link ( "Copy of questionnaire #{orig_questionnaire.name} has been created successfully." ) redirect_to controller : 'questionnaires' , action : 'view' , id : @questionnaire . id rescue StandardError flash [ :error ] = 'The questionnaire was not able to be copied. Please check the original course for missing information.' + $ERROR_INFO redirect_to action : 'list' , controller : 'tree_display' end end
clones the contents of a questionnaire, including the questions and associated advice
clones the contents of a questionnaire including the questions and associated advice
questions
orig_questionnaire