Skip to content

Commit

Permalink
Test: Fix Applying Default Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Dec 7, 2024
1 parent 720ee32 commit 7dc2c57
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
12 changes: 10 additions & 2 deletions components/ILIAS/ILIASObject/classes/class.ilObjectGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,19 @@ public function saveObject(): void
*/
public function getDidacticTemplateVar(string $type): int
{
if (!$this->post_wrapper->has("didactic_type")) {
$create_form = $this->initCreateForm($this->type);
if ($create_form instanceof StandardForm) {
$data = $create_form->withRequest($this->request)->getData();
return isset($data['didactic_templates'])
? $this->parseDidacticTemplateVar($data['didactic_templates'], $type)
: 0;
}

if (!$this->post_wrapper->has('didactic_type')) {
return 0;
}

$tpl = $this->post_wrapper->retrieve("didactic_type", $this->refinery->kindlyTo()->string());
$tpl = $this->post_wrapper->retrieve('didactic_type', $this->refinery->kindlyTo()->string());
return $this->parseDidacticTemplateVar($tpl, $type);
}

Expand Down
10 changes: 5 additions & 5 deletions components/ILIAS/Test/classes/class.ilObjTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5951,11 +5951,11 @@ public function addDefaults($a_name)
*/
public function applyDefaults($test_defaults): bool
{
$testsettings = unserialize($test_defaults['defaults']);
$unserialized_marks = unserialize($test_defaults['marks']);

if ($unserialized_marks instanceof MarkSchema) {
$unserialized_marks = $unserialized_marks->getMarkSteps();
$testsettings = unserialize($test_defaults['defaults'], ['allowed_classes' => [DateTimeImmutable::class]]);
try {
$unserialized_marks = unserialize($test_defaults['marks'], ['allowed_classes' => [Mark::class]]);
} catch (Exception $e) {
return false;
}

$this->mark_schema = $this->getMarkSchema()->withMarkSteps($unserialized_marks);
Expand Down
31 changes: 16 additions & 15 deletions components/ILIAS/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1397,15 +1397,12 @@ public function afterSave(ilObject $new_object): void
{
$new_object->saveToDb();

$test_def_id = $this->getDidacticTemplateVar("tstdef");
$test_def_id = $this->getDidacticTemplateVar('tstdef');
if ($test_def_id !== 0) {
$test_defaults = $new_object->getTestDefaults($test_def_id);
$new_object->applyDefaults($test_defaults);
}

$template_id = $this->getDidacticTemplateVar("tsttpl");
if ($template_id) {
$new_object->setTemplate($template_id);
if (!$new_object->applyDefaults($test_defaults)) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('tst_defaults_apply_not_possible'));
}
}

$new_object->saveToDb();
Expand All @@ -1422,7 +1419,7 @@ public function afterSave(ilObject $new_object): void
}

// always send a message
$this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
$this->tpl->setOnScreenMessage('success', $this->lng->txt('object_added'), true);
$this->ctrl->setParameter($this, 'ref_id', $new_object->getRefId());
$this->ctrl->redirectByClass(SettingsMainGUI::class);
}
Expand Down Expand Up @@ -1990,10 +1987,9 @@ public function confirmedApplyDefaultsObject()
*/
public function applyDefaultsObject($confirmed = false): void
{
$defaults = $this->testrequest->retrieveArrayOfIntsFromPost('chb_defaults');
if ($defaults !== []) {
$defaults_id = $this->testrequest->retrieveArrayOfIntsFromPost('chb_defaults');
if ($defaults_id === []) {
$this->tpl->setOnScreenMessage('info', $this->lng->txt('tst_defaults_apply_select_one'));

$this->defaultsObject();
return;
}
Expand All @@ -2005,7 +2001,11 @@ public function applyDefaultsObject($confirmed = false): void
return;
}

$default_settings = unserialize($defaults[0]['defaults'], ['allowed_classes' => false]);
$defaults = $this->getTestObject()->getTestDefaults($defaults_id[0]);
$default_settings = unserialize(
$defaults['defaults'],
['allowed_classes' => [DateTimeImmutable::class]]
);

if (isset($default_settings['isRandomTest'])) {
if ($default_settings['isRandomTest']) {
Expand Down Expand Up @@ -2052,13 +2052,14 @@ public function applyDefaultsObject($confirmed = false): void

if ($question_set_type_setting_switched && !$this->getTestObject()->getOfflineStatus()) {
$this->getTestObject()->setOfflineStatus(true);

$info = $this->lng->txt('tst_set_offline_due_to_switched_question_set_type_setting');

$this->tpl->setOnScreenMessage('info', $info, true);
}

$this->getTestObject()->applyDefaults($defaults);
if (!$this->getTestObject()->applyDefaults($defaults)) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('tst_defaults_apply_not_possible'));
$this->ctrl->redirect($this, 'defaults');
}

$this->tpl->setOnScreenMessage('success', $this->lng->txt('tst_defaults_applied'), true);

Expand Down
12 changes: 0 additions & 12 deletions components/ILIAS/Test/src/Scoring/Marks/Mark.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ public function __construct(
) {
}

/**
* Stephan Kergomard, 2023-11-08: We need an explicit __unserialize function
* here because of changes to the corresponding classes with ILIAS 8.
*/
public function __unserialize(array $data): void
{
$this->short_name = $data['short_name'];
$this->official_name = $data['short_name'];
$this->minimum_level = (float) $data['minimum_level'];
$this->passed = (int) $data['passed'];
}

public function getShortName(): string
{
return $this->short_name;
Expand Down

0 comments on commit 7dc2c57

Please sign in to comment.