From 231590bfccfdea544f681a9bb858a93088fe62ce Mon Sep 17 00:00:00 2001 From: Stephan Kergomard Date: Wed, 29 Jan 2025 10:25:46 +0200 Subject: [PATCH] Test: Fix LongMenu Saving on Creation See: https://mantis.ilias.de/view.php?id=43705 --- .../classes/class.assLongMenuGUI.php | 23 ++++++++++++------- .../classes/class.assQuestionGUI.php | 4 +--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/components/ILIAS/TestQuestionPool/classes/class.assLongMenuGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assLongMenuGUI.php index b13271d90ab5..9158098ce747 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assLongMenuGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assLongMenuGUI.php @@ -33,8 +33,6 @@ class assLongMenuGUI extends assQuestionGUI implements ilGuiQuestionScoringAdjus private readonly UIFactory $ui_factory; private readonly UIRenderer $ui_renderer; - private ?ilPropertyFormGUI $edit_form = null; - public function __construct($id = -1) { parent::__construct(); @@ -59,17 +57,17 @@ public function getCommand($cmd) */ protected function writePostData(bool $always = false): int { - $this->edit_form = $this->buildEditForm(); - $this->edit_form->setValuesByPost(); - $check = $this->edit_form->checkInput() && $this->verifyAnswerOptions(); + $this->editForm = $this->buildEditForm(); + $this->editForm->setValuesByPost(); + $check = $this->editForm->checkInput() && $this->verifyAnswerOptions(); if (!$check) { $this->editQuestion(); return 1; } $this->writeQuestionGenericPostData(); - $this->writeQuestionSpecificPostData($this->edit_form); - $custom_check = $this->object->checkQuestionCustomPart($this->edit_form); + $this->writeQuestionSpecificPostData($this->editForm); + $custom_check = $this->object->checkQuestionCustomPart($this->editForm); if (!$custom_check) { $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid')); $this->editQuestion(); @@ -151,11 +149,20 @@ public function editQuestion( bool $checkonly = false, ?bool $is_save_cmd = null ): bool { - $form = $this->edit_form; + $form = $this->editForm; if ($form === null) { $form = $this->buildEditForm(); } + /* + * sk 29.01.2025: This is a god aw-ful hack and one more sign, + * that the flow here needs to change, but we need this to set the + * question id on question creation (see: https://mantis.ilias.de/view.php?id=43705) + */ + if ($this->object->getId() > 0) { + $this->ctrl->setParameterByClass(self::class, 'q_id', $this->object->getId()); + } + $form->setFormAction($this->ctrl->getFormActionByClass(self::class)); $this->renderEditForm($form); return false; } diff --git a/components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php index 1d04283de4b5..3a3c8d88500a 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php @@ -114,8 +114,6 @@ abstract class assQuestionGUI protected GeneralQuestionPropertiesRepository $questionrepository; protected GUIService $notes_gui; protected ilCtrl $ctrl; - private array $new_id_listeners = []; - private int $new_id_listener_cnt = 0; private ?ilAssQuestionPreviewSession $preview_session = null; protected assQuestion $object; protected ilGlobalPageTemplate $tpl; @@ -150,7 +148,7 @@ abstract class assQuestionGUI private bool $previousSolutionPrefilled = false; - protected ilPropertyFormGUI $editForm; + protected ?ilPropertyFormGUI $editForm = null; protected readonly ilTestLegacyFormsHelper $forms_helper; protected readonly RequestDataCollector $request_data_collector; protected bool $parent_type_is_lm = false;