diff --git a/attendance.php b/attendance.php index d34d732..92f8e2e 100644 --- a/attendance.php +++ b/attendance.php @@ -39,7 +39,8 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST) // Require the user is logged in. require_login($course, true, $cm); -if (empty(get_config('attendance', 'studentscanmark')) || empty($attforsession->studentscanmark)) { +if (!attendance_can_student_mark($attforsession)) { + // TODO: should we add a log message here? - student has got to submit page but cannot save attendance (time ran out?) redirect(new moodle_url('/mod/attendance/view.php', array('id' => $cm->id))); exit; } diff --git a/lang/en/attendance.php b/lang/en/attendance.php index c99893e..b8ec66d 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -324,6 +324,10 @@ $string['eventstatusadded'] = 'Status added'; $string['studentscanmark'] = 'Allow students to record own attendance'; $string['studentscanmark_desc'] = 'If checked, teachers will be able to allow students to mark their own attendance.'; $string['studentscanmark_help'] = 'If checked students will be able to change their own attendance status for the session.'; +$string['studentscanmarksessiontime'] = 'Students record attendance during session time'; +$string['studentscanmarksessiontime_desc'] = 'If checked students can only record their attendance during the session.'; +$string['studentscanmarksessiontimeend'] = 'Session end (minutes)'; +$string['studentscanmarksessiontimeend_desc'] = 'If the session does not have an end time, how many minutes should the session be available for students to record their attendance.'; $string['set_by_student'] = 'Self-recorded'; $string['attendance_already_submitted'] = 'You may not self register attendance that has already been set.'; $string['lowgrade'] = 'Low grade'; diff --git a/locallib.php b/locallib.php index 0a98e8a..ccc5a96 100644 --- a/locallib.php +++ b/locallib.php @@ -374,4 +374,29 @@ function attendance_random_string($length=6) { $string .= substr($pool, ($rand % ($poollen)), 1); } return $string; +} + +/** + * Check to see if this session is open for student marking. + * + * @param stdclass $sess the session record from attendance_sessions. + * @return boolean + */ +function attendance_can_student_mark($sess) { + $canmark = false; + $attconfig = get_config('attendance'); + if (!empty($attconfig->studentscanmark) && !empty($sess->studentscanmark)) { + if (empty($attconfig->studentscanmarksessiontime)) { + $canmark = true; + } else { + $duration = $sess->duration; + if (empty($duration)) { + $duration = $attconfig->studentscanmarksessiontimeend * 60; + } + if ($sess->sessdate < time() && time() < ($sess->sessdate + $duration)) { + $canmark = true; + } + } + } + return $canmark; } \ No newline at end of file diff --git a/renderer.php b/renderer.php index e14241b..007225a 100644 --- a/renderer.php +++ b/renderer.php @@ -847,9 +847,10 @@ class mod_attendance_renderer extends plugin_renderer_base { $cell->colspan = 2; $row->cells[] = $cell; } else { - if (!empty(get_config('attendance', 'studentscanmark')) && !empty($sess->studentscanmark)) { + if (attendance_can_student_mark($sess)) { // Student can mark their own attendance. // URL to the page that lets the student modify their attendance. + $url = new moodle_url('/mod/attendance/attendance.php', array('sessid' => $sess->id, 'sesskey' => sesskey())); $cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attendance'))); diff --git a/settings.php b/settings.php index ed71efc..4b9ec09 100644 --- a/settings.php +++ b/settings.php @@ -48,6 +48,15 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configcheckbox('attendance/studentscanmark', get_string('studentscanmark', 'attendance'), get_string('studentscanmark_desc', 'attendance'), 1)); + $settings->add(new admin_setting_configcheckbox('attendance/studentscanmarksessiontime', + get_string('studentscanmarksessiontime', 'attendance'), + get_string('studentscanmarksessiontime_desc', 'attendance'), 1)); + + $settings->add(new admin_setting_configtext('attendance/studentscanmarksessiontimeend', + get_string('studentscanmarksessiontimeend', 'attendance'), + get_string('studentscanmarksessiontimeend_desc', 'attendance'), '60', PARAM_INT)); + + $name = new lang_string('defaultsettings', 'mod_attendance'); $description = new lang_string('defaultsettings_help', 'mod_attendance'); $settings->add(new admin_setting_heading('defaultsettings', $name, $description)); diff --git a/version.php b/version.php index 6f0f810..a646096 100644 --- a/version.php +++ b/version.php @@ -23,9 +23,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016121306; +$plugin->version = 2016121307; $plugin->requires = 2016111800; -$plugin->release = '3.2.6'; +$plugin->release = '3.2.7'; $plugin->maturity = MATURITY_STABLE; $plugin->cron = 0; $plugin->component = 'mod_attendance';