Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechecker fixes #759

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions absentee.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@
if (!empty($category)) {
$context = context_coursecat::instance($category);
$coursecat = core_course_category::get($category);
$courses = $coursecat->get_courses(array('recursive' => true, 'idonly' => true));
$courses = $coursecat->get_courses(['recursive' => true, 'idonly' => true]);
$PAGE->set_category_by_id($category);
require_login();
} else if (!empty($attendancecm)) {
$cm = get_coursemodule_from_id('attendance', $attendancecm, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
$courses = array($course->id);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$att = $DB->get_record('attendance', ['id' => $cm->instance], '*', MUST_EXIST);
$courses = [$course->id];
$context = context_module::instance($cm->id);
require_login($course, false, $cm);
} else {
admin_externalpage_setup('managemodules');
$context = context_system::instance();
$courses = array(); // Show all courses.
$courses = []; // Show all courses.
}
// Check permissions.
require_capability('mod/attendance:viewreports', $context);

$exportfilename = 'attendance-absentee.csv';

$PAGE->set_url('/mod/attendance/absentee.php', array('category' => $category, 'id' => $attendancecm));
$PAGE->set_url('/mod/attendance/absentee.php', ['category' => $category, 'id' => $attendancecm]);

$PAGE->set_heading($SITE->fullname);

Expand All @@ -80,32 +80,32 @@
}

}
$columns = array('coursename', 'aname', 'userid');
$headers = array(get_string('course'),
$columns = ['coursename', 'aname', 'userid'];
$headers = [get_string('course'),
get_string('pluginname', 'attendance'),
get_string('user'));
get_string('user'), ];

$extrafields = array();
$extrafields = [];
if (!empty($CFG->showuseridentity) && has_capability('moodle/site:viewuseridentity', $context)) {
$extrafields = explode(',', $CFG->showuseridentity);
foreach ($extrafields as $field) {
$columns[] = $field;
$headers[] = get_string($field);
}
}
$columns = array_merge($columns, array('numtakensessions', 'percent', 'timesent'));
$headers = array_merge($headers, array(
$columns = array_merge($columns, ['numtakensessions', 'percent', 'timesent']);
$headers = array_merge($headers, [
get_string('takensessions', 'attendance'),
get_string('averageattendance', 'attendance'),
get_string('triggered', 'attendance')));
get_string('triggered', 'attendance')]);

$table->define_columns($columns);
$table->define_headers($headers);

$table->sortable(true);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('class', 'generaltable generalbox');
$table->show_download_buttons_at(array(TABLE_P_BOTTOM));
$table->show_download_buttons_at([TABLE_P_BOTTOM]);
$table->setup();

// Work out direction of sort required.
Expand All @@ -130,13 +130,13 @@

