Skip to content

Commit

Permalink
fix: phpcs issues and removed dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
keevan committed May 2, 2024
1 parent 5bc020a commit 6c44901
Show file tree
Hide file tree
Showing 57 changed files with 1,307 additions and 1,034 deletions.
170 changes: 90 additions & 80 deletions attendees.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
if (!$session = facetoface_get_session($s)) {
throw new moodle_exception('error:incorrectcoursemodulesession', 'facetoface');
}
if (!$facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface))) {
if (!$facetoface = $DB->get_record('facetoface', ['id' => $session->facetoface])) {
throw new moodle_exception('error:incorrectfacetofaceid', 'facetoface');
}
if (!$course = $DB->get_record('course', array('id' => $facetoface->course))) {
if (!$course = $DB->get_record('course', ['id' => $facetoface->course])) {
throw new moodle_exception('error:coursemisconfigured', 'facetoface');
}
if (!$cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id)) {
Expand Down Expand Up @@ -85,8 +85,8 @@
$canviewsession = $canviewattendees || $cantakeattendance || $canviewcancellations;
$canapproverequests = false;

$requests = array();
$declines = array();
$requests = [];
$declines = [];

// If a user can take attendance, they can approve staff's booking requests.
if ($cantakeattendance) {
Expand All @@ -109,7 +109,7 @@
}

if (!empty($download) && $canviewattendees) {
// Download list of attendees
// Download list of attendees.
facetoface_download_attendees(format_string($facetoface->name), $session, $attendees, $download);
exit();
}
Expand All @@ -127,15 +127,13 @@
if ($cancelform) {
redirect($return);
} else if (!empty($form->requests)) {

// Approve requests.
if ($canapproverequests && facetoface_approve_requests($form)) {

// Logging and events trigger.
$params = array(
$params = [
'context' => $contextmodule,
'objectid' => $session->id
);
'objectid' => $session->id,
];
$event = \mod_facetoface\event\approve_requests::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
Expand All @@ -145,23 +143,21 @@
redirect($return);
} else if ($takeattendance) {
if (facetoface_take_attendance($form)) {

// Logging and events trigger.
$params = array(
$params = [
'context' => $contextmodule,
'objectid' => $session->id
);
'objectid' => $session->id,
];
$event = \mod_facetoface\event\take_attendance::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();
} else {

// Logging and events trigger.
$params = array(
$params = [
'context' => $contextmodule,
'objectid' => $session->id
);
'objectid' => $session->id,
];
$event = \mod_facetoface\event\take_attendance_failed::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
Expand All @@ -176,18 +172,18 @@
*/

// Logging and events trigger.
$params = array(
$params = [
'context' => $contextmodule,
'objectid' => $session->id
);
'objectid' => $session->id,
];
$event = \mod_facetoface\event\attendees_viewed::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();

$pagetitle = format_string($facetoface->name);

$PAGE->set_url('/mod/facetoface/attendees.php', array('s' => $s));
$PAGE->set_url('/mod/facetoface/attendees.php', ['s' => $s]);
$PAGE->set_context($context);
$PAGE->set_cm($cm);

Expand Down Expand Up @@ -229,17 +225,19 @@
echo $OUTPUT->notification(get_string('nosignedupusers', 'facetoface'));
} else {
if ($takeattendance) {
$attendeesurl = new moodle_url('attendees.php', array('s' => $s, 'takeattendance' => '1'));
echo html_writer::start_tag('form', array('action' => $attendeesurl, 'method' => 'post'));
$attendeesurl = new moodle_url('attendees.php', ['s' => $s, 'takeattendance' => '1']);
echo html_writer::start_tag('form', ['action' => $attendeesurl, 'method' => 'post']);
echo html_writer::tag('p', get_string('attendanceinstructions', 'facetoface'));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 's', 'value' => $s));
echo html_writer::empty_tag('input', array('type' => 'hidden', ' name' => 'backtoallsessions',
'value' => $backtoallsessions)) . '</p>';
echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey]);
echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 's', 'value' => $s]);
echo html_writer::empty_tag('input', [
'type' => 'hidden', ' name' => 'backtoallsessions',
'value' => $backtoallsessions,
]) . '</p>';

