Browse Source

Add support for session passwords when student marking.

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

27
classes/output/mobile.php

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

4
db/mobile.php

@ -56,7 +56,9 @@ $addons = [
['invalidstatus', 'attendance'],
['preventsharederror', '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['includeremarks'] = 'Include remarks';
$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['invalidaction'] = 'You must select an action';
$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>';
$string['participant'] = 'Participant';
$string['password'] = 'Password';
$string['enterpassword'] = 'Enter 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['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>
<%/messages%>
<%/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%>
<ion-list radio-group [(ngModel)]="status">
<%#statuses%>
@ -60,7 +68,7 @@
</ion-item>
<%/statuses%>
</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 }}
</button>
<%/showstatuses%>

Loading…
Cancel
Save