Skip to content

Commit

Permalink
MBS-8800: Add suffix for default completion
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-csg committed Feb 16, 2024
1 parent c63fdc2 commit 8484c7c
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function definition_after_data() {
* @return bool
*/
public function completion_rule_enabled($data): bool {
return (!empty($data['completiontype']) && $data['completiontype'] > 0);
return (!empty($data['completiontype' . $this->get_suffix()]));
}

/**
Expand All @@ -181,18 +181,20 @@ public function add_completion_rules(): array {
custom_completion::COMPLETION_WITH_ALL_PLACES => get_string('completion_with_all_places', 'mod_learningmap'),
];

$completiontype = 'completiontype' . $this->get_suffix();

$mform->addElement(
'select',
'completiontype',
$completiontype,
get_string('completiontype', 'learningmap'),
$completionoptions,
[]
);

$mform->setType('completiontype', PARAM_INT);
$mform->hideIf('completiontype', 'completion', 'neq', COMPLETION_TRACKING_AUTOMATIC);
$mform->setType($completiontype, PARAM_INT);
$mform->hideIf($completiontype, 'completion', 'neq', COMPLETION_TRACKING_AUTOMATIC);

return(['completiontype']);
return([$completiontype]);
}

/**
Expand Down Expand Up @@ -259,11 +261,27 @@ public function data_preprocessing(&$defaultvalues): void {
* @return void
*/
public function data_postprocessing($data): void {
$mapworker = new mapworker(
$data->introeditor['text'],
json_decode($data->placestore, true)
);
$mapworker->replace_stylesheet();
$data->introeditor['text'] = $mapworker->get_svgcode();
// As this form is also used for setting the default completion settings, there might not be an actual learningmap.
if (!empty($data->introeditor['text'])) {
$mapworker = new mapworker(
$data->introeditor['text'],
json_decode($data->placestore, true)
);
$mapworker->replace_stylesheet();
$data->introeditor['text'] = $mapworker->get_svgcode();
}
}

/**
* Get the suffix to be added to the completion elements when creating them.
* This acts as a spare for compatibility with Moodle 4.1 and 4.2.
*
* @return string The suffix
*/
public function get_suffix(): string {
if (method_exists(get_parent_class($this), 'get_suffix')) {
return parent::get_suffix();
}
return '';
}
}

0 comments on commit 8484c7c

Please sign in to comment.