Browse Source

Add support for session passwords when student marking.

MOODLE_36_STABLE
Dan Marsden 6 years ago
parent
commit
8bf807887e
  1. 73
      classes/output/mobile.php
  2. 4
      db/mobile.php
  3. 2
      lang/en/attendance.php
  4. 10
      templates/mobile_user_form.mustache

73
classes/output/mobile.php

@ -47,8 +47,8 @@ class mobile {
$cmid = $args->cmid; $cmid = $args->cmid;
$courseid = $args->courseid; $courseid = $args->courseid;
$takenstatus = empty($args->status) ? '' : $args->status; $takenstatus = empty($args->status) ? '' : $args->status;
$sessid = $args->sessid; $sessid = empty($args->sessid) ? '' : $args->sessid;
$groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. $password = empty($args->studentpass) ? '' : $args->studentpass;
// Capabilities check. // Capabilities check.
$cm = get_coursemodule_from_id('attendance', $cmid); $cm = get_coursemodule_from_id('attendance', $cmid);
@ -123,11 +123,13 @@ class mobile {
if (!$isteacher) { if (!$isteacher) {
if (!empty($sess->subnet) && !address_in_subnet(getremoteaddr(), $sess->subnet)) { if (!empty($sess->subnet) && !address_in_subnet(getremoteaddr(), $sess->subnet)) {
$data['showmessage'] = true;
$data['messages'][]['string'] = 'subnetwrong'; // Lang string to show as a message. $data['messages'][]['string'] = 'subnetwrong'; // Lang string to show as a message.
$html['sessid'] = null; // Unset sessid as we cannot record session on this ip. $html['sessid'] = null; // Unset sessid as we cannot record session on this ip.
} else if ($sess->autoassignstatus && empty($sess->studentpassword)) { } else if ($sess->autoassignstatus && empty($sess->studentpassword)) {
$statusid = attendance_session_get_highest_status($att, $sess); $statusid = attendance_session_get_highest_status($att, $sess);
if (empty($statusid)) { if (empty($statusid)) {
$data['showmessage'] = true;
$data['messages'][]['string'] = 'attendance_no_status'; $data['messages'][]['string'] = 'attendance_no_status';
} }
$take = new \stdClass(); $take = new \stdClass();
@ -139,32 +141,44 @@ class mobile {
$html['currentstatus'] = $userdata->statuses[$statusid]->description; $html['currentstatus'] = $userdata->statuses[$statusid]->description;
$html['sessid'] = null; // Unset sessid as we have recorded session. $html['sessid'] = null; // Unset sessid as we have recorded session.
} }
} else if (!empty($takenstatus)) { } else if ($sess->id == $sessid) {
$statuses = $att->get_statuses(); if (!empty($sess->studentpassword) && $password != $sess->studentpassword) {
// Check if user has access to all statuses. // Password incorrect.
foreach ($statuses as $status) { $data['showmessage'] = true;
if ($status->studentavailability === '0') { $data['messages'][]['string'] = 'incorrectpasswordshort';
unset($statuses[$status->id]); } else {
continue; $statuses = $att->get_statuses();
// Check if user has access to all statuses.
foreach ($statuses as $status) {
if ($status->studentavailability === '0') {
unset($statuses[$status->id]);
continue;
}
if (!empty($status->studentavailability) &&
time() > $sess->sessdate + ($status->studentavailability * 60)) {
unset($statuses[$status->id]);
continue;
}
} }
if (!empty($status->studentavailability) && if ($sess->autoassignstatus) {
time() > $sess->sessdate + ($status->studentavailability * 60)) { // If this is an auto-assign, get the highest status available.
unset($statuses[$status->id]); $takenstatus = attendance_session_get_highest_status($att, $sess);
continue;
} }
}
if (empty($statuses[$takenstatus])) { if (empty($statuses[$takenstatus])) {
// This status has probably expired and is not available - they need to choose a new one. // This status has probably expired and is not available - they need to choose a new one.
$data['messages'][]['string'] = 'invalidstatus'; $data['showmessage'] = true;
} else { $data['messages'][]['string'] = 'invalidstatus';
$take = new \stdClass(); } else {
$take->status = $takenstatus; $take = new \stdClass();
$take->sessid = $sess->id; $take->status = $takenstatus;
$success = $att->take_from_student($take); $take->sessid = $sess->id;
$success = $att->take_from_student($take);
if ($success) {
$html['currentstatus'] = $userdata->statuses[$takenstatus]->description; if ($success) {
$html['sessid'] = null; // Unset sessid as we have recorded session. $html['currentstatus'] = $userdata->statuses[$takenstatus]->description;
$html['sessid'] = null; // Unset sessid as we have recorded session.
}
} }
} }
} }
@ -231,6 +245,7 @@ class mobile {
$data['messages'] = array(); $data['messages'] = array();
$data['showmessage'] = false; $data['showmessage'] = false;
$data['showstatuses'] = true; $data['showstatuses'] = true;
$data['showpassword'] = false;
$data['statuses'] = array(); $data['statuses'] = array();
$data['disabledduetotime'] = false; $data['disabledduetotime'] = false;
@ -266,6 +281,12 @@ class mobile {
if (empty($data['statuses'])) { if (empty($data['statuses'])) {
$data['messages'][]['string'] = 'attendance_no_status'; $data['messages'][]['string'] = 'attendance_no_status';
$data['showstatuses'] = false; // Hide all statuses. $data['showstatuses'] = false; // Hide all statuses.
} else if (!empty($attforsession->studentpassword)) {
$data['showpassword'] = true;
if ($attforsession->autoassignstatus) {
// If this is an auto status - don't show the statuses, but show the form.
$data['statuses'] = array();
}
} }
} }
if (!empty($data['messages'])) { if (!empty($data['messages'])) {

4
db/mobile.php

@ -56,7 +56,9 @@ $addons = [
['invalidstatus', 'attendance'], ['invalidstatus', 'attendance'],
['preventsharederror', 'attendance'], ['preventsharederror', 'attendance'],
['closed', 'attendance'], ['closed', 'attendance'],
['subnetwrong', 'attendance'] ['subnetwrong', 'attendance'],
['enterpassword', 'attendance'],
['incorrectpasswordshort', 'attendance']
] ]
] ]
]; ];

