From 5502f623c2659831260bf6be9f49dd97b7189d9c Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 26 Aug 2021 09:14:01 +1200 Subject: [PATCH] Allow status with no availability value set to be included in auto-marking. --- classes/structure.php | 13 ++++++++++--- db/upgrade.php | 10 ++++++++++ lang/en/attendance.php | 2 ++ settings.php | 4 ++++ version.php | 4 ++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/classes/structure.php b/classes/structure.php index 17e051a..cc1e7f3 100644 --- a/classes/structure.php +++ b/classes/structure.php @@ -1309,9 +1309,16 @@ class mod_attendance_structure { } } else { foreach ($statuses as $status) { - if ($status->studentavailability !== '0' && - $this->sessioninfo[$sessionid]->sessdate + ($status->studentavailability * 60) > $time) { - + if ($status->studentavailability === '0') { + // This status not available to students. + continue; + } + if (empty($status->studentavailability) && ($session->sessdate + $duration >= $time) && + !empty(get_config('attendance', 'automark_useempty'))) { + // This is set to null - always available to students until end of session.. + return $status->id; + } + if ($this->sessioninfo[$sessionid]->sessdate + ($status->studentavailability * 60) > $time) { // Found first status we could set. return $status->id; } diff --git a/db/upgrade.php b/db/upgrade.php index cba434a..76c35b6 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -691,5 +691,15 @@ function xmldb_attendance_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2021082402, 'attendance'); } + if ($oldversion < 2021082600) { + // Check if auto-marking in use, and if so, set automark_useempty = 0 to prevent changes in existing behaviour. + if ($DB->record_exists_select('attendance_sessions', 'automark > 0')) { + set_config('automark_useempty', '0', 'attendance'); + } + + // Attendance savepoint reached. + upgrade_mod_savepoint(true, 2021082600, 'attendance'); + } + return $result; } diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 2f30a9f..76b9fd7 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -76,6 +76,8 @@ $string['attrecords'] = 'Attendances records'; $string['autoassignstatus'] = 'Automatically select highest status available'; $string['autoassignstatus_help'] = 'If this is selected, students will automatically be assigned the highest available grade.'; $string['automark'] = 'Automatic marking'; +$string['automarkuseempty'] = 'Auto-mark status availability handling'; +$string['automarkuseempty_desc'] = 'If ticked, status items that have an empty/unset "available for" setting will be allowed during auto-marking'; $string['selectactivity'] = 'Select activity'; $string['automark_help'] = 'Allows marking to be completed automatically. If "Yes" students will be automatically marked depending on their first access to the course. diff --git a/settings.php b/settings.php index 9713075..6a3bf11 100644 --- a/settings.php +++ b/settings.php @@ -106,6 +106,10 @@ if ($ADMIN->fulltree) { get_string('enablewarnings', 'attendance'), get_string('enablewarnings_desc', 'attendance'), 0)); + $settings->add(new admin_setting_configcheckbox('attendance/automark_useempty', + get_string('automarkuseempty', 'attendance'), + get_string('automarkuseempty_desc', 'attendance'), 1)); + $fields = array('id' => get_string('studentid', 'attendance')); $customfields = profile_get_custom_fields(); foreach ($customfields as $field) { diff --git a/version.php b/version.php index 2479dc1..ddac001 100755 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2021082403; +$plugin->version = 2021082600; $plugin->requires = 2021051700; // Requires 3.11. -$plugin->release = '3.11.9'; +$plugin->release = '3.11.10'; $plugin->maturity = MATURITY_STABLE; $plugin->cron = 0; $plugin->component = 'mod_attendance';