Browse Source

Fix some moodle coding guideline warnings.

MOODLE_37_STABLE
Dan Marsden 5 years ago
parent
commit
e167d10716
  1. 2
      add_form.php
  2. 12
      attendance.php
  3. 4
      classes/event/session_report_viewed.php
  4. 8
      externallib.php
  5. 4
      view.php

2
add_form.php

@ -247,7 +247,7 @@ class mod_attendance_add_form extends moodleform {
if (isset($pluginconfig->includeqrcode_default)) { if (isset($pluginconfig->includeqrcode_default)) {
$mform->setDefault('includeqrcode', $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)) { if (isset($pluginconfig->includeqrcode_default)) {
$mform->setDefault('rotateqrcode', $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); $secrethash = md5($USER->id.$attforsession->rotateqrcodesecret);
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); $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])) { if (isset($_COOKIE[$cookiename])) {
// Check the token // Check the token.
if ($secrethash !== $_COOKIE[$cookiename]) { if ($secrethash !== $_COOKIE[$cookiename]) {
// Flag error // Flag error.
print_error('qr_cookie_error', 'mod_attendance', $url); print_error('qr_cookie_error', 'mod_attendance', $url);
} }
} else { } else {
// Check password // Check password.
$sql = 'SELECT * FROM {attendance_rotate_passwords}'. $sql = 'SELECT * FROM {attendance_rotate_passwords}'.
' WHERE attendanceid = ? AND expirytime > ? ORDER BY expirytime ASC LIMIT 2'; ' WHERE attendanceid = ? AND expirytime > ? ORDER BY expirytime ASC LIMIT 2';
$qrpassdatabase = $DB->get_records_sql($sql, ['attendanceid' => $id, time() - $attconfig->rotateqrcodeexpirymargin]); $qrpassdatabase = $DB->get_records_sql($sql, ['attendanceid' => $id, time() - $attconfig->rotateqrcodeexpirymargin]);
@ -66,10 +66,10 @@ if ($attforsession->rotateqrcode == 1) {
} }
if ($qrpassflag) { if ($qrpassflag) {
// Create and store the token // Create and store the token.
setcookie($cookiename, $secrethash, time() + (60 * 5), "/"); setcookie($cookiename, $secrethash, time() + (60 * 5), "/");
} else { } else {
// Flag error // Flag error.
print_error('qr_pass_wrong', 'mod_attendance', $url); 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() { protected function init() {
$this->data['crud'] = 'r'; $this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING; $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)) { if (!isset($this->relateduserid)) {
throw new \coding_exception('The event mod_attendance\\event\\session_report_viewed must specify 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. // it was stored.
// filter params are important, but stored in session so default effectively unknown, // filter params are important, but stored in session so default effectively unknown,
// hence required here. // hence required here.

8
externallib.php

@ -45,7 +45,8 @@ class mod_wsattendance_external extends external_api {
'courseid' => new external_value(PARAM_INT, 'course id'), 'courseid' => new external_value(PARAM_INT, 'course id'),
'name' => new external_value(PARAM_TEXT, 'attendance name'), 'name' => new external_value(PARAM_TEXT, 'attendance name'),
'intro' => new external_value(PARAM_RAW, 'attendance description', VALUE_DEFAULT, ''), '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 * @param bool $addcalendarevent
* @return array * @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; global $USER, $DB;
$params = self::validate_parameters(self::add_session_parameters(), array( $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.'); throw new invalid_parameter_exception('Group id is not specified (or 0) in separate groups mode.');
} }
if ($groupmode === SEPARATEGROUPS || ($groupmode === VISIBLEGROUPS && $groupid > 0)) { if ($groupmode === SEPARATEGROUPS || ($groupmode === VISIBLEGROUPS && $groupid > 0)) {
// Determine valid groups // Determine valid groups.
$userid = has_capability('moodle/site:accessallgroups', $context) ? 0 : $USER->id; $userid = has_capability('moodle/site:accessallgroups', $context) ? 0 : $USER->id;
$validgroupids = array_map(function($group) { $validgroupids = array_map(function($group) {
return $group->id; return $group->id;

4
view.php

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

Loading…
Cancel
Save