From 7ea69132f7b8804a79c0774006d95b56d5b0f572 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Tue, 15 Oct 2019 14:45:05 +1300 Subject: [PATCH] Fix #425 new setting to control which sessions appear in the mobile app. --- classes/output/mobile.php | 10 ++++++---- lang/en/attendance.php | 6 ++++++ settings.php | 12 ++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/classes/output/mobile.php b/classes/output/mobile.php index 7ea7e9b..13ea491 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -70,6 +70,7 @@ class mobile { $attendance = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); + $config = get_config('attendance'); $data = array(); // Data to pass to renderer. $data['cmid'] = $cmid; @@ -126,14 +127,15 @@ class mobile { } } - // Get list of sessions within the next 24hrs and in last 6hrs. - // TODO: provide way of adjusting which sessions to show in app. - $time = time() - (6 * 60 * 60); + // Get list of sessions based on site level settings. default = the next 24hrs and in last 6hrs. + $timefrom = time() - $config->mobilesessionfrom; + $timeto = time() + $config->mobilesessionto; $data['sessions'] = array(); $sessions = $DB->get_records_select('attendance_sessions', - 'attendanceid = ? AND sessdate > ? ORDER BY sessdate', array($attendance->id, $time)); + 'attendanceid = ? AND sessdate > ? AND sessdate < ? ORDER BY sessdate', + array($attendance->id, $timefrom, $timeto)); if (!empty($sessions)) { $userdata = new \attendance_user_data($att, $USER->id, true); diff --git a/lang/en/attendance.php b/lang/en/attendance.php index 93abce7..0435a76 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -275,6 +275,12 @@ $string['maxpossiblepoints'] = 'Maximum possible points'; $string['maxwarn'] = 'Maximum number of e-mail warnings'; $string['maxwarn_help'] = 'The maximum number of times a warning should be sent (only one warning per session is sent)'; $string['mergeuser'] = 'Merge user'; +$string['mobilesessionfrom'] = 'Show sessions older than the last'; +$string['mobilesessionfrom_help'] = 'Allows the list of sessions to be restricted when marking in the app - only shows sessions that started since this value'; +$string['mobilesessionto'] = 'Show future sessions'; +$string['mobilesessionto_help'] = 'Allows the list of sessions to be restricted to only show a small number of future sessions.'; +$string['mobilesettings'] = 'Mobile app settings'; +$string['mobilesettings_help'] = 'These settings control Moodle mobile app behaviour'; $string['modulename'] = 'Attendance'; $string['modulename_help'] = 'The attendance activity module enables a teacher to take attendance during class and students to view their own attendance record. diff --git a/settings.php b/settings.php index 88ce361..534f865 100644 --- a/settings.php +++ b/settings.php @@ -105,6 +105,18 @@ if ($ADMIN->fulltree) { get_string('enablewarnings', 'attendance'), get_string('enablewarnings_desc', 'attendance'), 0)); + $name = new lang_string('mobilesettings', 'mod_attendance'); + $description = new lang_string('mobilesettings_help', 'mod_attendance'); + $settings->add(new admin_setting_heading('mobilesettings', $name, $description)); + + $settings->add(new admin_setting_configduration('attendance/mobilesessionfrom', + get_string('mobilesessionfrom', 'attendance'), get_string('mobilesessionfrom_help', 'attendance'), + 6 * HOURSECS, PARAM_RAW)); + + $settings->add(new admin_setting_configduration('attendance/mobilesessionto', + get_string('mobilesessionto', 'attendance'), get_string('mobilesessionto_help', 'attendance'), + 24 * HOURSECS, PARAM_RAW)); + $name = new lang_string('defaultsettings', 'mod_attendance'); $description = new lang_string('defaultsettings_help', 'mod_attendance'); $settings->add(new admin_setting_heading('defaultsettings', $name, $description));