From e167d10716c674b3b193a7d2d1b8c33c5871a80d Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 19 Sep 2019 11:02:12 +1200 Subject: [PATCH] Fix some moodle coding guideline warnings. --- add_form.php | 2 +- attendance.php | 12 ++++++------ classes/event/session_report_viewed.php | 4 ++-- externallib.php | 8 +++++--- view.php | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/add_form.php b/add_form.php index cf27bf3..0419e97 100644 --- a/add_form.php +++ b/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); } diff --git a/attendance.php b/attendance.php index 068b6f4..153e971 100644 --- a/attendance.php +++ b/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); } } diff --git a/classes/event/session_report_viewed.php b/classes/event/session_report_viewed.php index 36e26a2..ba3cf0a 100644 --- a/classes/event/session_report_viewed.php +++ b/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. diff --git a/externallib.php b/externallib.php index 1877ae2..5a9436d 100644 --- a/externallib.php +++ b/externallib.php @@ -45,7 +45,8 @@ class mod_wsattendance_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_wsattendance_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_wsattendance_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; diff --git a/view.php b/view.php index 5ac3294..dc5da51 100644 --- a/view.php +++ b/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,