// Prepare status options array.
$statuses = facetoface_statuses();
$statusoptions = array();
$statusoptions = [];
foreach ($statuses as $key => $value) {
if ($key <= MDL_F2F_STATUS_BOOKED) {
continue;
Expand All @@ -250,9 +248,9 @@
}

$table = new html_table();
$table->head = array(get_string('name'));
$table->align = array('left');
$table->size = array('100%');
$table->head = [get_string('name')];
$table->align = ['left'];
$table->size = ['100%'];

if ($takeattendance) {
$table->head[] = get_string('currentstatus', 'facetoface');
Expand All @@ -274,12 +272,11 @@
}

foreach ($attendees as $attendee) {
$data = array();
$attendeeurl = new moodle_url('/user/view.php', array('id' => $attendee->id, 'course' => $course->id));
$data = [];
$attendeeurl = new moodle_url('/user/view.php', ['id' => $attendee->id, 'course' => $course->id]);
$data[] = html_writer::link($attendeeurl, format_string(fullname($attendee)));

if ($takeattendance) {

// Show current status.
$data[] = get_string('status_'.facetoface_get_status($attendee->statuscode), 'facetoface');

Expand All @@ -304,32 +301,32 @@

if ($takeattendance) {
echo html_writer::start_tag('p');
echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('saveattendance', 'facetoface')));
echo '&nbsp;' . html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'cancelform',
'value' => get_string('cancel')));
echo html_writer::empty_tag('input', ['type' => 'submit', 'value' => get_string('saveattendance', 'facetoface')]);
echo '&nbsp;' . html_writer::empty_tag('input', [
'type' => 'submit', 'name' => 'cancelform',
'value' => get_string('cancel'),
]);
echo html_writer::end_tag('p') . html_writer::end_tag('form');
} else {

// Actions.
print html_writer::start_tag('p');
if ($cantakeattendance && $session->datetimeknown && facetoface_has_session_started($session, time())) {

// Take attendance.
$attendanceurl = new moodle_url('attendees.php', array('s' => $session->id, 'takeattendance' => '1',
'backtoallsessions' => $backtoallsessions));
$attendanceurl = new moodle_url('attendees.php', [
's' => $session->id, 'takeattendance' => '1',
'backtoallsessions' => $backtoallsessions,
]);
echo html_writer::link($attendanceurl, get_string('takeattendance', 'facetoface')) . ' - ';
}
}
}

if (!$takeattendance) {
if (has_capability('mod/facetoface:addattendees', $context) ||
has_capability('mod/facetoface:removeattendees', $context)) {

// Add/remove attendees.
$editattendeeslink = new moodle_url('editattendees.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions));
echo html_writer::link($editattendeeslink, get_string('addremoveattendees', 'facetoface')) . ' - ';
}
if (!$takeattendance
&& (has_capability('mod/facetoface:addattendees', $context)
|| has_capability('mod/facetoface:removeattendees', $context))) {
// Add/remove attendees.
$editattendeeslink = new moodle_url('editattendees.php', ['s' => $session->id, 'backtoallsessions' => $backtoallsessions]);
echo html_writer::link($editattendeeslink, get_string('addremoveattendees', 'facetoface')) . ' - ';
}
echo html_writer::link("attendees.php?s=$session->id&backtoallsessions=$session->facetoface&download=ods",
get_string('downloadods')) . ' - ';
Expand All @@ -338,9 +335,9 @@
}

// Go back.
$url = new moodle_url('/course/view.php', array('id' => $course->id));
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
if ($backtoallsessions) {
$url = new moodle_url('/mod/facetoface/view.php', array('f' => $facetoface->id, 'backtoallsessions' => $backtoallsessions));
$url = new moodle_url('/mod/facetoface/view.php', ['f' => $facetoface->id, 'backtoallsessions' => $backtoallsessions]);
}
echo html_writer::link($url, get_string('goback', 'facetoface')) . html_writer::end_tag('p');

Expand All @@ -349,7 +346,7 @@
* Print unapproved requests (if user able to view)
*/
if ($canapproverequests) {
echo html_writer::empty_tag('br', array('id' => 'unapproved'));
echo html_writer::empty_tag('br', ['id' => 'unapproved']);
if (!$requests) {
echo $OUTPUT->notification(get_string('noactionableunapprovedrequests', 'facetoface'));
} else {
Expand All @@ -362,38 +359,50 @@
}


$action = new moodle_url('attendees.php', array('s' => $s));
echo html_writer::start_tag('form', array('action' => $action->out(), 'method' => 'post'));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 's', 'value' => $s));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'backtoallsessions',
'value' => $backtoallsessions)) . html_writer::end_tag('p');
$action = new moodle_url('attendees.php', ['s' => $s]);
echo html_writer::start_tag('form', ['action' => $action->out(), 'method' => 'post']);
echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey]);
echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 's', 'value' => $s]);
echo html_writer::empty_tag('input', [
'type' => 'hidden', 'name' => 'backtoallsessions',
'value' => $backtoallsessions,
]) . html_writer::end_tag('p');

