Skip to content

Commit

Permalink
Merge pull request #48 from odeialba/SV-47
Browse files Browse the repository at this point in the history
SV-47 Fix the completion suffix error
  • Loading branch information
odeialba authored Jan 17, 2024
2 parents 6c9f3d3 + 5592769 commit c1be63b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public function data_postprocessing($data) {
parent::data_postprocessing($data);
// Set up completion section even if checkbox is not ticked.
if (!empty($data->completionunlocked)) {
if (empty($data->completionsubmit)) {
$data->completionsubmit = 0;
if (empty($data->{$this->get_suffixed_name('completionsubmit')})) {
$data->{$this->get_suffixed_name('completionsubmit')} = 0;
}
}
}
Expand All @@ -164,10 +164,11 @@ public function data_postprocessing($data) {
public function add_completion_rules() {
$mform =& $this->_form;

$mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'sortvoting'));
$completionsubmit = $this->get_suffixed_name('completionsubmit');
$mform->addElement('checkbox', $completionsubmit, '', get_string('completionsubmit', 'sortvoting'));
// Enable this completion rule by default.
$mform->setDefault('completionsubmit', 1);
return ['completionsubmit'];
$mform->setDefault($completionsubmit, 1);
return [$completionsubmit];
}

/**
Expand All @@ -177,6 +178,16 @@ public function add_completion_rules() {
* @return bool
*/
public function completion_rule_enabled($data) {
return !empty($data['completionsubmit']);
return !empty($data[$this->get_suffixed_name('completionsubmit')]);
}

/**
* Returns suffixed name.
*
* @param string $fieldname
* @return string
*/
protected function get_suffixed_name(string $fieldname): string {
return $fieldname . $this->get_suffix();
}
}

0 comments on commit c1be63b

Please sign in to comment.