From 114c00da7b6e7b246845f1d2c1ac73725c3f2892 Mon Sep 17 00:00:00 2001 From: Matthias Opitz Date: Thu, 23 Nov 2023 19:00:37 +0000 Subject: [PATCH] added suffix to completion rules --- mod_form.php | 53 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/mod_form.php b/mod_form.php index 7500339..65ce834 100644 --- a/mod_form.php +++ b/mod_form.php @@ -927,9 +927,18 @@ function validation($data, $files) { * @return array Array of string IDs of added items, empty array if none */ public function add_completion_rules() { + global $CFG; + $mform = $this->_form; $plugin = 'mod_hotpot'; + // Changes for Moodle 4.3 - MDL-78516. + if ($CFG->branch < 403) { + $suffix = ''; + } else { + $suffix = $this->get_suffix(); + } + // array of elements names to be returned by this method $names = array(); @@ -945,40 +954,40 @@ public function add_completion_rules() { $value = floatval($this->current->$name); } $group = array(); - $group[] = &$mform->createElement('checkbox', $name.'enabled', '', $label); - $group[] = &$mform->createElement('static', $name.'space', '', '   '); - $group[] = &$mform->createElement('text', $name, '', array('size' => 3)); - $mform->addGroup($group, $name.'group', '', '', false); - $mform->setType($name, PARAM_FLOAT); - $mform->setDefault($name, 0.00); - $mform->setType($name.'enabled', PARAM_INT); - $mform->setDefault($name.'enabled', empty($value) ? 0 : 1); - $mform->disabledIf($name, $name.'enabled', 'notchecked'); - $names[] = $name.'group'; - $disablednames[] = $name.'group'; + $group[] = &$mform->createElement('checkbox', $name . 'enabled' . $suffix, '', $label); + $group[] = &$mform->createElement('static', $name . 'space' . $suffix, '', '   '); + $group[] = &$mform->createElement('text', $name . $suffix, '', array('size' => 3)); + $mform->addGroup($group, $name . 'group' . $suffix, '', '', false); + $mform->setType($name . $suffix, PARAM_FLOAT); + $mform->setDefault($name . $suffix, 0.00); + $mform->setType($name . 'enabled' . $suffix, PARAM_INT); + $mform->setDefault($name . 'enabled . $suffix', empty($value) ? 0 : 1); + $mform->disabledIf($name, $name . 'enabled' . $suffix, 'notchecked'); + $names[] = $name . 'group' . $suffix; + $disablednames[] = $name . 'group' . $suffix; // add "grade passed" completion condition $name = 'completionpass'; $label = get_string($name, $plugin); - $mform->addElement('checkbox', $name, '', $label); - $mform->setType($name, PARAM_INT); - $mform->setDefault($name, 0); - $names[] = $name; - $disablednames[] = $name; + $mform->addElement('checkbox', $name . $suffix, '', $label); + $mform->setType($name . $suffix, PARAM_INT); + $mform->setDefault($name . $suffix, 0); + $names[] = $name . $suffix; + $disablednames[] = $name . $suffix; // add "status completed" completion condition $name = 'completioncompleted'; $label = get_string($name, $plugin); - $mform->addElement('checkbox', $name, '', $label); - $mform->setType($name, PARAM_INT); - $mform->setDefault($name, 0); - $names[] = $name; + $mform->addElement('checkbox', $name . $suffix, '', $label); + $mform->setType($name . $suffix, PARAM_INT); + $mform->setDefault($name . $suffix, 0); + $names[] = $name . $suffix; // no need to disable this field :-) // disable grade conditions, if necessary foreach ($disablednames as $name) { - if ($mform->elementExists($name)) { - $mform->disabledIf($name, 'gradeweighting', 'eq', 0); + if ($mform->elementExists($name . $suffix)) { + $mform->disabledIf($name . $suffix, 'gradeweighting', 'eq', 0); } }