$table = new html_table();
$table->head = array(get_string('name'), get_string('timerequested', 'facetoface'),
get_string('decidelater', 'facetoface'), get_string('decline', 'facetoface'),
get_string('approve', 'facetoface'));
$table->align = array('left', 'center', 'center', 'center', 'center');
$table->head = [
get_string('name'), get_string('timerequested', 'facetoface'),
get_string('decidelater', 'facetoface'), get_string('decline', 'facetoface'),
get_string('approve', 'facetoface'),
];
$table->align = ['left', 'center', 'center', 'center', 'center'];

foreach ($requests as $attendee) {
$data = array();
$attendeelink = new moodle_url('/user/view.php', array('id' => $attendee->id, 'course' => $course->id));
$data = [];
$attendeelink = new moodle_url('/user/view.php', ['id' => $attendee->id, 'course' => $course->id]);
$data[] = html_writer::link($attendeelink, format_string(fullname($attendee)));
$data[] = userdate($attendee->timerequested, get_string('strftimedatetime'));
$data[] = html_writer::empty_tag('input', array('type' => 'radio', 'name' => 'requests['.$attendee->id.']',
'value' => '0', 'checked' => 'checked'));
$data[] = html_writer::empty_tag('input', array('type' => 'radio', 'name' => 'requests['.$attendee->id.']',
'value' => '1'));
$disabled = ($canbookuser) ? array() : array('disabled' => 'disabled');
$data[] = html_writer::empty_tag('input', array_merge(array('type' => 'radio', 'name' => 'requests['.$attendee->id.']',
'value' => '2'), $disabled));
$data[] = html_writer::empty_tag('input', [
'type' => 'radio', 'name' => 'requests['.$attendee->id.']',
'value' => '0', 'checked' => 'checked',
]);
$data[] = html_writer::empty_tag('input', [
'type' => 'radio', 'name' => 'requests['.$attendee->id.']',
'value' => '1',
]);
$disabled = ($canbookuser) ? [] : ['disabled' => 'disabled'];
$data[] = html_writer::empty_tag('input', array_merge([
'type' => 'radio', 'name' => 'requests['.$attendee->id.']',
'value' => '2',
], $disabled));
$table->data[] = $data;
}

echo html_writer::table($table);

echo html_writer::tag('p', html_writer::empty_tag('input', array('type' => 'submit',
'value' => get_string('updaterequests', 'facetoface'))));
echo html_writer::tag('p', html_writer::empty_tag('input', [
'type' => 'submit',
'value' => get_string('updaterequests', 'facetoface'),
]));
echo html_writer::end_tag('form');
}
}
Expand All @@ -402,19 +411,20 @@
* Print cancellations (if user able to view)
*/
if (!$takeattendance && $canviewcancellations && $cancellations) {

echo html_writer::empty_tag('br');
echo $OUTPUT->heading(get_string('cancellations', 'facetoface'));

$table = new html_table();
$table->summary = get_string('cancellationstablesummary', 'facetoface');
$table->head = array(get_string('name'), get_string('timesignedup', 'facetoface'),
get_string('timecancelled', 'facetoface'), get_string('cancelreason', 'facetoface'));
$table->align = array('left', 'center', 'center');
$table->head = [
get_string('name'), get_string('timesignedup', 'facetoface'),
get_string('timecancelled', 'facetoface'), get_string('cancelreason', 'facetoface'),
];
$table->align = ['left', 'center', 'center'];

foreach ($cancellations as $attendee) {
$data = array();
$attendeelink = new moodle_url('/user/view.php', array('id' => $attendee->id, 'course' => $course->id));
$data = [];
$attendeelink = new moodle_url('/user/view.php', ['id' => $attendee->id, 'course' => $course->id]);
$data[] = html_writer::link($attendeelink, format_string(fullname($attendee)));
$data[] = userdate($attendee->timesignedup, get_string('strftimedatetime'));
$data[] = userdate($attendee->timecancelled, get_string('strftimedatetime'));
Expand Down
Loading

0 comments on commit 6c44901

Please sign in to comment.