$records = attendance_get_users_to_notify($courses, $orderby);
foreach ($records as $record) {
$row = array();
$row = [];
if (!$table->is_downloading($download, $exportfilename)) {
$url = new moodle_url('/mod/attendance/index.php', array('id' => $record->courseid));
$url = new moodle_url('/mod/attendance/index.php', ['id' => $record->courseid]);
$row[] = html_writer::link($url, $record->coursename);

$url = new moodle_url('/mod/attendance/view.php', array('studentid' => $record->userid,
'id' => $record->cmid, 'view' => ATT_VIEW_ALL));
$url = new moodle_url('/mod/attendance/view.php', ['studentid' => $record->userid,
'id' => $record->cmid, 'view' => ATT_VIEW_ALL]);
$row[] = html_writer::link($url, $record->aname);

$row[] = html_writer::link($url, fullname($record));
Expand Down
42 changes: 22 additions & 20 deletions attendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
$id = required_param('sessid', PARAM_INT);
$qrpass = optional_param('qrpass', '', PARAM_TEXT);

$attforsession = $DB->get_record('attendance_sessions', array('id' => $id), '*', MUST_EXIST);
$attforsession = $DB->get_record('attendance_sessions', ['id' => $id], '*', MUST_EXIST);
$attconfig = get_config('attendance');
$attendance = $DB->get_record('attendance', array('id' => $attforsession->attendanceid), '*', MUST_EXIST);
$attendance = $DB->get_record('attendance', ['id' => $attforsession->attendanceid], '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('attendance', $attendance->id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);

// Require the user is logged in.
require_login($course, true, $cm);
Expand All @@ -58,7 +58,7 @@
if ($canmark && attendance_session_open_for_students($attforsession) && $attforsession->rotateqrcode == 1) {
$cookiename = 'attendance_'.$attforsession->id;
$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', ['id' => $cm->id]);

// Check if cookie is set and verify.
if (isset($_COOKIE[$cookiename])) {
Expand Down Expand Up @@ -103,13 +103,13 @@


if (!$canmark) {
redirect(new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)), get_string($reason, 'attendance'));
redirect(new moodle_url('/mod/attendance/view.php', ['id' => $cm->id]), get_string($reason, 'attendance'));
exit;
}

// Check if subnet is set and if the user is in the allowed range.
if (!empty($attforsession->subnet) && !address_in_subnet(getremoteaddr(), $attforsession->subnet)) {
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
$url = new moodle_url('/mod/attendance/view.php', ['id' => $cm->id]);
notice(get_string('subnetwrong', 'attendance'), $url);
exit; // Notice calls this anyway.
}
Expand All @@ -122,9 +122,10 @@
}

// Check to see if autoassignstatus is in use and no password required or Qrpass given and passed.
if ($attforsession->autoassignstatus && attendance_session_open_for_students($attforsession) && (empty($attforsession->studentpassword)) || $qrpassflag) {
if ($attforsession->autoassignstatus && attendance_session_open_for_students($attforsession) &&
(empty($attforsession->studentpassword)) || $qrpassflag) {
$statusid = attendance_session_get_highest_status($att, $attforsession);
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
$url = new moodle_url('/mod/attendance/view.php', ['id' => $cm->id]);
if (empty($statusid)) {
throw new moodle_exception('attendance_no_status', 'mod_attendance', $url);
}
Expand All @@ -148,7 +149,7 @@
if (!empty($attforsession->studentpassword) &&
$attforsession->studentpassword !== $qrpass) {

$url = new moodle_url('/mod/attendance/attendance.php', array('sessid' => $id, 'sesskey' => sesskey()));
$url = new moodle_url('/mod/attendance/attendance.php', ['sessid' => $id, 'sesskey' => sesskey()]);
redirect($url, get_string('incorrectpassword', 'mod_attendance'), null, \core\output\notification::NOTIFY_ERROR);
}

Expand All @@ -158,14 +159,14 @@

$fromform->status = attendance_session_get_highest_status($att, $attforsession);
if (empty($fromform->status)) {
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
$url = new moodle_url('/mod/attendance/view.php', ['id' => $cm->id]);
throw new moodle_exception('attendance_no_status', 'mod_attendance', $url);
}

if (!empty($fromform->status)) {
$success = $att->take_from_student($fromform);

$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
$url = new moodle_url('/mod/attendance/view.php', ['id' => $cm->id]);
if ($success) {
// Redirect back to the view page.
redirect($url, get_string('studentmarked', 'attendance'));
Expand All @@ -180,33 +181,34 @@
// Create the form.
if ($attforsession->rotateqrcode == 1) {
$mform = new mod_attendance\form\studentattendance(null,
array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession,
'attendance' => $att, 'password' => $attforsession->studentpassword));
['course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession,
'attendance' => $att, 'password' => $attforsession->studentpassword]);
} else {
$mform = new mod_attendance\form\studentattendance(null,
array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession,
'attendance' => $att, 'password' => $qrpass));
['course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession,
'attendance' => $att, 'password' => $qrpass]);
}

if ($mform->is_cancelled()) {
// The user cancelled the form, so redirect them to the view page.
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
$url = new moodle_url('/mod/attendance/view.php', ['id' => $cm->id]);
redirect($url);
} else if ($fromform = $mform->get_data()) {
// Check if password required and if set correctly.
if (!empty($attforsession->studentpassword) &&
// Session is not currently open, but this status is allowed to be set before the session, don't require password.
!(!attendance_session_open_for_students($attforsession) && attendance_is_status_availablebeforesession($attforsession->id, $fromform->status))
!(!attendance_session_open_for_students($attforsession) &&
attendance_is_status_availablebeforesession($attforsession->id, $fromform->status))
// Check if password being passed is valid.
&& $attforsession->studentpassword !== $fromform->studentpassword) {

$url = new moodle_url('/mod/attendance/attendance.php', array('sessid' => $id, 'sesskey' => sesskey()));
$url = new moodle_url('/mod/attendance/attendance.php', ['sessid' => $id, 'sesskey' => sesskey()]);
redirect($url, get_string('incorrectpassword', 'mod_attendance'), null, \core\output\notification::NOTIFY_ERROR);
}
if (attendance_session_open_for_students($attforsession) && $attforsession->autoassignstatus) {
$fromform->status = attendance_session_get_highest_status($att, $attforsession);
if (empty($fromform->status)) {
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
$url = new moodle_url('/mod/attendance/view.php', ['id' => $cm->id]);
throw new moodle_exception('attendance_no_status', 'mod_attendance', $url);
}
}
Expand All @@ -218,7 +220,7 @@
}
$success = $att->take_from_student($fromform);

$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id));
$url = new moodle_url('/mod/attendance/view.php', ['id' => $cm->id]);
if ($success) {
// Redirect back to the view page.
redirect($url, get_string('studentmarked', 'attendance'));
Expand Down
7 changes: 4 additions & 3 deletions automark.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
$grouptype = required_param('grouptype', PARAM_INT);

$cm = get_coursemodule_from_id('attendance', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$att = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
$session = $DB->get_record('attendance_sessions', array('id' => $sessionid, 'attendanceid' => $att->id),
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$att = $DB->get_record('attendance', ['id' => $cm->instance], '*', MUST_EXIST);
$session = $DB->get_record('attendance_sessions', ['id' => $sessionid, 'attendanceid' => $att->id],
'*', MUST_EXIST);

require_login($course, true, $cm);
Expand All @@ -45,6 +45,7 @@
if ($session->automark == ATTENDANCE_AUTOMARK_CLOSE && ($session->sessdate + $session->duration) > time() ) {
throw new moodle_exception('automarkingnotavailableyet', 'attendance');
}
// phpcs:disable moodle.Commenting.TodoComment
// TODO Check Get session unmarked value for statusset used by this session.
$errors = \mod_attendance\local\automark::session($session, $course, $cm, $att, true);
$url = new moodle_url('/mod/attendance/take.php', ['id' => $id, 'sessionid' => $session->id, 'grouptype' => $grouptype]);
Expand Down
31 changes: 16 additions & 15 deletions backup/moodle2/backup_attendance_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,34 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// XML nodes declaration - non-user data.
$attendance = new backup_nested_element('attendance', array('id'), array(
'name', 'intro', 'introformat', 'grade', 'showextrauserdetails', 'showsessiondetails', 'sessiondetailspos', 'subnet'));
$attendance = new backup_nested_element('attendance', ['id'], [
'name', 'intro', 'introformat', 'grade', 'showextrauserdetails', 'showsessiondetails', 'sessiondetailspos', 'subnet']);

$statuses = new backup_nested_element('statuses');
$status = new backup_nested_element('status', array('id'), array(
'acronym', 'description', 'grade', 'studentavailability', 'availablebeforesession', 'setunmarked', 'visible', 'deleted', 'setnumber'));
$status = new backup_nested_element('status', ['id'], [
'acronym', 'description', 'grade', 'studentavailability', 'availablebeforesession', 'setunmarked', 'visible', 'deleted',
'setnumber']);

$warnings = new backup_nested_element('warnings');
$warning = new backup_nested_element('warning', array('id'), array('warningpercent', 'warnafter',
'maxwarn', 'emailuser', 'emailsubject', 'emailcontent', 'emailcontentformat', 'thirdpartyemails'));
$warning = new backup_nested_element('warning', ['id'], ['warningpercent', 'warnafter',
'maxwarn', 'emailuser', 'emailsubject', 'emailcontent', 'emailcontentformat', 'thirdpartyemails']);

$sessions = new backup_nested_element('sessions');
$session = new backup_nested_element('session', array('id'), array(
$session = new backup_nested_element('session', ['id'], [
'groupid', 'sessdate', 'duration', 'lasttaken', 'lasttakenby', 'timemodified',
'description', 'descriptionformat', 'studentscanmark', 'allowupdatestatus', 'studentpassword', 'autoassignstatus',
'subnet', 'automark', 'automarkcompleted', 'statusset', 'absenteereport', 'preventsharedip',
'preventsharediptime', 'caleventid', 'calendarevent', 'includeqrcode', 'automarkcmid',
'studentsearlyopentime'));
'studentsearlyopentime']);

$customfields = new backup_nested_element('customfields');
$customfield = new backup_nested_element('customfield', ['id'], [
'sessionid', 'shortname', 'type', 'value', 'valueformat']);

// XML nodes declaration - user data.
$logs = new backup_nested_element('logs');
$log = new backup_nested_element('log', array('id'), array(
'sessionid', 'studentid', 'statusid', 'statusset', 'timetaken', 'takenby', 'remarks'));
$log = new backup_nested_element('log', ['id'], [
'sessionid', 'studentid', 'statusid', 'statusset', 'timetaken', 'takenby', 'remarks']);

// Build the tree in the order needed for restore.
$attendance->add_child($statuses);
Expand All @@ -87,22 +88,22 @@ protected function define_structure() {

// Data sources - non-user data.

$attendance->set_source_table('attendance', array('id' => backup::VAR_ACTIVITYID));
$attendance->set_source_table('attendance', ['id' => backup::VAR_ACTIVITYID]);

$status->set_source_table('attendance_statuses', array('attendanceid' => backup::VAR_PARENTID));
$status->set_source_table('attendance_statuses', ['attendanceid' => backup::VAR_PARENTID]);

$warning->set_source_table('attendance_warning',
array('idnumber' => backup::VAR_PARENTID));
['idnumber' => backup::VAR_PARENTID]);

$session->set_source_table('attendance_sessions', array('attendanceid' => backup::VAR_PARENTID));
$session->set_source_table('attendance_sessions', ['attendanceid' => backup::VAR_PARENTID]);

$handler = mod_attendance\customfield\session_handler::create();
$fieldsforbackup = $handler->get_instance_data_for_backup_by_activity($this->task->get_activityid());
$customfield->set_source_array($fieldsforbackup);

// Data sources - user related data.
if ($userinfo) {
$log->set_source_table('attendance_log', array('sessionid' => backup::VAR_PARENTID));
$log->set_source_table('attendance_log', ['sessionid' => backup::VAR_PARENTID]);
}

// Id annotations.
Expand Down
17 changes: 9 additions & 8 deletions backup/moodle2/restore_attendance_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ protected function define_my_steps() {
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents = [];

$contents[] = new restore_decode_content('attendance', array('intro'), 'attendance');
$contents[] = new restore_decode_content('attendance', ['intro'], 'attendance');
$contents[] = new restore_decode_content('attendance_sessions',
array('description'), 'attendance_session');
['description'], 'attendance_session');

return $contents;
}
Expand All @@ -66,18 +66,18 @@ public static function define_decode_contents() {
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules = [];

$rules[] = new restore_decode_rule('ATTENDANCEVIEWBYID',
'/mod/attendance/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('ATTENDANCEVIEWBYIDSTUD',
'/mod/attendance/view.php?id=$1&studentid=$2', array('course_module', 'user'));
'/mod/attendance/view.php?id=$1&studentid=$2', ['course_module', 'user']);

// Older style backups using previous plugin name.
$rules[] = new restore_decode_rule('ATTFORBLOCKVIEWBYID',
'/mod/attendance/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('ATTFORBLOCKVIEWBYIDSTUD',
'/mod/attendance/view.php?id=$1&studentid=$2', array('course_module', 'user'));
'/mod/attendance/view.php?id=$1&studentid=$2', ['course_module', 'user']);

return $rules;

Expand All @@ -90,8 +90,9 @@ public static function define_decode_rules() {
* of {@see restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules = [];

// phpcs:disable moodle.Commenting.TodoComment
// TODO: log restore.
return $rules;
}
Expand All @@ -107,7 +108,7 @@ public static function define_restore_log_rules() {
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules = [];

return $rules;
}
Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/restore_attendance_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class restore_attendance_activity_structure_step extends restore_activity_struct
*/
protected function define_structure() {

$paths = array();
$paths = [];

$userinfo = $this->get_setting_value('userinfo'); // Are we including userinfo?

Expand Down
2 changes: 1 addition & 1 deletion classes/analytics/indicator/activity_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ abstract class activity_base extends \core_analytics\local\indicator\community_o
* @return string[]
*/
protected function feedback_viewed_events() {
return array('\mod_attendance\event\session_report_viewed');
return ['\mod_attendance\event\session_report_viewed'];
}
}
Loading
Loading