Example #1
0
 /**
  * Applies the selected test defaults
  */
 public function applyDefaultsObject($confirmed = false)
 {
     if (count($_POST["chb_defaults"]) != 1) {
         ilUtil::sendInfo($this->lng->txt("tst_defaults_apply_select_one"));
         return $this->defaultsObject();
     }
     // do not apply if user datasets exist
     if ($this->object->evalTotalPersons() > 0) {
         ilUtil::sendInfo($this->lng->txt("tst_defaults_apply_not_possible"));
         return $this->defaultsObject();
     }
     $defaults =& $this->object->getTestDefaults($_POST["chb_defaults"][0]);
     $defaultSettings = unserialize($defaults["defaults"]);
     if (isset($defaultSettings['isRandomTest'])) {
         if ($defaultSettings['isRandomTest']) {
             $newQuestionSetType = ilObjTest::QUESTION_SET_TYPE_RANDOM;
             $this->object->setQuestionSetType(ilObjTest::QUESTION_SET_TYPE_RANDOM);
         } else {
             $newQuestionSetType = ilObjTest::QUESTION_SET_TYPE_FIXED;
             $this->object->setQuestionSetType(ilObjTest::QUESTION_SET_TYPE_FIXED);
         }
     } elseif (isset($defaultSettings['questionSetType'])) {
         $newQuestionSetType = $defaultSettings['questionSetType'];
     }
     $oldQuestionSetType = $this->object->getQuestionSetType();
     $questionSetTypeSettingSwitched = $oldQuestionSetType != $newQuestionSetType;
     $oldQuestionSetConfig = $this->testQuestionSetConfigFactory->getQuestionSetConfigByType($oldQuestionSetType);
     switch (true) {
         case !$questionSetTypeSettingSwitched:
         case !$oldQuestionSetConfig->doesQuestionSetRelatedDataExist():
         case $confirmed:
             break;
         default:
             require_once 'Modules/Test/classes/confirmations/class.ilTestSettingsChangeConfirmationGUI.php';
             $confirmation = new ilTestSettingsChangeConfirmationGUI($this->lng, $this->object);
             $confirmation->setFormAction($this->ctrl->getFormAction($this));
             $confirmation->setCancel($this->lng->txt('cancel'), 'defaults');
             $confirmation->setConfirm($this->lng->txt('confirm'), 'confirmedApplyDefaults');
             $confirmation->setOldQuestionSetType($this->object->getQuestionSetType());
             $confirmation->setNewQuestionSetType($newQuestionSetType);
             $confirmation->setQuestionLossInfoEnabled(false);
             $confirmation->build();
             $confirmation->populateParametersFromPost();
             $this->tpl->setContent($this->ctrl->getHTML($confirmation));
             return;
     }
     if ($questionSetTypeSettingSwitched && $this->object->isOnline()) {
         $this->object->setOnline(false);
         $info = $this->lng->txt("tst_set_offline_due_to_switched_question_set_type_setting");
         ilUtil::sendInfo($info, true);
     }
     $this->object->applyDefaults($defaults);
     ilUtil::sendSuccess($this->lng->txt("tst_defaults_applied"), true);
     if ($questionSetTypeSettingSwitched && $oldQuestionSetConfig->doesQuestionSetRelatedDataExist()) {
         $oldQuestionSetConfig->removeQuestionSetRelatedData();
     }
     $this->ctrl->redirect($this, 'defaults');
 }
 private function saveFormCmd($isConfirmedSave = false)
 {
     $form = $this->buildForm();
     // form validation and initialisation
     $errors = !$form->checkInput();
     // ALWAYS CALL BEFORE setValuesByPost()
     $form->setValuesByPost();
     // NEVER CALL THIS BEFORE checkInput()
     // Sarcasm? No. Because checkInput checks the form graph against the POST without
     // actually setting the values into the form. Sounds ridiculous? Indeed, and it is.
     // return to form when any form validation errors exist
     if ($errors) {
         ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
         return $this->showFormCmd($form);
     }
     // return to form when online is to be set, but no questions are configured
     $currentQuestionSetConfig = $this->testQuestionSetConfigFactory->getQuestionSetConfig();
     if ($form->getItemByPostVar('online')->getChecked() && !$this->testOBJ->isComplete($currentQuestionSetConfig)) {
         $form->getItemByPostVar('online')->setAlert($this->lng->txt("cannot_switch_to_online_no_questions_andor_no_mark_steps"));
         ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
         return $this->showFormCmd($form);
     }
     // solve conflicts with question set type setting with confirmation screen if required
     // determine wether question set type relating data is to be removed (questions/pools)
     $questionSetTypeRelatingDataCleanupRequired = false;
     if ($form->getItemByPostVar('question_set_type') instanceof ilFormPropertyGUI) {
         $oldQuestionSetType = $this->testOBJ->getQuestionSetType();
         $newQuestionSetType = $form->getItemByPostVar('question_set_type')->getValue();
         if (!$this->testOBJ->participantDataExist() && $newQuestionSetType != $oldQuestionSetType) {
             $oldQuestionSetConfig = $this->testQuestionSetConfigFactory->getQuestionSetConfigByType($oldQuestionSetType);
             if ($oldQuestionSetConfig->doesQuestionSetRelatedDataExist()) {
                 if (!$isConfirmedSave) {
                     if ($oldQuestionSetType == ilObjTest::QUESTION_SET_TYPE_FIXED) {
                         return $this->showConfirmation($form, $oldQuestionSetType, $newQuestionSetType, $this->testOBJ->hasQuestionsWithoutQuestionpool());
                     }
                     return $this->showConfirmation($form, $oldQuestionSetType, $newQuestionSetType, false);
                 }
                 $questionSetTypeRelatingDataCleanupRequired = true;
             }
             if ($form->getItemByPostVar('online')->getChecked()) {
                 $form->getItemByPostVar('online')->setChecked(false);
                 if ($this->testOBJ->isOnline()) {
                     $infoMsg = $this->lng->txt("tst_set_offline_due_to_switched_question_set_type_setting");
                 } else {
                     $infoMsg = $this->lng->txt("tst_cannot_online_due_to_switched_quest_set_type_setting");
                 }
                 ilUtil::sendInfo($infoMsg, true);
             }
         }
     }
     // adjust use previous answers setting due to desired question set type
     if ($newQuestionSetType != ilObjTest::QUESTION_SET_TYPE_FIXED) {
         $form->getItemByPostVar('chb_use_previous_answers')->setValue(0);
     }
     // perform saving the form data
     $this->performSaveForm($form);
     // clean up test mode relating configuration data (questions/questionpools)
     if ($questionSetTypeRelatingDataCleanupRequired) {
         $oldQuestionSetConfig->removeQuestionSetRelatedData();
     }
     // disinvite all invited users if required
     if (!$this->testOBJ->participantDataExist() && !$this->testOBJ->getFixedParticipants()) {
         foreach ($this->testOBJ->getInvitedUsers() as $usrId => $usrData) {
             $this->testOBJ->disinviteUser($usrId);
         }
     }
     // redirect to form output
     ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
     $this->ctrl->redirect($this, self::CMD_SHOW_FORM);
 }