Skip to content

Commit

Permalink
Conditionally add suffix to completion rule elements
Browse files Browse the repository at this point in the history
Use unsiffxed completionpass identifier for help button
  • Loading branch information
Lyannic committed Jun 13, 2024
1 parent d428344 commit df232ce
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,33 @@ public function add_completion_rules() : array {
$items = array();

$group = array();
$completionpasselement = $this->get_completion_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_element_name('completionusegrade');
$mform->disabledIf($completionpasselement, $completionusegradeelement, 'notchecked');
$completionpassgroupelement = $this->get_completion_element_name('completionpassgroup');
$mform->addGroup($group, $completionpassgroupelement, get_string('completionpass', 'mumie'), '   ', false);
$mform->addHelpButton($completionpassgroupelement, 'completionpass', 'mumie');
$items[] = $completionpassgroupelement;
return $items;
}

private function get_completion_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 +490,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_element_name('completionpass');
return !empty($data[$completionpasselement]);
}


Expand Down

0 comments on commit df232ce

Please sign in to comment.