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

MBS-8000: Add suffix for default completion #94

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
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 (function_exists('parent::get_suffix')) {
return parent::get_suffix();
}
return '';
}
}
Loading