Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T&A 41629: Fix handling of deleted global templates #8338

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions Modules/Test/classes/class.ilObjTestSettingsGeneralGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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)
Expand All @@ -163,32 +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) {
$title = $this->settingsTemplate->getTitle();
if (!$this->settingsTemplate) {
return;
}

$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);
}

global $DIC;
$tpl = $DIC['tpl'];

$link = $this->ctrl->getLinkTarget($this, self::CMD_SHOW_RESET_TPL_CONFIRM);
$link = "<a href=\"" . $link . "\">" . $this->lng->txt("test_using_template_link") . "</a>";

$msgHTML = ilUtil::getSystemMessageHTML(
sprintf($this->lng->txt("test_using_template"), $title, $link),
"info"
);

$msgHTML = "<div style=\"margin-top:10px\">$msgHTML</div>";
$message = sprintf($this->lng->txt('test_using_template'), $title, $this->ui_renderer->render($link));
} else {
$msgHTML = '';
$message = sprintf($this->lng->txt('test_using_removed_template'), $this->ui_renderer->render($link));
}

return $msgHTML;
$this->tpl->setOnScreenMessage(
$this->settingsTemplate->isAvailable() ? 'info' : 'failure',
$message,
!$this->settingsTemplate->isAvailable()
);
}

private function confirmedSaveFormCmd(): void
Expand Down Expand Up @@ -975,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());
}

Expand Down
6 changes: 4 additions & 2 deletions Modules/Test/test/ilObjTestSettingsGeneralGUITest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilObjTestSettingsGeneralGUITest
* @author Marvin Beym <[email protected]>
Expand All @@ -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));
Expand Down
14 changes: 11 additions & 3 deletions Services/Administration/classes/class.ilSettingsTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> */
private array $hidden_tab = [];
private bool $auto_generated = false;
private ?ilSettingsTemplateConfig $config = null;
private bool $available = true;

public function __construct(
int $a_id = 0,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -188,6 +194,7 @@ public function read(): void
" id = " . $ilDB->quote($this->getId(), "integer")
);
if ($ilDB->numRows($set) === 0) {
$this->available = false;
return;
}

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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ö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
Expand Down
3 changes: 2 additions & 1 deletion lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Loading