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

added suffix to completion rules #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
53 changes: 31 additions & 22 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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', '', ' &nbsp; ');
$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, '', ' &nbsp; ');
$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);
}
}

Expand Down