From 5cf889e9b6d7a9d0935c7f40f9a0bab7cc9074fa Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Thu, 31 Oct 2024 13:10:53 +0100 Subject: [PATCH 1/6] fix: add handling to remove deleted global template by adding default property initialization and showing failure message (41629) --- .../class.ilObjTestSettingsGeneralGUI.php | 28 ++++++++----------- .../classes/class.ilSettingsTemplate.php | 14 ++++++++-- lang/ilias_de.lang | 1 + lang/ilias_en.lang | 3 +- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php b/Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php index 6c6fd434ddf6..81fbb8a13cc9 100644 --- a/Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php +++ b/Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php @@ -165,30 +165,26 @@ private function showConfirmation(ilPropertyFormGUI $form, $oldQuestionSetType, protected function getSettingsTemplateMessageHTML(): string { - if ($this->settingsTemplate) { - $title = $this->settingsTemplate->getTitle(); + if (!$this->settingsTemplate) { + return ''; + } + $link = $this->ctrl->getLinkTarget($this, self::CMD_SHOW_RESET_TPL_CONFIRM); + $link = '' . $this->lng->txt('test_using_template_link') . ''; + + if ($this->settingsTemplate->isAvailable()) { + $title = $this->settingsTemplate->getTitle(); if ($this->settingsTemplate->getAutoGenerated()) { $title = $this->lng->txt($title); } - global $DIC; - $tpl = $DIC['tpl']; - - $link = $this->ctrl->getLinkTarget($this, self::CMD_SHOW_RESET_TPL_CONFIRM); - $link = "" . $this->lng->txt("test_using_template_link") . ""; - - $msgHTML = ilUtil::getSystemMessageHTML( - sprintf($this->lng->txt("test_using_template"), $title, $link), - "info" - ); - - $msgHTML = "
$msgHTML
"; + $message = sprintf($this->lng->txt('test_using_template'), $title, $link); } else { - $msgHTML = ''; + $message = sprintf($this->lng->txt('test_using_removed_template'), $link); } - return $msgHTML; + $type = $this->settingsTemplate->isAvailable() ? 'info' : 'failure'; + return '
' . ilUtil::getSystemMessageHTML($message, $type) . '
'; } private function confirmedSaveFormCmd(): void diff --git a/Services/Administration/classes/class.ilSettingsTemplate.php b/Services/Administration/classes/class.ilSettingsTemplate.php index 40b2fe562234..cba37e313c08 100644 --- a/Services/Administration/classes/class.ilSettingsTemplate.php +++ b/Services/Administration/classes/class.ilSettingsTemplate.php @@ -28,14 +28,15 @@ class ilSettingsTemplate { protected ilDBInterface $db; private int $id; - private string $type; - private string $title; - private string $description; + private string $type = ''; + private string $title = ''; + private string $description = ''; private array $setting = []; /** @var array */ private array $hidden_tab = []; private bool $auto_generated = false; private ?ilSettingsTemplateConfig $config = null; + private bool $available = true; public function __construct( int $a_id = 0, @@ -103,6 +104,11 @@ public function getDescription(): string return $this->description; } + public function isAvailable(): bool + { + return $this->available; + } + /** * Set setting * @param array|string $a_value @@ -188,6 +194,7 @@ public function read(): void " id = " . $ilDB->quote($this->getId(), "integer") ); if ($ilDB->numRows($set) === 0) { + $this->available = false; return; } @@ -220,6 +227,7 @@ public function read(): void while ($rec = $ilDB->fetchAssoc($set)) { $this->addHiddenTab($rec["tab_id"]); } + $this->available = true; } public function create(): void diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index 359292544f4b..0b879ee0a97f 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -1262,6 +1262,7 @@ assessment#:#test_question_set_type_random_info#:#Jedem Teilnehmenden werden unt assessment#:#test_results#:#Bekanntgabe des Testergebnisses assessment#:#test_scoring#:#Bewertung des Tests assessment#:#test_template_reset#:#Die Vorlage wurde entfernt. +assessment#:#test_using_removed_template#:#Dieser Test verwendet eine gelöscht Vorlage. Bitte entfernen Sie die Verknüpfung hier: %s. assessment#:#test_using_template#:#Dieser Test verwendet die Vorlage %s. Wenn Sie keine Vorlage und alle Einstellungen verwenden wollen, klicken Sie bitte hier: %s. assessment#:#test_using_template_link#:#Vorlage nicht mehr verwenden assessment#:#text_correct#:#Korrekter Text diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 5cb78e32f34e..6454a6fca038 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -1262,6 +1262,7 @@ assessment#:#test_question_set_type_random_info#:#Each test participant will see assessment#:#test_results#:#Summary Test Results assessment#:#test_scoring#:#Scoring Options assessment#:#test_template_reset#:#The template has been removed. +assessment#:#test_using_removed_template#:#This test uses a deleted template. Please remove the connection here: %s. assessment#:#test_using_template#:#This test uses the template %s. If you do not want to use a template and have access to all settings, please click here: %s. assessment#:#test_using_template_link#:#Do not use template anymore assessment#:#text_correct#:#Correct Text @@ -14173,7 +14174,7 @@ registration#:#reg_direct_info#:#New user registration requests are automaticall registration#:#reg_disabled#:#No Registration Possible registration#:#reg_domain#:#Domain registration#:#reg_domain_already_assigned_p#:#The domains '%s' were already entered for another role. -registration#:#reg_domain_already_assigned_s#:#The domain '%s' was already entered for another role. +registration#:#reg_domain_already_assigned_s#:#The domain '%s' was already entered for another role. registration#:#reg_email#:#Automatic Role Assignment registration#:#reg_email_domains#:#The following e-mail address domains are valid: %s registration#:#reg_email_domains_code#:#With a registration code any E-Mail-Address is valid. From 8a0010e4b4db42435a9ab923ffafc8f86c25bca0 Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer <47783030+lukas-heinrich@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:56:18 +0100 Subject: [PATCH 2/6] style: fix typo in error message --- lang/ilias_de.lang | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index 0b879ee0a97f..64e734e6c9b9 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -1262,7 +1262,7 @@ assessment#:#test_question_set_type_random_info#:#Jedem Teilnehmenden werden unt assessment#:#test_results#:#Bekanntgabe des Testergebnisses assessment#:#test_scoring#:#Bewertung des Tests assessment#:#test_template_reset#:#Die Vorlage wurde entfernt. -assessment#:#test_using_removed_template#:#Dieser Test verwendet eine gelöscht Vorlage. Bitte entfernen Sie die Verknüpfung hier: %s. +assessment#:#test_using_removed_template#:#Dieser Test verwendet eine gelöschte Vorlage. Bitte entfernen Sie die Verknüpfung hier: %s. assessment#:#test_using_template#:#Dieser Test verwendet die Vorlage %s. Wenn Sie keine Vorlage und alle Einstellungen verwenden wollen, klicken Sie bitte hier: %s. assessment#:#test_using_template_link#:#Vorlage nicht mehr verwenden assessment#:#text_correct#:#Korrekter Text @@ -17206,4 +17206,4 @@ wsp#:#wsp_type_ltiv#:#Zertifikat: LTI-Konsument wsp#:#wsp_type_scov#:#Zertifikat: SCORM wsp#:#wsp_type_tstv#:#Zertifikat: Test wsp#:#wsp_type_webr#:#Weblink -wsp#:#wsp_type_wfld#:#Ordner \ No newline at end of file +wsp#:#wsp_type_wfld#:#Ordner From 9fa191d1c754c765c8aebe9e6e55cbca5c5c5626 Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Wed, 6 Nov 2024 13:00:53 +0100 Subject: [PATCH 3/6] refactor: use ui factory and renderer instead of html tags --- .../class.ilObjTestSettingsGeneralGUI.php | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php b/Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php index 81fbb8a13cc9..5a5a350e1b2e 100644 --- a/Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php +++ b/Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php @@ -17,6 +17,8 @@ *********************************************************************/ use Psr\Http\Message\RequestInterface; +use ILIAS\UI\Factory as UIFactory; +use ILIAS\UI\Renderer as UIRenderer; /** * GUI class that manages the editing of general test settings/properties @@ -61,6 +63,8 @@ class ilObjTestSettingsGeneralGUI extends ilTestSettingsGUI protected ilObjTestGUI $testGUI; private ilTestQuestionSetConfigFactory $testQuestionSetConfigFactory; private RequestInterface $request; + private UIFactory $ui_factory; + private UIRenderer $ui_renderer; public function __construct( ilCtrlInterface $ctrl, @@ -93,6 +97,8 @@ public function __construct( $testGUI->getTestObject() ); $this->request = $DIC->http()->request(); + $this->ui_factory = $DIC->ui()->factory(); + $this->ui_renderer = $DIC->ui()->renderer(); parent::__construct($testGUI->getTestObject()); } @@ -138,10 +144,8 @@ private function showFormCmd(ilPropertyFormGUI $form = null) $form = $this->buildForm(); } - $formHTML = $this->ctrl->getHTML($form); - $msgHTML = $this->getSettingsTemplateMessageHTML(); - - $this->tpl->setContent($formHTML . $msgHTML); + $this->tpl->setContent($this->ctrl->getHTML($form)); + $this->populateSettingsTemplateMessage(); } private function showConfirmation(ilPropertyFormGUI $form, $oldQuestionSetType, $newQuestionSetType, $hasQuestionsWithoutQuestionpool) @@ -163,28 +167,32 @@ private function showConfirmation(ilPropertyFormGUI $form, $oldQuestionSetType, $this->tpl->setContent($this->ctrl->getHTML($confirmation)); } - protected function getSettingsTemplateMessageHTML(): string + protected function populateSettingsTemplateMessage(): void { if (!$this->settingsTemplate) { - return ''; + return; } - $link = $this->ctrl->getLinkTarget($this, self::CMD_SHOW_RESET_TPL_CONFIRM); - $link = '' . $this->lng->txt('test_using_template_link') . ''; - + $link = $this->ui_factory->link()->standard( + $this->lng->txt('test_using_template_link'), + $this->ctrl->getLinkTarget($this, self::CMD_SHOW_RESET_TPL_CONFIRM) + ); if ($this->settingsTemplate->isAvailable()) { $title = $this->settingsTemplate->getTitle(); if ($this->settingsTemplate->getAutoGenerated()) { $title = $this->lng->txt($title); } - $message = sprintf($this->lng->txt('test_using_template'), $title, $link); + $message = sprintf($this->lng->txt('test_using_template'), $title, $this->ui_renderer->render($link)); } else { - $message = sprintf($this->lng->txt('test_using_removed_template'), $link); + $message = sprintf($this->lng->txt('test_using_removed_template'), $this->ui_renderer->render($link)); } - $type = $this->settingsTemplate->isAvailable() ? 'info' : 'failure'; - return '
' . ilUtil::getSystemMessageHTML($message, $type) . '
'; + $this->tpl->setOnScreenMessage( + $this->settingsTemplate->isAvailable() ? 'info' : 'failure', + $message, + !$this->settingsTemplate->isAvailable() + ); } private function confirmedSaveFormCmd(): void @@ -971,7 +979,7 @@ private function addTestRunProperties(ilPropertyFormGUI $form) $duration->setShowMinutes(true); $pw_time_array = ["00", "000", "00", "00", "00"]; - if($this->testOBJ->getPassWaiting() !== '') { + if ($this->testOBJ->getPassWaiting() !== '') { $pw_time_array = explode(':', $this->testOBJ->getPassWaiting()); } From d2b3dc684d89ff3ce76e11a589b559d54169f956 Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Wed, 6 Nov 2024 16:36:24 +0100 Subject: [PATCH 4/6] fix: add missing global mocks in ilObjTestSettingsGeneralGUITest --- Modules/Test/test/ilObjTestSettingsGeneralGUITest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Modules/Test/test/ilObjTestSettingsGeneralGUITest.php b/Modules/Test/test/ilObjTestSettingsGeneralGUITest.php index 23705ada873f..3b2d2dffd330 100644 --- a/Modules/Test/test/ilObjTestSettingsGeneralGUITest.php +++ b/Modules/Test/test/ilObjTestSettingsGeneralGUITest.php @@ -1,7 +1,5 @@ @@ -38,6 +38,8 @@ protected function setUp(): void $this->addGlobal_tree(); $this->addGlobal_ilAppEventHandler(); $this->addGlobal_objDefinition(); + $this->addGlobal_uiRenderer(); + $this->addGlobal_uiFactory(); $objTestGui_mock = $this->getMockBuilder(ilObjTestGUI::class)->disableOriginalConstructor()->onlyMethods(array('getTestObject'))->getMock(); $objTestGui_mock->method('getTestObject')->willReturn($this->createMock(ilObjTest::class)); From 4f777918f419026939b8c15ed838fa19c81f455f Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Wed, 6 Nov 2024 16:52:57 +0100 Subject: [PATCH 5/6] fix: sort langfile ilias_de.lang --- lang/ilias_de.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index 64e734e6c9b9..d38d75fa35a0 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -17206,4 +17206,4 @@ wsp#:#wsp_type_ltiv#:#Zertifikat: LTI-Konsument wsp#:#wsp_type_scov#:#Zertifikat: SCORM wsp#:#wsp_type_tstv#:#Zertifikat: Test wsp#:#wsp_type_webr#:#Weblink -wsp#:#wsp_type_wfld#:#Ordner +wsp#:#wsp_type_wfld#:#Ordner \ No newline at end of file From baef3e2df40e9f482e479659413305ada9fb2631 Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Thu, 7 Nov 2024 09:33:55 +0100 Subject: [PATCH 6/6] fix: update copyright header in class.ilSettingsTemplate.php --- Services/Administration/classes/class.ilSettingsTemplate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Services/Administration/classes/class.ilSettingsTemplate.php b/Services/Administration/classes/class.ilSettingsTemplate.php index cba37e313c08..ec4cc145ba2d 100644 --- a/Services/Administration/classes/class.ilSettingsTemplate.php +++ b/Services/Administration/classes/class.ilSettingsTemplate.php @@ -1,7 +1,5 @@