2
lang/en/attendance.php

@ -243,6 +243,7 @@ $string['includenottaken'] = 'Include not taken sessions';
$string['includeqrcode'] = 'Include QR code'; $string['includeqrcode'] = 'Include QR code';
$string['includeremarks'] = 'Include remarks'; $string['includeremarks'] = 'Include remarks';
$string['incorrectpassword'] = 'You have entered an incorrect password and your attendance has not been recorded, please enter the correct password.'; $string['incorrectpassword'] = 'You have entered an incorrect password and your attendance has not been recorded, please enter the correct password.';
$string['incorrectpasswordshort'] = 'Incorrect password, attendance not recorded.';
$string['indetail'] = 'In detail...'; $string['indetail'] = 'In detail...';
$string['invalidaction'] = 'You must select an action'; $string['invalidaction'] = 'You must select an action';
$string['invalidemails'] = 'You must specify addresses of existing user accounts, could not find: {$a}'; $string['invalidemails'] = 'You must specify addresses of existing user accounts, could not find: {$a}';
@ -324,6 +325,7 @@ $string['oversessionstaken_help'] = 'Shows statistics for sessions where attenda
</ul>'; </ul>';
$string['participant'] = 'Participant'; $string['participant'] = 'Participant';
$string['password'] = 'Password'; $string['password'] = 'Password';
$string['enterpassword'] = 'Enter password';
$string['passwordgrp'] = 'Student password'; $string['passwordgrp'] = 'Student password';
$string['passwordgrp_help'] = 'If set students will be required to enter this password before they can set their own attendance status for the session. If empty, no password is required.'; $string['passwordgrp_help'] = 'If set students will be required to enter this password before they can set their own attendance status for the session. If empty, no password is required.';
$string['passwordrequired'] = 'You must enter the session password before you can submit your attendance'; $string['passwordrequired'] = 'You must enter the session password before you can submit your attendance';

10
templates/mobile_user_form.mustache

@ -51,6 +51,14 @@
</ion-item> </ion-item>
<%/messages%> <%/messages%>
<%/showmessage%> <%/showmessage%>
<%#showpassword%>
<ion-list [(ngModel)]="studentpass">
<ion-item>
<ion-label>{{ 'plugin.mod_attendance.enterpassword' | translate }}:</ion-label>
<ion-input type="text" name="studentpass"></ion-input>
</ion-item>
</ion-list>
<%/showpassword%>
<%#showstatuses%> <%#showstatuses%>
<ion-list radio-group [(ngModel)]="status"> <ion-list radio-group [(ngModel)]="status">
<%#statuses%> <%#statuses%>
@ -60,7 +68,7 @@
</ion-item> </ion-item>
<%/statuses%> <%/statuses%>
</ion-list> </ion-list>
<button ion-button core-site-plugins-new-content component="mod_attendance" method="mobile_view_activity" [args]="{cmid: <% cmid %>, courseid: <% courseid %>, sessid: <% sessid %>, status: status}"> <button ion-button core-site-plugins-new-content component="mod_attendance" method="mobile_view_activity" [args]="{cmid: <% cmid %>, courseid: <% courseid %>, sessid: <% sessid %>, status: status, studentpass: studentpass}">
{{ 'plugin.mod_attendance.submitattendance' | translate }} {{ 'plugin.mod_attendance.submitattendance' | translate }}
</button> </button>
<%/showstatuses%> <%/showstatuses%>

Loading…
Cancel
Save