MDL-74516 workshop: Better handling of floats for gradepass fields

This re-applies the same fix that was used for the central mod form
to the workshop activity. This is needed because the completion
support for this module is custom (there are 2 grade items), hence
the validations are also custom.

For more information, read the previous commit and MDL-74516

Unfortunately, because of a related bug with assessment completion
(see MDL-69690) we cannot provide automated testing for this
activity. Manual instructions will be provided instead.
This commit is contained in:
Eloy Lafuente (stronk7) 2022-06-27 00:27:59 +02:00
parent b3b1006201
commit 64bf0e9165

View File

@ -97,10 +97,9 @@ class mod_workshop_mod_form extends moodleform_mod {
$mform->setDefault('grade', $workshopconfig->grade);
$mform->addHelpButton('submissiongradegroup', 'submissiongrade', 'workshop');
$mform->addElement('text', 'submissiongradepass', get_string('gradetopasssubmission', 'workshop'));
$mform->addElement('float', 'submissiongradepass', get_string('gradetopasssubmission', 'workshop'));
$mform->addHelpButton('submissiongradepass', 'gradepass', 'grades');
$mform->setDefault('submissiongradepass', '');
$mform->setType('submissiongradepass', PARAM_RAW);
$label = get_string('gradinggrade', 'workshop');
$mform->addGroup(array(
@ -110,10 +109,9 @@ class mod_workshop_mod_form extends moodleform_mod {
$mform->setDefault('gradinggrade', $workshopconfig->gradinggrade);
$mform->addHelpButton('gradinggradegroup', 'gradinggrade', 'workshop');
$mform->addElement('text', 'gradinggradepass', get_string('gradetopassgrading', 'workshop'));
$mform->addElement('float', 'gradinggradepass', get_string('gradetopassgrading', 'workshop'));
$mform->addHelpButton('gradinggradepass', 'gradepass', 'grades');
$mform->setDefault('gradinggradepass', '');
$mform->setType('gradinggradepass', PARAM_RAW);
$options = array();
for ($i = 5; $i >= 0; $i--) {
@ -469,7 +467,14 @@ class mod_workshop_mod_form extends moodleform_mod {
isset($data['completiongradeitemnumber'])) {
$itemnames = component_gradeitems::get_itemname_mapping_for_component('mod_workshop');
$gradepassfield = $itemnames[(int) $data['completiongradeitemnumber']] . 'gradepass';
if (!isset($data[$gradepassfield]) || grade_floatval($data[$gradepassfield]) == 0) {
// We need to make all the validations related with $gradepassfield
// with them being correct floats, keeping the originals unmodified for
// later validations / showing the form back...
// TODO: Note that once MDL-73994 is fixed we'll have to re-visit this and
// adapt the code below to the new values arriving here, without forgetting
// the special case of empties and nulls.
$gradepass = isset($data[$gradepassfield]) ? unformat_float($data[$gradepassfield]) : null;
if (is_null($gradepass) || $gradepass == 0) {
$errors['completionpassgrade'] = get_string(
'activitygradetopassnotset',
'completion'