Skip to content

Commit

Permalink
Merge pull request #77 from integral-learning/76-wrong-suffix-custom-…
Browse files Browse the repository at this point in the history
…completion-rule

Conditionally add suffix to completion rule elements
  • Loading branch information
Lyannic authored Jun 13, 2024
2 parents d428344 + 722bcec commit f05ada5
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,41 @@ public function add_completion_rules() : array {
$items = array();

$group = array();
$completionpasselement = $this->get_completion_rule_element_name('completionpass');
$group[] = $mform->createElement(
'advcheckbox',
'completionpass',
$completionpasselement,
null,
get_string('completionpass', 'mumie'),
array('group' => 'cpass')
);
$mform->disabledIf('completionpass', 'completionusegrade', 'notchecked');
$mform->addGroup($group, 'completionpassgroup', get_string('completionpass', 'mumie'), '   ', false);
$mform->addHelpButton('completionpassgroup', 'completionpass', 'mumie');
$items[] = 'completionpassgroup';
$completionusegradeelement = $this->get_completion_rule_element_name('completionusegrade');
$mform->disabledIf($completionpasselement, $completionusegradeelement, 'notchecked');
$completionpassgroupelement = $this->get_completion_rule_element_name('completionpassgroup');
$mform->addGroup($group, $completionpassgroupelement, get_string('completionpass', 'mumie'), '   ', false);
$mform->addHelpButton($completionpassgroupelement, 'completionpass', 'mumie');
$items[] = $completionpassgroupelement;
return $items;
}

/**
* Get the completion rule's element name.
*
* Conditionally add suffix for Moodle >= 4.3.
*
* @param string $rawname The raw name of the completion rule.
* @return string The properly suffixed element name.
*/
private function get_completion_rule_element_name($rawname) : string {
global $CFG;
if ($CFG->branch < 403) {
$suffix = '';
} else {
$suffix = $this->get_suffix();
}
return $rawname . $suffix;
}

/**
* Disable all options for grades if the user has chosen to link a course instead of a problem.
*/
Expand Down Expand Up @@ -477,7 +498,8 @@ function ($server) use ($data) {
* @return bool True if one or more rules is enabled, false if none are.
*/
public function completion_rule_enabled($data) : bool {
return !empty($data['completionpass']);
$completionpasselement = $this->get_completion_rule_element_name('completionpass');
return !empty($data[$completionpasselement]);
}


Expand Down

0 comments on commit f05ada5

Please sign in to comment.