/** * 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 showConfirmation(ilPropertyFormGUI $form, $oldQuestionSetType, $newQuestionSetType, $hasQuestionsWithoutQuestionpool) { require_once 'Modules/Test/classes/confirmations/class.ilTestSettingsChangeConfirmationGUI.php'; $confirmation = new ilTestSettingsChangeConfirmationGUI($this->lng, $this->testOBJ); $confirmation->setFormAction($this->ctrl->getFormAction($this)); $confirmation->setCancel($this->lng->txt('cancel'), self::CMD_SHOW_FORM); $confirmation->setConfirm($this->lng->txt('confirm'), self::CMD_CONFIRMED_SAVE_FORM); $confirmation->setOldQuestionSetType($oldQuestionSetType); $confirmation->setNewQuestionSetType($newQuestionSetType); $confirmation->setQuestionLossInfoEnabled($hasQuestionsWithoutQuestionpool); $confirmation->build(); $confirmation->populateParametersFromPropertyForm($form, $this->activeUser->getTimeZone()); $this->tpl->setContent($this->ctrl->getHTML($confirmation)); }