From 4e4c2542d2b9e33104cc3f3e01d92662e7561354 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Wed, 25 Aug 2021 20:11:43 +1200 Subject: [PATCH] Prevent automarking settings from being used if setunmarked status not in place. --- classes/form/addsession.php | 21 +++++++++++---------- classes/form/updatesession.php | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/classes/form/addsession.php b/classes/form/addsession.php index ece7d8b..331f1fe 100644 --- a/classes/form/addsession.php +++ b/classes/form/addsession.php @@ -207,19 +207,20 @@ class addsession extends moodleform { $mform->addElement('hidden', 'studentscanmark', '0'); $mform->settype('studentscanmark', PARAM_INT); } + if ($DB->record_exists('attendance_statuses', ['attendanceid' => $this->_customdata['att']->id, 'setunmarked' => 1])) { + $options = attendance_get_automarkoptions(); - $options = attendance_get_automarkoptions(); + $mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options); + $mform->setType('automark', PARAM_INT); + $mform->addHelpButton('automark', 'automark', 'attendance'); + $mform->setDefault('automark', $this->_customdata['att']->automark); - $mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options); - $mform->setType('automark', PARAM_INT); - $mform->addHelpButton('automark', 'automark', 'attendance'); - $mform->setDefault('automark', $this->_customdata['att']->automark); + $automarkcmoptions = attendance_get_coursemodulenames($course->id); - $automarkcmoptions = attendance_get_coursemodulenames($course->id); - - $mform->addElement('select', 'automarkcmid', get_string('selectactivity', 'attendance'), $automarkcmoptions); - $mform->setType('automarkcmid', PARAM_INT); - $mform->hideif('automarkcmid', 'automark', 'neq', '3'); + $mform->addElement('select', 'automarkcmid', get_string('selectactivity', 'attendance'), $automarkcmoptions); + $mform->setType('automarkcmid', PARAM_INT); + $mform->hideif('automarkcmid', 'automark', 'neq', '3'); + } if (!empty($studentscanmark)) { $mgroup = array(); diff --git a/classes/form/updatesession.php b/classes/form/updatesession.php index 140d538..e3bdab9 100644 --- a/classes/form/updatesession.php +++ b/classes/form/updatesession.php @@ -143,21 +143,22 @@ class updatesession extends \moodleform { $mform->settype('studentscanmark', PARAM_INT); } - $options2 = attendance_get_automarkoptions(); + if ($DB->record_exists('attendance_statuses', ['attendanceid' => $this->_customdata['att']->id, 'setunmarked' => 1])) { + $options2 = attendance_get_automarkoptions(); - $mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options2); - $mform->setType('automark', PARAM_INT); - $mform->addHelpButton('automark', 'automark', 'attendance'); + $mform->addElement('select', 'automark', get_string('automark', 'attendance'), $options2); + $mform->setType('automark', PARAM_INT); + $mform->addHelpButton('automark', 'automark', 'attendance'); - $automarkcmoptions2 = attendance_get_coursemodulenames($COURSE->id); + $automarkcmoptions2 = attendance_get_coursemodulenames($COURSE->id); - $mform->addElement('select', 'automarkcmid', get_string('selectactivity', 'attendance'), $automarkcmoptions2); - $mform->setType('automarkcmid', PARAM_INT); - $mform->hideif('automarkcmid', 'automark', 'neq', '3'); - if (!empty($sess->automarkcompleted)) { - $mform->hardFreeze('automarkcmid,automark,studentscanmark'); + $mform->addElement('select', 'automarkcmid', get_string('selectactivity', 'attendance'), $automarkcmoptions2); + $mform->setType('automarkcmid', PARAM_INT); + $mform->hideif('automarkcmid', 'automark', 'neq', '3'); + if (!empty($sess->automarkcompleted)) { + $mform->hardFreeze('automarkcmid,automark,studentscanmark'); + } } - if (!empty($studentscanmark)) { $mform->addElement('text', 'studentpassword', get_string('studentpassword', 'attendance')); $mform->setType('studentpassword', PARAM_TEXT);