Skip to content

Commit

Permalink
Test: Warn on Old Mark Schema in Personal Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Jan 3, 2025
1 parent 1d06b2d commit 370863a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 27 deletions.
47 changes: 31 additions & 16 deletions components/ILIAS/Test/classes/class.ilObjTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5762,6 +5762,16 @@ public function addDefaults($a_name)
'HideInfoTab' => (int) $main_settings->getAdditionalSettings()->getHideInfoTab(),
];

$marks = array_map(
fn(Mark $v): array => [
'short_name' => $v->getShortName(),
'official_name' => $v->getOfficialName(),
'minimum_level' => $v->getMinimumLevel(),
'passed' => $v->getPassed()
],
$this->getMarkSchema()->getMarkSteps()
);

$next_id = $this->db->nextId('tst_test_defaults');
$this->db->insert(
'tst_test_defaults',
Expand All @@ -5770,30 +5780,35 @@ public function addDefaults($a_name)
'name' => ['text', $a_name],
'user_fi' => ['integer', $this->user->getId()],
'defaults' => ['clob', serialize($testsettings)],
'marks' => ['clob', serialize($this->getMarkSchema()->getMarkSteps())],
'marks' => ['clob', json_encode($marks)],
'tstamp' => ['integer', time()]
]
);
}

/**
* Applies given test defaults to this test
*
* @param array $test_default The test defaults database id.
*
* @return boolean TRUE if the application succeeds, FALSE otherwise
*/
public function applyDefaults(array $test_defaults): bool
public function applyDefaults(array $test_defaults): string
{
$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;
$unserialized_marks = json_decode($test_defaults['marks'], true);

$info = '';
if (is_array($unserialized_marks)
&& is_array($unserialized_marks[0])) {
$this->mark_schema = $this->getMarkSchema()->withMarkSteps(
array_map(
fn(array $v): Mark => new Mark(
$v['short_name'],
$v['official_name'],
$v['minimum_level'],
$v['passed']
),
$unserialized_marks
)
);
} else {
$info = 'old_mark_default_not_applied';
}

$this->mark_schema = $this->getMarkSchema()->withMarkSteps($unserialized_marks);

$this->storeActivationSettings([
'is_activation_limited' => $testsettings['activation_limited'],
'activation_starting_time' => $testsettings['activation_start_time'],
Expand Down Expand Up @@ -5924,7 +5939,7 @@ public function applyDefaults(array $test_defaults): bool
$this->getScoreSettingsRepository()->store($score_settings);
$this->saveToDb();

return true;
return $info;
}

private function convertTimeToDateTimeImmutableIfNecessary(
Expand Down
27 changes: 16 additions & 11 deletions components/ILIAS/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1398,13 +1398,13 @@ public function retrieveAdditionalDidacticTemplateOptions(): array
*/
public function afterSave(ilObject $new_object): void
{
$info = '';
$new_object->saveToDb();

$test_def_id = $this->getSelectedPersonalDefaultsSettingsFromForm();
if ($test_def_id !== null
&& ($defaults = $new_object->getTestDefaults($test_def_id)) !== null
&& !$new_object->applyDefaults($defaults)) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('tst_defaults_apply_not_possible'));
&& ($defaults = $new_object->getTestDefaults($test_def_id)) !== null) {
$info = $new_object->applyDefaults($defaults);
}

$new_object->saveToDb();
Expand All @@ -1420,8 +1420,11 @@ public function afterSave(ilObject $new_object): void
);
}

// always send a message
$this->tpl->setOnScreenMessage('success', $this->lng->txt('object_added'), true);
if ($info === '') {
$this->tpl->setOnScreenMessage('success', $this->lng->txt('object_added'), true);
} else {
$this->tpl->setOnScreenMessage('info', $this->lng->txt($info), true);
}
$this->ctrl->setParameter($this, 'ref_id', $new_object->getRefId());
$this->ctrl->redirectByClass(SettingsMainGUI::class);
}
Expand Down Expand Up @@ -2007,13 +2010,13 @@ public function applyDefaultsObject($confirmed = false): void
}

// do not apply if user datasets exist
if ($this->getTestObject()->evalTotalPersons() > 0) {
if ($this->getTestObject()->evalTotalPersons() > 0
|| ($defaults = $this->getTestObject()->getTestDefaults($defaults_id[0])) === null) {
$this->tpl->setOnScreenMessage('info', $this->lng->txt('tst_defaults_apply_not_possible'));
$this->defaultsObject();
return;
}

$defaults = $this->getTestObject()->getTestDefaults($defaults_id[0]);
$default_settings = unserialize(
$defaults['defaults'],
['allowed_classes' => [DateTimeImmutable::class]]
Expand Down Expand Up @@ -2068,12 +2071,14 @@ public function applyDefaultsObject($confirmed = false): void
$this->tpl->setOnScreenMessage('info', $info, true);
}

if (is_array($defaults) && !$this->getTestObject()->applyDefaults($defaults)) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('tst_defaults_apply_not_possible'));
$this->ctrl->redirect($this, 'defaults');
$info = $this->getTestObject()->applyDefaults($defaults);
if ($info === '') {
$this->tpl->setOnScreenMessage('success', $this->lng->txt('tst_defaults_applied'), true);
} else {
$this->tpl->setOnScreenMessage('info', $this->lng->txt($info), true);
}

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


if ($question_set_type_setting_switched && $old_question_set_config->doesQuestionSetRelatedDataExist()) {
$old_question_set_config->removeQuestionSetRelatedData();
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ assessment#:#not_yet_accessed#:#Noch kein Zugriff erfolgt
assessment#:#nr_of_correct_answers#:#Anzahl der erwünschten Antworten
assessment#:#number_of_answers#:#Anzahl der Antworten
assessment#:#numeric_gap#:#Numerische Lücke
assessment#:#old_mark_default_not_applied#:#Das Notenschma aus Ihren persönlichen Einstellungen konnte nicht übernommen werden, da es ein altes Format verwendet. Alle anderen Einstellungen wurden angewendet.
assessment#:#option_label#:#Optionsbezeichnungen
assessment#:#option_label_adequate#:#adäquat
assessment#:#option_label_adequate_or_not#:#adäquat / nicht adäquat
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ assessment#:#not_yet_accessed#:#Not yet accessed
assessment#:#nr_of_correct_answers#:#Number of Requested Answers
assessment#:#number_of_answers#:#Number of Answers
assessment#:#numeric_gap#:#Numeric Gap
assessment#:#old_mark_default_not_applied#:#The marks from your personal settings could not be applied as they use an old format. All other settings have been updated.
assessment#:#option_label#:#Option Labels
assessment#:#option_label_adequate#:#adequate
assessment#:#option_label_adequate_or_not#:#adequate / not adequate
Expand Down

0 comments on commit 370863a

Please sign in to comment.