Fixes #223 allow student attendance to be disabled at site-level MOODLE_29_STABLE
authorDan Marsden <dan@danmarsden.com>
Mon, 26 Sep 2016 22:25:34 +0000 (11:25 +1300)
committerDan Marsden <dan@danmarsden.com>
Mon, 26 Sep 2016 22:29:43 +0000 (11:29 +1300)
add_form.php
attendance.php
lang/en/attendance.php
renderer.php
sessions.php
settings.php

index 700c337..d69dfa0 100644 (file)
@@ -118,8 +118,13 @@ class mod_attendance_add_form extends moodleform {
         }
 
         // Students can mark own attendance.
-        $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance'));
-        $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance');
+        if (!empty(get_config('attendance', 'studentscanmark'))) {
+            $mform->addElement('checkbox', 'studentscanmark', '', get_string('studentscanmark', 'attendance'));
+            $mform->addHelpButton('studentscanmark', 'studentscanmark', 'attendance');
+        } else {
+            $mform->addElement('hidden', 'studentscanmark', '0');
+            $mform->settype('studentscanmark', PARAM_INT);
+        }
 
         $mform->addElement('editor', 'sdescription', get_string('description', 'attendance'), array('rows' => 1, 'columns' => 80),
                             array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $modcontext));
index 0a7a2ba..8b9bda8 100644 (file)
@@ -39,6 +39,10 @@ $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)) {
+    redirect(new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)));
+    exit;
+}
 $pageparams->sessionid = $id;
 $att = new mod_attendance_structure($attendance, $cm, $course, $PAGE->context, $pageparams);
 
index 8c1f312..a13a0ab 100644 (file)
@@ -293,6 +293,7 @@ $string['eventstatusupdated'] = 'Status updated';
 $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['set_by_student'] = 'Self-recorded';
 $string['attendance_already_submitted'] = 'You may not self register attendance that has already been set.';
index fe86450..263ec34 100644 (file)
@@ -806,7 +806,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
                 $cell->colspan = 2;
                 $row->cells[] = $cell;
             } else {
-                if (!empty($sess->studentscanmark)) { // Student can mark their own attendance.
+                if (!empty(get_config('attendance', 'studentscanmark')) && !empty($sess->studentscanmark)) {
+                    // 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()));
index dc790f8..ee52e1b 100644 (file)
@@ -237,6 +237,10 @@ function construct_sessions_data_for_add($formdata) {
     $duration = $sesendtime - $sesstarttime;
     $now = time();
 
+    if (empty(get_config('attendance', 'studentscanmark'))) {
+        $formdata->studentscanmark = 0;
+    }
+
     $sessions = array();
     if (isset($formdata->addmultiply)) {
         $startdate = $sessiondate;
index 66c5805..81ebf6c 100644 (file)
@@ -41,4 +41,7 @@ if ($ADMIN->fulltree) {
 
     $settings->add(new admin_setting_configselect('attendance/resultsperpage',
         get_string('resultsperpage', 'attendance'), get_string('resultsperpage_desc', 'attendance'), 25, $options));
+
+    $settings->add(new admin_setting_configcheckbox('attendance/studentscanmark',
+        get_string('studentscanmark', 'attendance'), get_string('studentscanmark_desc', 'attendance'), 1));
 }