Browse Source

Fix some moodle coding guideline warnings.

nwp90-nwp90-allsessionsreport
Dan Marsden 5 years ago
parent
commit
2a9976ccca
  1. 2
      add_form.php
  2. 12
      attendance.php
  3. 4
      classes/event/session_report_viewed.php
  4. 8
      externallib.php
  5. 16
      locallib.php
  6. 3
      renderer.php
  7. 4
      view.php

2
add_form.php

@ -247,7 +247,7 @@ class mod_attendance_add_form extends moodleform {
if (isset($pluginconfig->includeqrcode_default)) {
$mform->setDefault('includeqrcode', $pluginconfig->includeqrcode_default);
}
// TODO - Change in DB and provide value
// TODO - Change in DB and provide value.
if (isset($pluginconfig->includeqrcode_default)) {
$mform->setDefault('rotateqrcode', $pluginconfig->includeqrcode_default);
}

12
attendance.php

@ -44,15 +44,15 @@ if ($attforsession->rotateqrcode == 1) {
$secrethash = md5($USER->id.$attforsession->rotateqrcodesecret);
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
// Check if cookie is set and verify
// Check if cookie is set and verify.
if (isset($_COOKIE[$cookiename])) {
// Check the token
// Check the token.
if ($secrethash !== $_COOKIE[$cookiename]) {
// Flag error
// Flag error.
print_error('qr_cookie_error', 'mod_attendance', $url);
}
} else {
// Check password
// Check password.
$sql = 'SELECT * FROM {attendance_rotate_passwords}'.
' WHERE attendanceid = ? AND expirytime > ? ORDER BY expirytime ASC LIMIT 2';
$qrpassdatabase = $DB->get_records_sql($sql, ['attendanceid' => $id, time() - $attconfig->rotateqrcodeexpirymargin]);
@ -66,10 +66,10 @@ if ($attforsession->rotateqrcode == 1) {
}
if ($qrpassflag) {
// Create and store the token
// Create and store the token.
setcookie($cookiename, $secrethash, time() + (60 * 5), "/");
} else {
// Flag error
// Flag error.
print_error('qr_pass_wrong', 'mod_attendance', $url);
}
}

4
classes/event/session_report_viewed.php

@ -46,7 +46,7 @@ class session_report_viewed extends \core\event\base {
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
// objecttable and objectid can't be meaningfully specified
// Objecttable and objectid can't be meaningfully specified.
}
/**
@ -121,7 +121,7 @@ class session_report_viewed extends \core\event\base {
if (!isset($this->relateduserid)) {
throw new \coding_exception('The event mod_attendance\\event\\session_report_viewed must specify relateduserid.');
}
// view params can be left out as defaults will be the same when log event is viewed as when
// View params can be left out as defaults will be the same when log event is viewed as when
// it was stored.
// filter params are important, but stored in session so default effectively unknown,
// hence required here.

8
externallib.php

@ -45,7 +45,8 @@ class mod_attendance_external extends external_api {
'courseid' => new external_value(PARAM_INT, 'course id'),
'name' => new external_value(PARAM_TEXT, 'attendance name'),
'intro' => new external_value(PARAM_RAW, 'attendance description', VALUE_DEFAULT, ''),
'groupmode' => new external_value(PARAM_INT, 'group mode (0 - no groups, 1 - separate groups, 2 - visible groups)', VALUE_DEFAULT, 0),
'groupmode' => new external_value(PARAM_INT,
'group mode (0 - no groups, 1 - separate groups, 2 - visible groups)', VALUE_DEFAULT, 0),
)
);
}
@ -188,7 +189,8 @@ class mod_attendance_external extends external_api {
* @param bool $addcalendarevent
* @return array
*/
public static function add_session(int $attendanceid, $description, int $sessiontime, int $duration, int $groupid, bool $addcalendarevent) {
public static function add_session(int $attendanceid, $description, int $sessiontime, int $duration, int $groupid,
bool $addcalendarevent) {
global $USER, $DB;
$params = self::validate_parameters(self::add_session_parameters(), array(
@ -218,7 +220,7 @@ class mod_attendance_external extends external_api {
throw new invalid_parameter_exception('Group id is not specified (or 0) in separate groups mode.');
}
if ($groupmode === SEPARATEGROUPS || ($groupmode === VISIBLEGROUPS && $groupid > 0)) {
// Determine valid groups
// Determine valid groups.
$userid = has_capability('moodle/site:accessallgroups', $context) ? 0 : $USER->id;
$validgroupids = array_map(function($group) {
return $group->id;

16
locallib.php

@ -1104,7 +1104,8 @@ function attendance_renderqrcode($session) {
global $CFG;
if (strlen($session->studentpassword) > 0) {
$qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?qrpass=' . $session->studentpassword . '&sessid=' . $session->id;
$qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?qrpass=' .
$session->studentpassword . '&sessid=' . $session->id;
} else {
$qrcodeurl = $CFG->wwwroot . '/mod/attendance/attendance.php?sessid=' . $session->id;
}
@ -1127,7 +1128,8 @@ function attendance_generate_passwords($session) {
$password = array();
for ($i = 0; $i < 30; $i++) {
array_push($password, array("attendanceid" => $session->id, "password" => mt_rand(1000, 10000), "expirytime" => time() + ($attconfig->rotateqrcodeinterval * $i)));
array_push($password, array("attendanceid" => $session->id,
"password" => mt_rand(1000, 10000), "expirytime" => time() + ($attconfig->rotateqrcodeinterval * $i)));
}
$DB->insert_records('attendance_rotate_passwords', $password);
@ -1139,7 +1141,7 @@ function attendance_generate_passwords($session) {
* @param stdClass $session
*/
function attendance_renderqrcoderotate($session) {
// load requered js
// Load required js.
echo html_writer::tag('script', '',
[
'src' => 'js/qrcode/qrcode.min.js',
@ -1152,12 +1154,12 @@ function attendance_renderqrcoderotate($session) {
'type' => 'text/javascript'
]
);
echo html_writer::tag('div', '', ['id' => 'rotate-time']); // div to display timer
echo html_writer::tag('div', '', ['id' => 'rotate-time']); // Div to display timer.
echo html_writer::tag('h3', get_string('passwordgrp', 'attendance'));
echo html_writer::tag('div', '', ['id' => 'text-password']); // div to display password
echo html_writer::tag('div', '', ['id' => 'text-password']); // Div to display password.
echo html_writer::tag('h3', get_string('qrcode', 'attendance'));
echo html_writer::tag('div', '', ['id' => 'qrcode']); // div to display qr code
// js to start the password manager
echo html_writer::tag('div', '', ['id' => 'qrcode']); // Div to display qr code.
// Js to start the password manager.
echo '
<script type="text/javascript">
let qrCodeRotate = new attendance_QRCodeRotate();

3
renderer.php

@ -1176,7 +1176,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
$output .= html_writer::empty_tag('input', array('type' => 'submit',
'value' => get_string('submit'),
'class' => 'btn btn-secondary'));
$cell = new html_table_cell(html_writer::tag('form', $output, array('action' => $url->out(), 'method' => 'get')));
$cell = new html_table_cell(html_writer::tag('form', $output,
array('action' => $url->out(), 'method' => 'get')));
} else {
// Student can mark their own attendance.
// URL to the page that lets the student modify their attendance.

4
view.php

@ -79,8 +79,6 @@ if (isset($pageparams->studentid) && $USER->id != $pageparams->studentid) {
$userdata = new attendance_user_data($att, $userid);
// Trigger viewed event
// Create url for link in log screen.
$filterparams = array(
'view' => $userdata->pageparams->view,
@ -94,6 +92,8 @@ if (empty($userdata->pageparams->studentid)) {
} else {
$relateduserid = $userdata->pageparams->studentid;
}
// Trigger viewed event.
$event = \mod_attendance\event\session_report_viewed::create(array(
'relateduserid' => $relateduserid,
'context' => $context,

Loading…
Cancel
Save