diff --git a/attendees.php b/attendees.php index 44c0bb7..2401419 100644 --- a/attendees.php +++ b/attendees.php @@ -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)) { @@ -59,7 +59,6 @@ // Load cancellations. $cancellations = facetoface_get_cancellations($session->id); - /* * Capability checks to see if the current user can view this page * @@ -85,8 +84,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) { @@ -109,7 +108,7 @@ } if (!empty($download) && $canviewattendees) { - // Download list of attendees + // Download list of attendees. facetoface_download_attendees(format_string($facetoface->name), $session, $attendees, $download); exit(); } @@ -127,15 +126,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); @@ -145,23 +142,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); @@ -176,10 +171,10 @@ */ // 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); @@ -187,7 +182,7 @@ $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); @@ -229,17 +224,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)) . '

'; + 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, + ]) . '

'; // Prepare status options array. $statuses = facetoface_statuses(); - $statusoptions = array(); + $statusoptions = []; foreach ($statuses as $key => $value) { if ($key <= MDL_F2F_STATUS_BOOKED) { continue; @@ -250,9 +247,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'); @@ -274,12 +271,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'); @@ -304,32 +300,32 @@ if ($takeattendance) { echo html_writer::start_tag('p'); - echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('saveattendance', 'facetoface'))); - echo ' ' . 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 ' ' . 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')) . ' - '; @@ -338,18 +334,17 @@ } // 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'); - /* * 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 { @@ -361,39 +356,50 @@ echo html_writer::tag('p', get_string('cannotapproveatcapacity', 'facetoface')); } - - $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'); } } @@ -402,19 +408,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')); diff --git a/backup/moodle1/lib.php b/backup/moodle1/lib.php index 27a547b..c334b7c 100644 --- a/backup/moodle1/lib.php +++ b/backup/moodle1/lib.php @@ -28,8 +28,6 @@ * @author Francois Marier */ -defined('MOODLE_INTERNAL') || die(); - /** * Glossary conversion handler */ @@ -55,24 +53,20 @@ class moodle1_mod_facetoface_handler extends moodle1_mod_handler { * @return array of {@link convert_path} instances */ public function get_paths() { - return array( + return [ new convert_path( 'facetoface', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE', - array( - 'renamefields' => array( - 'description' => 'intro', - ), - 'newfields' => array( - 'introformat' => FORMAT_MOODLE, - ), - ) + [ + 'renamefields' => ['description' => 'intro'], + 'newfields' => ['introformat' => FORMAT_MOODLE], + ] ), new convert_path('facetoface_sessions', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE/SESSIONS'), new convert_path('facetoface_session', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE/SESSIONS/SESSION'), new convert_path('facetoface_sessions_dates', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE/SESSIONS/SESSION/DATES'), new convert_path('facetoface_sessions_date', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FACETOFACE/SESSIONS/SESSION/DATES/DATE'), - ); + ]; } /** @@ -104,9 +98,11 @@ public function process_facetoface($data) { // Start writing facetoface.xml. $this->open_xml_writer("activities/facetoface_{$this->moduleid}/facetoface.xml"); - $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, - 'modulename' => 'facetoface', 'contextid' => $contextid)); - $this->xmlwriter->begin_tag('facetoface', array('id' => $instanceid)); + $this->xmlwriter->begin_tag('activity', [ + 'id' => $instanceid, 'moduleid' => $this->moduleid, + 'modulename' => 'facetoface', 'contextid' => $contextid, + ]); + $this->xmlwriter->begin_tag('facetoface', ['id' => $instanceid]); unset($data['id']); foreach ($data as $field => $value) { @@ -128,7 +124,7 @@ public function on_facetoface_sessions_start() { * data available */ public function process_facetoface_session($data) { - $this->write_xml('session', $data, array('/session/id')); + $this->write_xml('session', $data, ['/session/id']); } @@ -148,7 +144,7 @@ public function on_facetoface_sessions_dates_start() { } public function process_facetoface_sessions_date($data) { - $this->write_xml('sessions_date', $data, array('/date/id')); + $this->write_xml('sessions_date', $data, ['/date/id']); } public function on_facetoface_sessions_dates_end() { @@ -170,7 +166,7 @@ public function on_facetoface_end() { $this->xmlwriter->begin_tag('inforef'); $this->xmlwriter->begin_tag('fileref'); foreach ($this->fileman->get_fileids() as $fileid) { - $this->write_xml('file', array('id' => $fileid)); + $this->write_xml('file', ['id' => $fileid]); } $this->xmlwriter->end_tag('fileref'); $this->xmlwriter->end_tag('inforef'); diff --git a/backup/moodle2/backup_facetoface_stepslib.php b/backup/moodle2/backup_facetoface_stepslib.php index c1cb062..4d51713 100644 --- a/backup/moodle2/backup_facetoface_stepslib.php +++ b/backup/moodle2/backup_facetoface_stepslib.php @@ -28,8 +28,6 @@ * @author Francois Marier */ -defined('MOODLE_INTERNAL') || die(); - class backup_facetoface_activity_structure_step extends backup_activity_structure_step { protected function define_structure() { @@ -38,45 +36,52 @@ protected function define_structure() { $userinfo = $this->get_setting_value('userinfo'); // Define each element separated. - $facetoface = new backup_nested_element('facetoface', array('id'), array( + $facetoface = new backup_nested_element('facetoface', ['id'], [ 'name', 'intro', 'introformat', 'thirdparty', 'thirdpartywaitlist', 'display', 'timecreated', 'timemodified', 'shortname', 'showoncalendar', 'usercalentry', 'confirmationsubject', 'confirmationinstrmngr', 'confirmationmessage', 'waitlistedsubject', 'waitlistedmessage', 'cancellationsubject', 'cancellationinstrmngr', 'cancellationmessage', 'remindersubject', 'reminderinstrmngr', 'remindermessage', 'reminderperiod', 'requestsubject', 'requestinstrmngr', 'requestmessage', - 'approvalreqd', 'allowcancellationsdefault', 'signuptype', 'multiplesignupmethod', 'completionattendance')); + 'approvalreqd', 'allowcancellationsdefault', 'signuptype', 'multiplesignupmethod', 'completionattendance', + ]); $sessions = new backup_nested_element('sessions'); - $session = new backup_nested_element('session', array('id'), array( + $session = new backup_nested_element('session', ['id'], [ 'facetoface', 'capacity', 'allowoverbook', 'details', 'datetimeknown', 'duration', 'normalcost', - 'discountcost', 'allowcancellations', 'timecreated', 'timemodified')); + 'discountcost', 'allowcancellations', 'timecreated', 'timemodified', + ]); $signups = new backup_nested_element('signups'); - $signup = new backup_nested_element('signup', array('id'), array( - 'sessionid', 'userid', 'mailedreminder', 'discountcode', 'notificationtype')); + $signup = new backup_nested_element('signup', ['id'], [ + 'sessionid', 'userid', 'mailedreminder', 'discountcode', 'notificationtype', + ]); $signupsstatus = new backup_nested_element('signups_status'); - $signupstatus = new backup_nested_element('signup_status', array('id'), array( - 'signupid', 'statuscode', 'superceded', 'grade', 'note', 'advice', 'createdby', 'timecreated')); + $signupstatus = new backup_nested_element('signup_status', ['id'], [ + 'signupid', 'statuscode', 'superceded', 'grade', 'note', 'advice', 'createdby', 'timecreated', + ]); $sessionroles = new backup_nested_element('session_roles'); - $sessionrole = new backup_nested_element('session_role', array('id'), array( - 'sessionid', 'roleid', 'userid')); + $sessionrole = new backup_nested_element('session_role', ['id'], [ + 'sessionid', 'roleid', 'userid', + ]); $sessiondata = new backup_nested_element('session_data'); // May need to replace first item 'data' with better value. - $sessiondataelement = new backup_nested_element('data', array('id'), array( - 'fieldid', 'sessionid', 'data')); + $sessiondataelement = new backup_nested_element('data', ['id'], [ + 'fieldid', 'sessionid', 'data', + ]); $sessionsdates = new backup_nested_element('sessions_dates'); - $sessionsdate = new backup_nested_element('sessions_date', array('id'), array( - 'sessionid', 'timestart', 'timefinish')); + $sessionsdate = new backup_nested_element('sessions_date', ['id'], [ + 'sessionid', 'timestart', 'timefinish', + ]); // Build the tree. $facetoface->add_child($sessions); @@ -98,20 +103,20 @@ protected function define_structure() { $sessionsdates->add_child($sessionsdate); // Define sources. - $facetoface->set_source_table('facetoface', array('id' => backup::VAR_ACTIVITYID)); + $facetoface->set_source_table('facetoface', ['id' => backup::VAR_ACTIVITYID]); - $session->set_source_table('facetoface_sessions', array('facetoface' => backup::VAR_PARENTID)); + $session->set_source_table('facetoface_sessions', ['facetoface' => backup::VAR_PARENTID]); - $sessionsdate->set_source_table('facetoface_sessions_dates', array('sessionid' => backup::VAR_PARENTID)); + $sessionsdate->set_source_table('facetoface_sessions_dates', ['sessionid' => backup::VAR_PARENTID]); if ($userinfo) { - $signup->set_source_table('facetoface_signups', array('sessionid' => backup::VAR_PARENTID)); + $signup->set_source_table('facetoface_signups', ['sessionid' => backup::VAR_PARENTID]); - $signupstatus->set_source_table('facetoface_signups_status', array('signupid' => backup::VAR_PARENTID)); + $signupstatus->set_source_table('facetoface_signups_status', ['signupid' => backup::VAR_PARENTID]); - $sessionrole->set_source_table('facetoface_session_roles', array('sessionid' => backup::VAR_PARENTID)); + $sessionrole->set_source_table('facetoface_session_roles', ['sessionid' => backup::VAR_PARENTID]); - $sessiondataelement->set_source_table('facetoface_session_data', array('sessionid' => backup::VAR_PARENTID)); + $sessiondataelement->set_source_table('facetoface_session_data', ['sessionid' => backup::VAR_PARENTID]); } // Define id annotations. diff --git a/backup/moodle2/restore_facetoface_activity_task.class.php b/backup/moodle2/restore_facetoface_activity_task.class.php index a326670..d4729c8 100644 --- a/backup/moodle2/restore_facetoface_activity_task.class.php +++ b/backup/moodle2/restore_facetoface_activity_task.class.php @@ -54,9 +54,7 @@ protected function define_my_steps() { * processed by the link decoder */ public static function define_decode_contents() { - $contents = array(); - // $contents[] = new restore_decode_content('facetoface', array(), 'facetoface'); - return $contents; + return []; } /** @@ -64,7 +62,7 @@ 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('FACETOFACEVIEWBYID', '/mod/facetoface/view.php?id=$1', 'course_module'); $rules[] = new restore_decode_rule('FACETOFACEINDEX', '/mod/facetoface/index.php?id=$1', 'course'); return $rules; @@ -77,8 +75,7 @@ public static function define_decode_rules() { * of {@link restore_log_rule} objects */ public static function define_restore_log_rules() { - $rules = array(); - return $rules; + return []; } /** @@ -92,7 +89,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 = []; $rules[] = new restore_log_rule('facetoface', 'view all', 'index.php?id={course}', null); return $rules; } diff --git a/backup/moodle2/restore_facetoface_stepslib.php b/backup/moodle2/restore_facetoface_stepslib.php index 8e84082..394cf27 100644 --- a/backup/moodle2/restore_facetoface_stepslib.php +++ b/backup/moodle2/restore_facetoface_stepslib.php @@ -28,26 +28,42 @@ * @author Francois Marier */ -defined('MOODLE_INTERNAL') || die(); - /** * Structure step to restore one facetoface activity */ class restore_facetoface_activity_structure_step extends restore_activity_structure_step { protected function define_structure() { - $paths = array(); + $paths = []; $userinfo = $this->get_setting_value('userinfo'); $paths[] = new restore_path_element('facetoface', '/activity/facetoface'); $paths[] = new restore_path_element('facetoface_session', '/activity/facetoface/sessions/session'); - $paths[] = new restore_path_element('facetoface_sessions_dates', '/activity/facetoface/sessions/session/sessions_dates/sessions_date'); - $paths[] = new restore_path_element('facetoface_session_data', '/activity/facetoface/sessions/session/session_data/session_data_element'); - $paths[] = new restore_path_element('facetoface_session_field', '/activity/facetoface/sessions/session/session_field/session_field_element'); + $paths[] = new restore_path_element( + 'facetoface_sessions_dates', + '/activity/facetoface/sessions/session/sessions_dates/sessions_date' + ); + $paths[] = new restore_path_element( + 'facetoface_session_data', + '/activity/facetoface/sessions/session/session_data/session_data_element' + ); + $paths[] = new restore_path_element( + 'facetoface_session_field', + '/activity/facetoface/sessions/session/session_field/session_field_element' + ); if ($userinfo) { - $paths[] = new restore_path_element('facetoface_signup', '/activity/facetoface/sessions/session/signups/signup'); - $paths[] = new restore_path_element('facetoface_signups_status', '/activity/facetoface/sessions/session/signups/signup/signups_status/signup_status'); - $paths[] = new restore_path_element('facetoface_session_roles', '/activity/facetoface/sessions/session/session_roles/session_role'); + $paths[] = new restore_path_element( + 'facetoface_signup', + '/activity/facetoface/sessions/session/signups/signup' + ); + $paths[] = new restore_path_element( + 'facetoface_signups_status', + '/activity/facetoface/sessions/session/signups/signup/signups_status/signup_status' + ); + $paths[] = new restore_path_element( + 'facetoface_session_roles', + '/activity/facetoface/sessions/session/session_roles/session_role' + ); } // Return the paths wrapped into standard activity structure. @@ -57,7 +73,7 @@ protected function define_structure() { protected function process_facetoface($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->course = $this->get_courseid(); @@ -69,7 +85,7 @@ protected function process_facetoface($data) { protected function process_facetoface_session($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->facetoface = $this->get_new_parentid('facetoface'); @@ -85,7 +101,7 @@ protected function process_facetoface_session($data) { protected function process_facetoface_signup($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->sessionid = $this->get_new_parentid('facetoface_session'); @@ -99,7 +115,7 @@ protected function process_facetoface_signup($data) { protected function process_facetoface_signups_status($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->signupid = $this->get_new_parentid('facetoface_signup'); @@ -113,7 +129,7 @@ protected function process_facetoface_signups_status($data) { protected function process_facetoface_session_roles($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->sessionid = $this->get_new_parentid('facetoface_session'); @@ -127,7 +143,7 @@ protected function process_facetoface_session_roles($data) { protected function process_facetoface_session_data($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->sessionid = $this->get_new_parentid('facetoface_session'); @@ -141,7 +157,7 @@ protected function process_facetoface_session_data($data) { protected function process_facetoface_session_field($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; // Insert the entry record. @@ -151,7 +167,7 @@ protected function process_facetoface_session_field($data) { protected function process_facetoface_sessions_dates($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->sessionid = $this->get_new_parentid('facetoface_session'); diff --git a/cancelsignup.php b/cancelsignup.php index 9d923e0..ff6957e 100644 --- a/cancelsignup.php +++ b/cancelsignup.php @@ -41,10 +41,10 @@ if (!$session->allowcancellations) { throw new moodle_exception('error:cancellationsnotallowed', '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)) { @@ -67,7 +67,6 @@ } if ($fromform = $mform->get_data()) { // Form submitted. - if (empty($fromform->submitbutton)) { throw new moodle_exception('error:unknownbuttonclicked', 'facetoface', $returnurl); } @@ -76,12 +75,11 @@ $errorstr = ''; if (facetoface_user_cancel($session, false, false, $errorstr, $fromform->cancelreason)) { - // Logging and events trigger. - $params = array( + $params = [ 'context' => $contextmodule, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\cancel_booking::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -93,9 +91,13 @@ $error = facetoface_send_cancellation_notice($facetoface, $session, $USER->id); if (empty($error)) { if ($session->datetimeknown && $facetoface->cancellationinstrmngr) { - $message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('cancellationsentmgr', 'facetoface'); + $message .= html_writer::empty_tag('br') + . html_writer::empty_tag('br') + . get_string('cancellationsentmgr', 'facetoface'); } else { - $message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('cancellationsent', 'facetoface'); + $message .= html_writer::empty_tag('br') + . html_writer::empty_tag('br') + . get_string('cancellationsent', 'facetoface'); } } else { throw new moodle_exception($error, 'facetoface'); @@ -104,12 +106,11 @@ redirect($returnurl, $message, $timemessage); } else { - // Logging and events trigger. - $params = array( + $params = [ 'context' => $contextmodule, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\cancel_booking_failed::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -124,7 +125,7 @@ $pagetitle = format_string($facetoface->name); $PAGE->set_cm($cm); -$PAGE->set_url('/mod/facetoface/cancelsignup.php', array('s' => $s, 'backtoallsessions' => $backtoallsessions, 'confirm' => $confirm)); +$PAGE->set_url('/mod/facetoface/cancelsignup.php', ['s' => $s, 'backtoallsessions' => $backtoallsessions, 'confirm' => $confirm]); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); diff --git a/classes/booking_manager.php b/classes/booking_manager.php new file mode 100644 index 0000000..b6230f0 --- /dev/null +++ b/classes/booking_manager.php @@ -0,0 +1,344 @@ +. + +namespace mod_facetoface; + +use context_course; +use context_user; +use file_storage; +use lang_string; +use moodle_exception; + +/** + * Booking manager + * + * @package mod_facetoface + * @author Kevin Pham + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class booking_manager { + + /** @var stored_file the file to process as a stored_file object */ + private $file; + + /** @var int The facetoface module ID. */ + private $f; + + /** @var int The course id. */ + private $course; + + /** @var context_course The course context. */ + private $coursecontext; + + /** @var int The course id. */ + private $facetoface; + + /** @var array collection of records (if loaded from memory), in an array. */ + private $records; + + /** @var bool Whether or not the bookings are loaded from a file. */ + private $usefile = true; + + /** + * Constructor for the booking manager. + * @param int $f The facetoface module ID. + * @param array $records The records to process. + */ + public function __construct($f, $records = []) { + global $DB; + + if (!$facetoface = $DB->get_record('facetoface', ['id' => $f])) { + throw new moodle_exception('error:incorrectfacetofaceid', 'facetoface'); + } + if (!$course = $DB->get_record('course', ['id' => $facetoface->course])) { + throw new moodle_exception('error:coursemisconfigured', 'facetoface'); + } + + $this->f = $f; + $this->facetoface = $facetoface; + $this->course = $course; + $this->coursecontext = context_course::instance($course->id); + $this->records = $records; + } + + /** + * Returns file from file system. File must exist. + * @param int $fileitemid Item id of file stored in the current $USER's draft file area + */ + public function load_from_file(int $fileitemid) { + global $USER; + $this->usefile = true; + + $fs = new file_storage(); + $files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $fileitemid, 'itemid', false); + + if (count($files) != 1) { + throw new moodle_exception('error:cannotloadfile', 'mod_facetoface'); + } + + $this->file = current($files); + } + + /** + * Load in the records to process from an array + * @param array $records + */ + public function load_from_array(array $records) { + $this->usefile = false; + $this->records = $records; + + return $this; + } + + /** + * Get the headers for the records. + * @return array + */ + public static function get_headers(): array { + return [ + 'email', + 'session', + 'status', + 'discountcode', + 'notificationtype', + ]; + } + + /** + * Get an iterator for the records. + * @return Generator + */ + private function get_iterator(): \Generator { + if (!$this->usefile) { + foreach ($this->records as $record) { + yield $record; + } + return; + } + + $handle = $this->file->get_content_file_handle(); + $maxlinelength = 1000; + $delimiter = ','; + $rownumber = 1; // First row is headers. + $headers = self::get_headers(); + $numheaders = count($headers); + fgets($handle); // Move pointer past first line (headers). + try { + while (($data = fgetcsv($handle, $maxlinelength, $delimiter)) !== false) { + $rownumber++; + $numfields = count($data); + if ($numfields !== $numheaders) { + throw new moodle_exception('error:bookingsuploadfileheaderfieldmismatch', 'mod_facetoface'); + } + $record = array_combine($headers, $data); + yield (object) $record; + } + } finally { + fclose($handle); + } + } + + /** + * Validate the records provided to ensure they can be processed without errors. + * + * As there are multiple dependant data points (users, sessions, capacity) + * that are checked. They are all in this method. + * + * @return array An array of errors. + */ + public function validate(): array { + global $DB; + $errors = []; + $sessioncapacitycache = []; + + // Break into rows and validate the multiple interdependant fields together. + foreach ($this->get_iterator() as $index => $entry) { + $row = $index + 1; + + // Set defaults for fields with no value. + $entry->status = $entry->status ?? ''; + $entry->notificationtype = $entry->notificationtype ?? ''; + $entry->discountcode = $entry->discountcode ?? ''; + + // Validate and get user. + $userids = $DB->get_records('user', ['email' => $entry->email], 'id'); + + // Multiple matched, ambiguous which is the real one. + if (count($userids) > 1) { + $errors[] = [$row, new lang_string('error:multipleusersmatched', 'mod_facetoface', $entry->email)]; + } + + // None matched at all - missing. + if (empty($userids)) { + $errors[] = [$row, new lang_string('error:userdoesnotexist', 'mod_facetoface', $entry->email)]; + } else { + $userid = current($userids)->id; + } + + // Check session exists. + $session = facetoface_get_session($entry->session); + if (!$session) { + $errors[] = [$row, new lang_string('error:sessiondoesnotexist', 'mod_facetoface', $entry->session)]; + } + + // Check for session overbooking, that is, if it would go over session capacity. + if ($session) { + $timenow = time(); + + // Don't allow user to cancel a session that has already occurred. + if ($entry->status === 'cancelled' && facetoface_has_session_started($session, $timenow)) { + $errors[] = [$row, new lang_string('error:sessionalreadystarted', 'mod_facetoface', $entry->session)]; + } + + if ($session->datetimeknown + && $entry->status !== 'cancelled' + && facetoface_has_session_started($session, $timenow)) { + $inprogressstr = get_string('cannotsignupsessioninprogress', 'facetoface'); + $overstr = get_string('cannotsignupsessionover', 'facetoface'); + + $errorstring = facetoface_is_session_in_progress($session, $timenow) ? $inprogressstr : $overstr; + $errors[] = [$row, $errorstring]; + } + + // Set the session capacity if it hasn't been set yet. + if ($session->allowoverbook == 0 && !isset($sessioncapacitycache[$session->id])) { + // Total minus current capacity. + $sessioncapacitycache[$session->id]['capacity'] = + $session->capacity - facetoface_get_num_attendees($session->id, MDL_F2F_STATUS_APPROVED); + } + + // If the status is not cancelled, then it's considered a booking and it should deduct from the session. + if ($session->allowoverbook == 0 && $entry->status !== 'cancelled') { + $sessioncapacitycache[$session->id]['capacity']--; + $sessioncapacitycache[$session->id]['rows'][] = $row; + } + } + + // Check user enrolment into the course. + if (isset($userid) && !is_enrolled($this->coursecontext, $userid)) { + $errors[] = [$row, new lang_string('error:userisnotenrolledintocourse', 'mod_facetoface', $entry->email)]; + } + + // Check to ensure valid notification types are used if set. + if (isset($entry->notificationtype) + && !in_array( + $this->transform_notification_type($entry->notificationtype), + [MDL_F2F_BOTH, MDL_F2F_TEXT, MDL_F2F_ICAL] + )) { + $errors[] = [ + $row, + new lang_string('error:invalidnotificationtypespecified', 'mod_facetoface', $entry->notificationtype), + ]; + } + + // Check to ensure a valid status is set. + if (isset($entry->status) && !in_array($entry->status, ['', 'cancelled', 'booked'])) { + $errors[] = [ + $row, + new lang_string('error:invalidstatusspecified', 'mod_facetoface', $entry->status), + ]; + } + } + + // For all sessions that went over capacity, report it. + $overcapacitysessions = array_filter($sessioncapacitycache, function ($s) { + return $s['capacity'] < 0; + }); + if (!empty($overcapacitysessions)) { + foreach ($overcapacitysessions as $sessionid => $details) { + $errors[] = [ + implode(', ', $details['rows']), + new lang_string( + 'error:sessionoverbooked', + 'mod_facetoface', + (object) ['session' => $sessionid, 'amount' => -$details['capacity']] + ), + ]; + } + } + + return $errors; + } + + /** + * Transform notification type to internal representation. + * + * @param string $type Notification type. + * @return int|null + */ + private function transform_notification_type($type) { + $mapping = [ + 'email' => MDL_F2F_TEXT, + 'ical' => MDL_F2F_ICAL, + 'icalendar' => MDL_F2F_ICAL, + 'both' => MDL_F2F_BOTH, + '' => MDL_F2F_BOTH, // Defaults to sending both if nothing is specified. + ]; + + return $mapping[strtolower($type)] ?? null; + } + + /** + * Process the bookings in the file. + * + * @return bool + * @throws moodle_exception + */ + public function process() { + global $DB; + + if (!empty($this->validate())) { + throw new moodle_exception('error:cannotprocessbookingsvalidationerrorsexist', 'facetoface'); + } + + // Records should be valid at this point. + foreach ($this->get_iterator() as $entry) { + $user = $DB->get_record('user', ['email' => $entry->email]); + $session = facetoface_get_session($entry->session); + + // Get signup type. + if ($entry->status === 'cancelled') { + if (facetoface_user_cancel($session, $user->id, true, $cancelerr)) { + // Notify the user of the cancellation if the session hasn't started yet. + $timenow = time(); + if (!facetoface_has_session_started($session, $timenow)) { + facetoface_send_cancellation_notice($this->facetoface, $session, $user->id); + } + } else { + throw new \Exception($cancelerr); + } + } else { + $statuscode = MDL_F2F_STATUS_WAITLISTED; + if ($session->datetimeknown) { + $statuscode = MDL_F2F_STATUS_BOOKED; + } + facetoface_user_signup( + $session, + $this->facetoface, + $this->course, + $entry->discountcode, + $this->transform_notification_type($entry->notificationtype), + $statuscode, + $user->id, + true + ); + } + } + + return true; + } +} diff --git a/classes/cancelsignup_form.php b/classes/cancelsignup_form.php index e8e445d..2fec831 100644 --- a/classes/cancelsignup_form.php +++ b/classes/cancelsignup_form.php @@ -50,9 +50,9 @@ public function definition() { $mform->addElement('text', 'cancelreason', get_string('cancelreason', 'facetoface'), 'size="60" maxlength="255"'); $mform->setType('cancelreason', PARAM_TEXT); - $buttonarray = array(); + $buttonarray = []; $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('yes')); $buttonarray[] =& $mform->createElement('cancel', 'cancelbutton', get_string('no')); - $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); } } diff --git a/classes/completion/custom_completion.php b/classes/completion/custom_completion.php index cc4705c..3382c1e 100644 --- a/classes/completion/custom_completion.php +++ b/classes/completion/custom_completion.php @@ -84,9 +84,7 @@ public function get_custom_rule_descriptions(): array { $text = get_string('completiondetail:attendance_full', 'facetoface'); } } - return [ - 'completionattendance' => $text, - ]; + return ['completionattendance' => $text]; } /** diff --git a/classes/customfield_form.php b/classes/customfield_form.php index 1c2acfa..8cf9557 100644 --- a/classes/customfield_form.php +++ b/classes/customfield_form.php @@ -51,11 +51,11 @@ public function definition() { $mform->addRule('shortname', null, 'required', null, 'client'); $mform->setType('shortname', PARAM_ALPHANUM); - $options = array( + $options = [ CUSTOMFIELD_TYPE_TEXT => get_string('field:text', 'facetoface'), CUSTOMFIELD_TYPE_SELECT => get_string('field:select', 'facetoface'), - CUSTOMFIELD_TYPE_MULTISELECT => get_string('field:multiselect', 'facetoface') - ); + CUSTOMFIELD_TYPE_MULTISELECT => get_string('field:multiselect', 'facetoface'), + ]; $mform->addElement('select', 'type', get_string('setting:type', 'facetoface'), $options); $mform->addRule('type', null, 'required', null, 'client'); $mform->setDefault('type', 0); @@ -80,9 +80,9 @@ public function definition() { public function validation($data, $files) { global $DB; - $errors = array(); + $errors = []; $where = "id <> ? AND shortname = ?"; - $params = array($data['id'], $data['shortname']); + $params = [$data['id'], $data['shortname']]; if ($DB->record_exists_select('facetoface_session_field', $where, $params)) { $errors['shortname'] = get_string('error:shortnametaken', 'facetoface'); diff --git a/classes/event/add_session.php b/classes/event/add_session.php index 71a9d43..6815184 100644 --- a/classes/event/add_session.php +++ b/classes/event/add_session.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface add session event class. * @@ -76,7 +74,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/sessions.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/sessions.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/add_session_failed.php b/classes/event/add_session_failed.php index 36d5103..23095fb 100644 --- a/classes/event/add_session_failed.php +++ b/classes/event/add_session_failed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface add session failed event class. * @@ -76,7 +74,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/sessions.php', array('f' => $this->objectid)); + return new \moodle_url('/mod/facetoface/sessions.php', ['f' => $this->objectid]); } /** diff --git a/classes/event/approve_requests.php b/classes/event/approve_requests.php index e3591ed..026255c 100644 --- a/classes/event/approve_requests.php +++ b/classes/event/approve_requests.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface approve requests event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' has approved attendance requests for session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid'."; + return "The user with id '$this->userid' has approved attendance requests " + . "for session with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid'."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/attendees.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/attendees.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/attendees_viewed.php b/classes/event/attendees_viewed.php index 9c4d0a1..dd01996 100644 --- a/classes/event/attendees_viewed.php +++ b/classes/event/attendees_viewed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface attendees viewed event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' has viewed the attendees for session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid'."; + return "The user with id '$this->userid' has viewed the attendees " + . "for session with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid'."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/attendees.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/attendees.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/cancel_booking.php b/classes/event/cancel_booking.php index 535da87..4907147 100644 --- a/classes/event/cancel_booking.php +++ b/classes/event/cancel_booking.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface cancel booking event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' has cancelled the booking for session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid'."; + return "The user with id '$this->userid' has cancelled the booking " + . "for session with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid'."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/cancelsignup.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/cancelsignup.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/cancel_booking_failed.php b/classes/event/cancel_booking_failed.php index de35782..98ef63e 100644 --- a/classes/event/cancel_booking_failed.php +++ b/classes/event/cancel_booking_failed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface cancel booking failed event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' tried to cancel booking for session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid' and it failed."; + return "The user with id '$this->userid' tried to cancel booking " + . "for session with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid' and it failed."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/cancelsignup.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/cancelsignup.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/course_module_viewed.php b/classes/event/course_module_viewed.php index c710e04..932a7f6 100644 --- a/classes/event/course_module_viewed.php +++ b/classes/event/course_module_viewed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface course module viewed event class. * @@ -57,7 +55,8 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' has viewed the Face-to-Face instance with course module id '$this->contextinstanceid' "; + return "The user with id '$this->userid' has viewed the Face-to-Face instance " + . "with course module id '$this->contextinstanceid' "; } /** @@ -75,6 +74,6 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/view.php', array('f' => $this->objectid)); + return new \moodle_url('/mod/facetoface/view.php', ['f' => $this->objectid]); } } diff --git a/classes/event/course_viewed.php b/classes/event/course_viewed.php index 02a82ba..06f2706 100644 --- a/classes/event/course_viewed.php +++ b/classes/event/course_viewed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface course viewed event class. * @@ -75,7 +73,6 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/index.php', array('id' => $this->courseid)); + return new \moodle_url('/mod/facetoface/index.php', ['id' => $this->courseid]); } - } diff --git a/classes/event/csv_processed.php b/classes/event/csv_processed.php new file mode 100644 index 0000000..e4a3f70 --- /dev/null +++ b/classes/event/csv_processed.php @@ -0,0 +1,81 @@ +. + +namespace mod_facetoface\event; + +/** + * The mod_facetoface CSV processed event. + * + * @package mod_facetoface + * @author Kevin Pham + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class csv_processed extends \core\event\base { + + /** + * Init method. + * + * @return void + */ + protected function init() { + $this->data['crud'] = 'r'; + $this->data['edulevel'] = self::LEVEL_PARTICIPATING; + $this->data['objecttable'] = 'facetoface'; + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return "The user with id '$this->userid' has processed an uploaded CSV file for session bookings " . + "in the facetoface instance with the course module id '$this->contextinstanceid'."; + } + + /** + * Return localised event name. + * + * @return string + */ + public static function get_name() { + return get_string('eventcsvprocessed', 'mod_facetoface'); + } + + /** + * Get URL related to the action + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/mod/facetoface/upload.php', ['f' => $this->objectid]); + } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if ($this->contextlevel != CONTEXT_MODULE) { + throw new \coding_exception('Context level must be CONTEXT_MODULE.'); + } + } +} diff --git a/classes/event/delete_session.php b/classes/event/delete_session.php index 35c31b7..78f1909 100644 --- a/classes/event/delete_session.php +++ b/classes/event/delete_session.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface delete session event class. * @@ -76,7 +74,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/sessions.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/sessions.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/delete_session_failed.php b/classes/event/delete_session_failed.php index 02743f9..6a68d10 100644 --- a/classes/event/delete_session_failed.php +++ b/classes/event/delete_session_failed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface delete session failed event class. * @@ -76,7 +74,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/sessions.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/sessions.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/signup_failed.php b/classes/event/signup_failed.php index 76c56fd..0c66daa 100644 --- a/classes/event/signup_failed.php +++ b/classes/event/signup_failed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface signup failed event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' tried to signup for session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid' and it failed."; + return "The user with id '$this->userid' tried to signup " + . "for session with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid' and it failed."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/signup.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/signup.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/signup_success.php b/classes/event/signup_success.php index 5883bd1..717500b 100644 --- a/classes/event/signup_success.php +++ b/classes/event/signup_success.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface signup event class. * @@ -76,7 +74,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/signup.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/signup.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/take_attendance.php b/classes/event/take_attendance.php index 60a8ee5..6f9c8f8 100644 --- a/classes/event/take_attendance.php +++ b/classes/event/take_attendance.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface take attendance event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' has taken the attendance for session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid'."; + return "The user with id '$this->userid' has taken the attendance " + . "for session with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid'."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/attendees.php', array('s' => $this->objectid, 'takeattendance' => 1)); + return new \moodle_url('/mod/facetoface/attendees.php', ['s' => $this->objectid, 'takeattendance' => 1]); } /** diff --git a/classes/event/take_attendance_failed.php b/classes/event/take_attendance_failed.php index 8737a14..37d1008 100644 --- a/classes/event/take_attendance_failed.php +++ b/classes/event/take_attendance_failed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface take attendance event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' tried to take attendance for session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid' and it failed."; + return "The user with id '$this->userid' tried to take attendance " + . "for session with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid' and it failed."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/attendees.php', array('s' => $this->objectid, 'takeattendance' => 1)); + return new \moodle_url('/mod/facetoface/attendees.php', ['s' => $this->objectid, 'takeattendance' => 1]); } /** diff --git a/classes/event/update_manageremail_failed.php b/classes/event/update_manageremail_failed.php index d77f2b9..ec2e9e5 100644 --- a/classes/event/update_manageremail_failed.php +++ b/classes/event/update_manageremail_failed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface update manager email failed event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' tried to update a manager email for session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid' and it failed."; + return "The user with id '$this->userid' tried to update a manager email " + . "for session with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid' and it failed."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/signup.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/signup.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/update_session.php b/classes/event/update_session.php index 13878dc..9ff16ae 100644 --- a/classes/event/update_session.php +++ b/classes/event/update_session.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface update session event class. * @@ -76,7 +74,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/sessions.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/sessions.php', ['s' => $this->objectid]); } /** diff --git a/classes/event/update_session_failed.php b/classes/event/update_session_failed.php index 4d51cf8..eaf26ac 100644 --- a/classes/event/update_session_failed.php +++ b/classes/event/update_session_failed.php @@ -27,8 +27,6 @@ namespace mod_facetoface\event; -defined('MOODLE_INTERNAL') || die(); - /** * The mod_facetoface update session failed event class. * @@ -57,8 +55,9 @@ protected function init() { * @return string */ public function get_description() { - return "The user with id '$this->userid' has tried to update session with id '$this->objectid' in the facetoface instance " . - "with the course module id '$this->contextinstanceid' and it failed."; + return "The user with id '$this->userid' has tried to update session " + . "with id '$this->objectid' in the facetoface instance " + . "with the course module id '$this->contextinstanceid' and it failed."; } /** @@ -76,7 +75,7 @@ public static function get_name() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/facetoface/sessions.php', array('s' => $this->objectid)); + return new \moodle_url('/mod/facetoface/sessions.php', ['s' => $this->objectid]); } /** diff --git a/classes/form/confirm_bookings_form.php b/classes/form/confirm_bookings_form.php new file mode 100644 index 0000000..b79b2ec --- /dev/null +++ b/classes/form/confirm_bookings_form.php @@ -0,0 +1,67 @@ +. + +namespace mod_facetoface\form; + +use html_writer; +use moodle_url; +use moodleform; +use single_button; + +defined('MOODLE_INTERNAL') || die; +require_once($CFG->libdir . '/formslib.php'); + +/** + * Processing confirm form + * + * @package local_facetoface + * @author Kevin Pham + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class confirm_bookings_form extends moodleform { + + /** + * Form definition + */ + public function definition() { + global $OUTPUT; + + $mform = $this->_form; + $fileid = $this->_customdata['fileid'] ?: 0; + $f = $this->_customdata['f'] ?: 0; + + // The facetoface module ID. + $mform->addElement('hidden', 'f'); + $mform->setType('f', PARAM_INT); + + // Reference to the uploaded file. + $mform->addElement('hidden', 'fileid', $fileid); + $mform->setType('fileid', PARAM_INT); + + $backurl = new moodle_url('/mod/facetoface/upload.php', ['f' => $f]); + $htmlbuttons = $OUTPUT->render((new single_button( + new moodle_url('/mod/facetoface/upload.php', ['f' => $f, 'fileid' => $fileid, 'process' => 1]), + get_string('facetoface:confirmandprocess', 'mod_facetoface'), + 'post', + true + ))); + $htmlbuttons .= $OUTPUT->single_button($backurl, get_string('back'), 'get', ['class' => 'ml-3']); + + $htmlbuttons = html_writer::tag('div', $htmlbuttons, ['class' => 'd-flex gap-2']); + $mform->addElement('html', $htmlbuttons); + } +} diff --git a/classes/form/upload_bookings_form.php b/classes/form/upload_bookings_form.php new file mode 100644 index 0000000..f4d76eb --- /dev/null +++ b/classes/form/upload_bookings_form.php @@ -0,0 +1,73 @@ +. + +namespace mod_facetoface\form; + +use moodle_url; +use html_writer; + +/** + * Upload bookings form class + * + * @package mod_facetoface + * @author Kevin Pham + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class upload_bookings_form extends \moodleform { + + /** + * Build form for importing bookings. + * + * {@inheritDoc} + * @see \moodleform::definition() + */ + public function definition() { + global $CFG; + + $mform = $this->_form; + + $mform->addElement('header', 'settingsheader', get_string('upload')); + + $url = new moodle_url('/mod/facetoface/example.csv'); + $link = html_writer::link($url, 'example.csv'); + $mform->addElement('static', 'examplecsv', get_string('facetoface:examplecsv', 'mod_facetoface'), $link); + + $maxbytes = get_max_upload_file_size($CFG->maxbytes, 0); + $mform->addElement('filemanager', 'csvfile', get_string('facetoface:uploadbookingsfile', 'mod_facetoface'), null, [ + 'subdirs' => 0, + 'maxfiles' => 1, + 'accepted_types' => 'csv', + 'maxbytes' => $maxbytes, + 'return_types' => FILE_INTERNAL | FILE_EXTERNAL, + ]); + $mform->setType('csvfile', PARAM_INT); + $mform->addRule('csvfile', get_string('required'), 'required', null, 'client'); + + $mform->addElement('static', 'csvuploadhelp', '', + nl2br(get_string('facetoface:uploadbookingsfiledesc', 'mod_facetoface'))); + + // The facetoface module ID. + $mform->addElement('hidden', 'f'); + $mform->setType('f', PARAM_INT); + + // Whether or not the form should process what has been uploaded. + $mform->addElement('hidden', 'validate'); + $mform->setType('validate', PARAM_INT); + + $mform->addElement('submit', 'submit', get_string('facetoface:uploadandpreview', 'mod_facetoface')); + } +} diff --git a/classes/helper.php b/classes/helper.php index 64b2490..bb28aa0 100644 --- a/classes/helper.php +++ b/classes/helper.php @@ -16,6 +16,11 @@ namespace mod_facetoface; +use context_user; +use file_storage; +use stored_file; +use moodle_exception; + /** * Helper functions for plugin. * @@ -43,4 +48,21 @@ public static function is_approval_required(\stdClass $instance): bool { // Approvals must be enabled at site level and activity level. return get_config('facetoface', 'enableapprovals') && $instance->approvalreqd; } + + /** + * Returns file from file system. File must exist. + * @param int $fileitemid Item id of file stored in the current $USER's draft file area + * @return stored_file + */ + public static function get_file(int $fileitemid): stored_file { + global $USER; + $fs = new file_storage(); + $files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $fileitemid, 'itemid', false); + + if (count($files) != 1) { + throw new moodle_exception('error:cannotloadfile', 'mod_facetoface'); + } + + return current($files); + } } diff --git a/classes/observer.php b/classes/observer.php index 1e9a424..89c79cc 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -28,8 +28,6 @@ * @author Francois Marier */ -defined('MOODLE_INTERNAL') || die(); - /** * Event observer for mod_forum. */ @@ -45,9 +43,9 @@ public static function user_enrolment_deleted(\core\event\user_enrolment_deleted // NOTE: this has to be as fast as possible. // Get user enrolment info from event. - $cp = (object)$event->other['userenrolment']; + $cp = (object) $event->other['userenrolment']; if ($cp->lastenrol) { - $params = array('userid' => $cp->userid, 'courseid' => $cp->courseid); + $params = ['userid' => $cp->userid, 'courseid' => $cp->courseid]; $f2fselect = "IN (SELECT s.id FROM {facetoface_sessions} s JOIN {facetoface} f ON f.id = s.facetoface WHERE f.course = :courseid)"; @@ -55,7 +53,8 @@ public static function user_enrolment_deleted(\core\event\user_enrolment_deleted // Start deletions. $transaction = $DB->start_delegated_transaction(); $DB->delete_records_select('facetoface_signups_status', - 'signupid IN (SELECT id FROM {facetoface_signups} WHERE userid = :userid AND sessionid ' . $f2fselect . ')', $params); + 'signupid IN (SELECT id FROM {facetoface_signups} WHERE userid = :userid AND sessionid ' . $f2fselect . ')', + $params); $DB->delete_records_select('facetoface_signups', 'userid = :userid AND sessionid ' . $f2fselect, $params); $DB->delete_records_select('facetoface_session_roles', 'userid = :userid AND sessionid ' . $f2fselect, $params); $transaction->allow_commit(); diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 61de87a..e8ea863 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -24,8 +24,6 @@ namespace mod_facetoface\privacy; -defined('MOODLE_INTERNAL') || die(); - use core_privacy\local\metadata\collection; use core_privacy\local\request\approved_contextlist; use core_privacy\local\request\approved_userlist; @@ -45,18 +43,19 @@ class provider implements // This plugin stores personal data. \core_privacy\local\metadata\provider, - // This plugin deals with user lists + // This plugin deals with user lists. \core_privacy\local\request\core_userlist_provider, // This plugin is a core_user_data_provider. \core_privacy\local\request\plugin\provider { + /** * Return the fields which contain personal data. * * @param collection $items a reference to the collection to use to store the metadata. * @return collection the updated collection of metadata items. */ - public static function get_metadata(collection $collection) : collection { + public static function get_metadata(collection $collection): collection { $collection->add_database_table( 'facetoface_signups', [ @@ -99,7 +98,7 @@ public static function get_metadata(collection $collection) : collection { * @param int $userid the userid. * @return contextlist the list of contexts containing user info for the user. */ - public static function get_contexts_for_userid(int $userid) : contextlist { + public static function get_contexts_for_userid(int $userid): contextlist { // Fetch all facetoface contexts with userdata. $sql = "SELECT c.id FROM {context} c @@ -130,7 +129,7 @@ public static function export_user_data(approved_contextlist $contextlist) { global $DB; // Remove contexts different from COURSE_MODULE. - $contexts = array_reduce($contextlist->get_contexts(), function($carry, $context) { + $contexts = array_reduce($contextlist->get_contexts(), function ($carry, $context) { if ($context->contextlevel == CONTEXT_MODULE) { $carry[] = $context->id; } @@ -173,13 +172,13 @@ public static function export_user_data(approved_contextlist $contextlist) { if ($session->mailedreminder > 100) { // Mailed reminder uses magic numbers or timestamp. $session->mailedreminder = transform::datetime($session->mailedreminder); } - $signups[$session->contextid][$session->id] = (object)[ + $signups[$session->contextid][$session->id] = (object) [ 'id' => $session->id, 'sessionid' => $session->sessionid, 'mailedreminder' => $session->mailedreminder, ]; } - $signupstatus[$session->contextid][$session->id][] = (object)[ + $signupstatus[$session->contextid][$session->id][] = (object) [ 'statuscode' => $session->id, 'grade' => $session->grade, 'note' => $session->note, @@ -188,22 +187,22 @@ public static function export_user_data(approved_contextlist $contextlist) { } $sessions->close(); - array_walk($signups, function($data, $contextid) { + array_walk($signups, function ($data, $contextid) { $context = \context::instance_by_id($contextid); writer::with_context($context)->export_related_data( [], 'sessions', - (object)['signups' => $data] + (object) ['signups' => $data] ); }); - array_walk($signupstatus, function($data, $contextid) { + array_walk($signupstatus, function ($data, $contextid) { $context = \context::instance_by_id($contextid); - array_walk($data, function($data, $attempt) use ($context) { + array_walk($data, function ($data, $attempt) use ($context) { writer::with_context($context)->export_related_data( [], 'signupstatus', - (object)['status' => $data] + (object) ['status' => $data] ); }); }); @@ -227,14 +226,12 @@ public static function export_user_data(approved_contextlist $contextlist) { writer::with_context($context)->export_related_data( [], 'trainer', - (object)['role' => $role->shortname] + (object) ['role' => $role->shortname] ); } $roles->close(); } - - /** * Delete all data for all users in the specified context. * @@ -248,7 +245,7 @@ public static function delete_data_for_all_users_in_context(\context $context) { } if ($cm = get_coursemodule_from_id('facetoface', $context->instanceid)) { - $params = array('fid' => $cm->instance); + $params = ['fid' => $cm->instance]; $f2fselect = "IN (SELECT s.id FROM {facetoface_sessions} s JOIN {facetoface} f ON f.id = s.facetoface WHERE f.id = :fid)"; @@ -278,13 +275,12 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { $userid = $contextlist->get_user()->id; foreach ($contextlist->get_contexts() as $context) { - if (!$context instanceof \context_module) { return; } if ($cm = get_coursemodule_from_id('facetoface', $context->instanceid)) { - $params = array('userid' => $userid, 'fid' => $cm->instance); + $params = ['userid' => $userid, 'fid' => $cm->instance]; $f2fselect = "IN (SELECT s.id FROM {facetoface_sessions} s JOIN {facetoface} f ON f.id = s.facetoface WHERE f.id = :fid)"; @@ -324,7 +320,7 @@ public static function get_users_in_context(userlist $userlist) { $params = [ 'contextlevel' => CONTEXT_MODULE, - 'contextid' => $context->id + 'contextid' => $context->id, ]; $userlist->add_from_sql('userid', $sql, $params); } @@ -345,12 +341,12 @@ public static function delete_data_for_users(approved_userlist $userlist) { $userids = $userlist->get_userids(); list ($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); - // Get session id from module id + // Get session id from module id. $sessionid = $DB->get_records_select( 'facetoface_sessions', "facetoface = :facetoface", [ - 'facetoface' => $cm->instance + 'facetoface' => $cm->instance, ] ); diff --git a/classes/search/activity.php b/classes/search/activity.php index c51d23d..7b9ffa4 100644 --- a/classes/search/activity.php +++ b/classes/search/activity.php @@ -24,8 +24,6 @@ namespace mod_facetoface\search; -defined('MOODLE_INTERNAL') || die(); - /** * Search area for mod_facetoface activities. * @@ -45,7 +43,7 @@ class activity extends \core_search\base_activity { * @param stdClass $record Post info. * @return \core_search\document */ - public function get_document($record, $options = array()) { + public function get_document($record, $options = []) { $doc = parent::get_document($record, $options); if (!$doc) { return false; diff --git a/classes/session.php b/classes/session.php index 7242495..7b6684c 100644 --- a/classes/session.php +++ b/classes/session.php @@ -19,8 +19,8 @@ /** * Helper class to get info about facetoface sessions. * - * It's not a ORM/persistent object for a session as it should be due to the age of the plugin, and the effort to retrofit sessions data - * into a class. + * It's not a ORM/persistent object for a session as it should be due to the + * age of the plugin, and the effort to retrofit sessions data into a class. * * @package mod_facetoface * @author Andrew Madden diff --git a/classes/session_form.php b/classes/session_form.php index f08d541..29ada7b 100644 --- a/classes/session_form.php +++ b/classes/session_form.php @@ -77,16 +77,16 @@ public function definition() { $mform->addHelpButton('custom_room', 'room', 'facetoface'); } - $formarray = array(); + $formarray = []; $formarray[] = $mform->createElement('selectyesno', 'datetimeknown', get_string('sessiondatetimeknown', 'facetoface')); $formarray[] = $mform->createElement('static', 'datetimeknownhint', '', - html_writer::tag('span', get_string('datetimeknownhinttext', 'facetoface'), array('class' => 'hint-text'))); - $mform->addGroup($formarray, 'datetimeknown_group', get_string('sessiondatetimeknown', 'facetoface'), array(' '), false); + html_writer::tag('span', get_string('datetimeknownhinttext', 'facetoface'), ['class' => 'hint-text'])); + $mform->addGroup($formarray, 'datetimeknown_group', get_string('sessiondatetimeknown', 'facetoface'), [' '], false); $mform->addGroupRule('datetimeknown_group', null, 'required', null, 'client'); $mform->setDefault('datetimeknown', false); $mform->addHelpButton('datetimeknown_group', 'sessiondatetimeknown', 'facetoface'); - $repeatarray = array(); + $repeatarray = []; $repeatarray[] = &$mform->createElement('hidden', 'sessiondateid', 0); $mform->setType('sessiondateid', PARAM_INT); $repeatarray[] = &$mform->createElement('date_time_selector', 'timestart', get_string('timestart', 'facetoface')); @@ -98,9 +98,9 @@ public function definition() { $repeatcount = $this->_customdata['nbdays']; - $repeatoptions = array(); - $repeatoptions['timestart']['disabledif'] = array('datetimeknown', 'eq', 0); - $repeatoptions['timefinish']['disabledif'] = array('datetimeknown', 'eq', 0); + $repeatoptions = []; + $repeatoptions['timestart']['disabledif'] = ['datetimeknown', 'eq', 0]; + $repeatoptions['timefinish']['disabledif'] = ['datetimeknown', 'eq', 0]; $mform->setType('timestart', PARAM_INT); $mform->setType('timefinish', PARAM_INT); @@ -127,20 +127,20 @@ public function definition() { $mform->addHelpButton('duration', 'duration', 'facetoface'); if (!get_config('facetoface', 'hidecost')) { - $formarray = array(); + $formarray = []; $formarray[] = $mform->createElement('text', 'normalcost', get_string('normalcost', 'facetoface'), 'size="5"'); $formarray[] = $mform->createElement('static', 'normalcosthint', '', html_writer::tag('span', - get_string('normalcosthinttext', 'facetoface'), array('class' => 'hint-text'))); - $mform->addGroup($formarray, 'normalcost_group', get_string('normalcost', 'facetoface'), array(' '), false); + get_string('normalcosthinttext', 'facetoface'), ['class' => 'hint-text'])); + $mform->addGroup($formarray, 'normalcost_group', get_string('normalcost', 'facetoface'), [' '], false); $mform->setType('normalcost', PARAM_TEXT); $mform->addHelpButton('normalcost_group', 'normalcost', 'facetoface'); if (!get_config('facetoface', 'hidediscount')) { - $formarray = array(); + $formarray = []; $formarray[] = $mform->createElement('text', 'discountcost', get_string('discountcost', 'facetoface'), 'size="5"'); $formarray[] = $mform->createElement('static', 'discountcosthint', '', html_writer::tag('span', - get_string('discountcosthinttext', 'facetoface'), array('class' => 'hint-text'))); - $mform->addGroup($formarray, 'discountcost_group', get_string('discountcost', 'facetoface'), array(' '), false); + get_string('discountcosthinttext', 'facetoface'), ['class' => 'hint-text'])); + $mform->addGroup($formarray, 'discountcost_group', get_string('discountcost', 'facetoface'), [' '], false); $mform->setType('discountcost', PARAM_TEXT); $mform->addHelpButton('discountcost_group', 'discountcost', 'facetoface'); } @@ -154,7 +154,6 @@ public function definition() { $rolenames = facetoface_get_trainer_roles(); if ($rolenames) { - // Get current trainers. $currenttrainers = facetoface_get_trainers($this->_customdata['s']); @@ -183,7 +182,7 @@ public function definition() { continue; } - $choices = array(); + $choices = []; foreach ($rs as $roleuser) { $choices[$roleuser->id] = fullname($roleuser); } @@ -199,7 +198,6 @@ public function definition() { if (count($choices) < 4) { $roleshown = false; foreach ($choices as $cid => $choice) { - // Only display the role title for the first checkbox for each role. if (!$roleshown) { $roledisplay = $rolename; @@ -209,19 +207,19 @@ public function definition() { } $mform->addElement('advcheckbox', 'trainerrole[' . $role . '][' . $cid . ']', $roledisplay, $choice, - null, array('', $cid)); + null, ['', $cid]); $mform->setType('trainerrole[' . $role . '][' . $cid . ']', PARAM_INT); } } else { $mform->addElement('select', 'trainerrole[' . $role . ']', $rolename, $choices, - array('multiple' => 'multiple')); + ['multiple' => 'multiple']); $mform->setType('trainerrole[' . $role . ']', PARAM_SEQUENCE); } // Select current trainers. if ($currenttrainers) { foreach ($currenttrainers as $role => $trainers) { - $t = array(); + $t = []; foreach ($trainers as $trainer) { $t[] = $trainer->id; $mform->setDefault('trainerrole[' . $role . '][' . $trainer->id . ']', $trainer->id); @@ -243,7 +241,7 @@ public function validation($data, $files) { for ($i = 0; $i < $dates; $i++) { $starttime = $data["timestart"][$i]; $endtime = $data["timefinish"][$i]; - $removecheckbox = empty($data["datedelete"]) ? array() : $data["datedelete"]; + $removecheckbox = empty($data["datedelete"]) ? [] : $data["datedelete"]; if ($starttime > $endtime && !isset($removecheckbox[$i])) { $errstr = get_string('error:sessionstartafterend', 'facetoface'); $errors['timestart'][$i] = $errstr; diff --git a/classes/signup_form.php b/classes/signup_form.php index da3f363..91d12a2 100644 --- a/classes/signup_form.php +++ b/classes/signup_form.php @@ -64,11 +64,11 @@ public function definition() { } $mform->setType('discountcode', PARAM_TEXT); - $options = array( + $options = [ MDL_F2F_BOTH => get_string('notificationboth', 'facetoface'), MDL_F2F_TEXT => get_string('notificationemail', 'facetoface'), - MDL_F2F_ICAL => get_string('notificationical', 'facetoface') - ); + MDL_F2F_ICAL => get_string('notificationical', 'facetoface'), + ]; $mform->addElement('select', 'notificationtype', get_string('notificationtype', 'facetoface'), $options); $mform->addHelpButton('notificationtype', 'notificationtype', 'facetoface'); $mform->addRule('notificationtype', null, 'required', null, 'client'); diff --git a/classes/sitenotice_form.php b/classes/sitenotice_form.php index a297c91..e911cde 100644 --- a/classes/sitenotice_form.php +++ b/classes/sitenotice_form.php @@ -47,7 +47,7 @@ public function definition() { $mform->addRule('name', null, 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); - $mform->addElement('editor', 'text', get_string('noticetext', 'facetoface'), array('rows' => 10, 'cols' => 64)); + $mform->addElement('editor', 'text', get_string('noticetext', 'facetoface'), ['rows' => 10, 'cols' => 64]); $mform->setType('text', PARAM_RAW); $mform->addRule('text', null, 'required', null, 'client'); diff --git a/classes/task/cron_task.php b/classes/task/cron_task.php index d2a22f9..d158186 100644 --- a/classes/task/cron_task.php +++ b/classes/task/cron_task.php @@ -30,8 +30,6 @@ namespace mod_facetoface\task; -defined('MOODLE_INTERNAL') || die(); - class cron_task extends \core\task\scheduled_task { /** diff --git a/customfield.php b/customfield.php index b9d7b94..991bb22 100644 --- a/customfield.php +++ b/customfield.php @@ -32,17 +32,17 @@ require_once($CFG->libdir . '/adminlib.php'); $id = required_param('id', PARAM_INT); // ID in facetoface_session_field. -$d = optional_param('d', false, PARAM_BOOL); // set to true to delete the given field. -$confirm = optional_param('confirm', false, PARAM_BOOL); // delete confirmationx. +$d = optional_param('d', false, PARAM_BOOL); // Set to true to delete the given field. +$confirm = optional_param('confirm', false, PARAM_BOOL); // Delete confirmationx. $field = null; if ($id > 0) { - if (!$field = $DB->get_record('facetoface_session_field', array('id' => $id))) { + if (!$field = $DB->get_record('facetoface_session_field', ['id' => $id])) { throw new moodle_exception('error:fieldidincorrect', 'facetoface', '', $id); } } -$PAGE->set_url('/mod/facetoface/customfield.php', array('id' => $id, 'd' => $d, 'confirm' => $confirm)); +$PAGE->set_url('/mod/facetoface/customfield.php', ['id' => $id, 'd' => $d, 'confirm' => $confirm]); admin_externalpage_setup('managemodules'); // This is hacky, there should be a special hidden page for it. @@ -70,7 +70,7 @@ if (!$confirm) { echo $OUTPUT->header(); echo $OUTPUT->heading($title); - $optionsyes = array('id' => $id, 'sesskey' => $USER->sesskey, 'd' => 1, 'confirm' => 1); + $optionsyes = ['id' => $id, 'sesskey' => $USER->sesskey, 'd' => 1, 'confirm' => 1]; echo $OUTPUT->confirm(get_string('fielddeleteconfirm', 'facetoface', format_string($field->name)), new moodle_url("customfield.php", $optionsyes), new moodle_url($returnurl)); @@ -80,11 +80,11 @@ $transaction = $DB->start_delegated_transaction(); try { - if (!$DB->delete_records('facetoface_session_field', array('id' => $id))) { + if (!$DB->delete_records('facetoface_session_field', ['id' => $id])) { throw new Exception(get_string('error:couldnotdeletefield', 'facetoface')); } - if (!$DB->delete_records('facetoface_session_data', array('fieldid' => $id))) { + if (!$DB->delete_records('facetoface_session_data', ['fieldid' => $id])) { throw new Exception(get_string('error:couldnotdeletefield', 'facetoface')); } @@ -103,7 +103,6 @@ } if ($fromform = $mform->get_data()) { // Form submitted. - if (empty($fromform->submitbutton)) { throw new moodle_exception('error:unknownbuttonclicked', 'facetoface', $returnurl); } @@ -123,7 +122,7 @@ } $valueslist = explode("\n", trim($fromform->possiblevalues)); - $posvals = array(); + $posvals = []; foreach ($valueslist as $val) { $trimmedval = trim($val); if (strlen($trimmedval) != 0) { @@ -154,7 +153,6 @@ redirect($returnurl); } else if ($field != null) { // Edit mode. - // Set values for the form. $toform = new stdClass(); $toform->name = $field->name; diff --git a/db/access.php b/db/access.php index 77f8eba..f4cad23 100644 --- a/db/access.php +++ b/db/access.php @@ -30,152 +30,152 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ // Ability to see that the activity exists, and the basic information about its sessions. - 'mod/facetoface:view' => array( + 'mod/facetoface:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'guest' => CAP_ALLOW, 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to signup for a session. - 'mod/facetoface:signup' => array( + 'mod/facetoface:signup' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to see activities for which no sessions have been added. - 'mod/facetoface:viewemptyactivities' => array( + 'mod/facetoface:viewemptyactivities' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to see how many people have signed up for a session. - 'mod/facetoface:viewattendees' => array( + 'mod/facetoface:viewattendees' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to take attendance. - 'mod/facetoface:takeattendance' => array( + 'mod/facetoface:takeattendance' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to add attendees to a session. - 'mod/facetoface:addattendees' => array( + 'mod/facetoface:addattendees' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to remove attendees from a session. - 'mod/facetoface:removeattendees' => array( + 'mod/facetoface:removeattendees' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to add, edit, copy and delete a session. - 'mod/facetoface:editsessions' => array( + 'mod/facetoface:editsessions' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], // View session cancellations. - 'mod/facetoface:viewcancellations' => array( + 'mod/facetoface:viewcancellations' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - ), + 'manager' => CAP_ALLOW, + ], + ], // Allow the configuration of sign-up cancellations, upon adding/editing a face-to-face activity. - 'mod/facetoface:configurecancellation' => array( + 'mod/facetoface:configurecancellation' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to overbook a session by signing up for it. // Users with mod/facetoface:addattendees can also overbook. - 'mod/facetoface:overbook' => array( + 'mod/facetoface:overbook' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to add a new facetoface activity to a course. - 'mod/facetoface:addinstance' => array( + 'mod/facetoface:addinstance' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - ), + 'manager' => CAP_ALLOW, + ], + ], // Ability to create site-wide events. 'mod/facetoface:createsitewideevent' => [ @@ -183,7 +183,17 @@ 'contextlevel' => CONTEXT_COURSE, 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ] - ] -); + 'manager' => CAP_ALLOW, + ], + ], + + // Ability to upload and process bookings via CSV. + 'mod/facetoface:uploadbookings' => [ + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => [ + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW, + ], + ], +]; diff --git a/db/events.php b/db/events.php index 054f4a3..23b99fa 100644 --- a/db/events.php +++ b/db/events.php @@ -31,9 +31,9 @@ defined('MOODLE_INTERNAL') || die(); // List of observers. -$observers = array( - array( +$observers = [ + [ 'eventname' => '\core\event\user_enrolment_deleted', 'callback' => 'mod_facetoface_observer::user_enrolment_deleted', - ), -); + ], +]; diff --git a/db/log.php b/db/log.php index f780e4f..abcd800 100644 --- a/db/log.php +++ b/db/log.php @@ -30,19 +30,19 @@ defined('MOODLE_INTERNAL') || die(); -$logs = array( - array('module' => 'facetoface', 'action' => 'add', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'delete', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'update', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'view', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'view all', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'add session', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'copy session', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'delete session', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'update session', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'view session', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'view attendees', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'take attendance', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'signup', 'mtable' => 'facetoface', 'field' => 'name'), - array('module' => 'facetoface', 'action' => 'cancel', 'mtable' => 'facetoface', 'field' => 'name'), -); +$logs = [ + ['module' => 'facetoface', 'action' => 'add', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'delete', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'update', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'view', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'view all', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'add session', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'copy session', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'delete session', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'update session', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'view session', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'view attendees', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'take attendance', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'signup', 'mtable' => 'facetoface', 'field' => 'name'], + ['module' => 'facetoface', 'action' => 'cancel', 'mtable' => 'facetoface', 'field' => 'name'], +]; diff --git a/db/tasks.php b/db/tasks.php index bdb7af2..61bd15f 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -30,14 +30,14 @@ defined('MOODLE_INTERNAL') || die(); -$tasks = array( - array( +$tasks = [ + [ 'classname' => 'mod_facetoface\task\cron_task', 'blocking' => 0, 'minute' => '*', 'hour' => '1', 'day' => '*', 'month' => '*', - 'dayofweek' => '*' - ) -); + 'dayofweek' => '*', + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 4caa565..1981038 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -28,10 +28,7 @@ * @author Francois Marier */ -defined('MOODLE_INTERNAL') || die(); - /** - * * Sends message to administrator listing all updated * duplicate custom fields * @param array $data @@ -45,11 +42,11 @@ function facetoface_send_admin_upgrade_msg($data) { } $table = new html_table(); - $table->head = array(get_string('customfieldid', 'mod_facetoface'), + $table->head = [get_string('customfieldid', 'mod_facetoface'), get_string('customfieldoriginalshortname', 'mod_facetoface'), - get_string('customfieldnewshortname', 'mod_facetoface')); + get_string('customfieldnewshortname', 'mod_facetoface'), ]; $table->data = $data; - $table->align = array ('center', 'center', 'center'); + $table->align = ['center', 'center', 'center']; $title = get_string('upgradeinfofacetoface', 'mod_facetoface', $SITE->fullname); $note = get_string('noteinfo', 'mod_facetoface'); @@ -177,7 +174,7 @@ function xmldb_facetoface_upgrade($oldversion=0) { $table1->add_field('defaultvalue', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table1->add_field('isfilter', XMLDB_TYPE_INTEGER, '1', true, XMLDB_NOTNULL, null, '1'); $table1->add_field('showinsummary', XMLDB_TYPE_INTEGER, '1', true, XMLDB_NOTNULL, null, '1'); - $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table1->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); $result = $result && $dbman->create_table($table1); $table2 = new xmldb_table('facetoface_session_data'); @@ -185,7 +182,7 @@ function xmldb_facetoface_upgrade($oldversion=0) { $table2->add_field('fieldid', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, '0'); $table2->add_field('sessionid', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, '0'); $table2->add_field('data', XMLDB_TYPE_CHAR, '255', null, null, null, null); - $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table2->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); $result = $result && $dbman->create_table($table2); } @@ -233,7 +230,7 @@ function xmldb_facetoface_upgrade($oldversion=0) { $olddebug = $DB->debug; $DB->debug = false; // Too much debug output. - if ($rs = $DB->get_recordset('facetoface_sessions', array(), '', 'id, location, venue, room')) { + if ($rs = $DB->get_recordset('facetoface_sessions', [], '', 'id, location, venue, room')) { foreach ($rs as $session) { $locationdata = new stdClass(); $locationdata->sessionid = $session->id; @@ -275,12 +272,12 @@ function xmldb_facetoface_upgrade($oldversion=0) { $olddebug = $DB->debug; $DB->debug = false; // Too much debug output. - $templatedfields = array('confirmationsubject', 'confirmationinstrmngr', 'confirmationmessage', + $templatedfields = ['confirmationsubject', 'confirmationinstrmngr', 'confirmationmessage', 'cancellationsubject', 'cancellationinstrmngr', 'cancellationmessage', 'remindersubject', 'reminderinstrmngr', 'remindermessage', - 'waitlistedsubject', 'waitlistedmessage'); + 'waitlistedsubject', 'waitlistedmessage', ]; - if ($rs = $DB->get_recordset('facetoface', array(), '', 'id, ' . implode(', ', $templatedfields))) { + if ($rs = $DB->get_recordset('facetoface', [], '', 'id, ' . implode(', ', $templatedfields))) { foreach ($rs as $activity) { $todb = new stdClass(); $todb->id = $activity->id; @@ -312,8 +309,7 @@ function xmldb_facetoface_upgrade($oldversion=0) { foreach ($records as $record) { if (!facetoface_remove_session_from_calendar($record, SITEID)) { $result = false; - throw new Exception('Could not remove session from site calendar'); - break; + throw new \Exception('Could not remove session from site calendar'); } } @@ -324,8 +320,7 @@ function xmldb_facetoface_upgrade($oldversion=0) { if (!facetoface_add_session_to_calendar($session, $facetoface, 'site')) { $result = false; - throw new Exception('Could not add session to site calendar'); - break; + throw new \Exception('Could not add session to site calendar'); } } } @@ -343,8 +338,8 @@ function xmldb_facetoface_upgrade($oldversion=0) { $table->add_field('sessionid', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, null); $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, null); - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('sessionid', XMLDB_KEY_FOREIGN, array('sessionid'), 'facetoface_sessions', array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('sessionid', XMLDB_KEY_FOREIGN, ['sessionid'], 'facetoface_sessions', ['id']); $result = $result && $dbman->create_table($table); // Create table facetoface_signups. @@ -355,8 +350,8 @@ function xmldb_facetoface_upgrade($oldversion=0) { $table->add_field('mailedreminder', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, null); $table->add_field('discountcode', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('notificationtype', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, null); - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('sessionid', XMLDB_KEY_FOREIGN, array('sessionid'), 'facetoface_sessions', array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('sessionid', XMLDB_KEY_FOREIGN, ['sessionid'], 'facetoface_sessions', ['id']); $result = $result && $dbman->create_table($table); // Create table facetoface_signups_status. @@ -369,8 +364,8 @@ function xmldb_facetoface_upgrade($oldversion=0) { $table->add_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, '0'); $table->add_field('note', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, null); - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table->add_key('signupid', XMLDB_KEY_FOREIGN, array('signupid'), 'facetoface_signups', array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table->add_key('signupid', XMLDB_KEY_FOREIGN, ['signupid'], 'facetoface_signups', ['id']); $result = $result && $dbman->create_table($table); // Migrate submissions to signups. @@ -519,7 +514,7 @@ function xmldb_facetoface_upgrade($oldversion=0) { $table1->add_field('id', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table1->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table1->add_field('text', XMLDB_TYPE_TEXT, 'medium', null, null, null, null); - $table1->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table1->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); $result = $result && $dbman->create_table($table1); $table2 = new xmldb_table('facetoface_notice_data'); @@ -527,8 +522,8 @@ function xmldb_facetoface_upgrade($oldversion=0) { $table2->add_field('fieldid', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, '0'); $table2->add_field('noticeid', XMLDB_TYPE_INTEGER, '10', true, XMLDB_NOTNULL, null, '0'); $table2->add_field('data', XMLDB_TYPE_CHAR, '255', null, null, null, null); - $table2->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); - $table2->add_index('facetoface_notice_date_fieldid', XMLDB_INDEX_NOTUNIQUE, array('fieldid')); + $table2->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); + $table2->add_index('facetoface_notice_date_fieldid', XMLDB_INDEX_NOTUNIQUE, ['fieldid']); $result = $result && $dbman->create_table($table2); } @@ -606,55 +601,53 @@ function xmldb_facetoface_upgrade($oldversion=0) { if ($oldversion < 2011120702) { $table = new xmldb_table('facetoface_session_field'); $index = new xmldb_index('ind_session_field_unique'); - $index->set_attributes(XMLDB_INDEX_UNIQUE, array('shortname')); + $index->set_attributes(XMLDB_INDEX_UNIQUE, ['shortname']); - if ($dbman->table_exists($table)) { + // Do we need to check for duplicates? + if ($dbman->table_exists($table) + && !$dbman->index_exists($table, $index)) { - // Do we need to check for duplicates? - if (!$dbman->index_exists($table, $index)) { - - // Check for duplicate records and make them unique. - $replacements = array(); - - $transaction = $DB->start_delegated_transaction(); - - $sql = 'SELECT - l.id, - l.shortname - FROM - {facetoface_session_field} l, - ( SELECT - MIN(id) AS id, - shortname - FROM - {facetoface_session_field} - GROUP BY - shortname - HAVING COUNT(*)>1 - ) a - WHERE - l.id<>a.id - AND l.shortname = a.shortname - '; - $rs = $DB->get_recordset_sql($sql, null); - - if ($rs !== false) { - foreach ($rs as $item) { - $data = (object)$item; - - // Randomize the value. - $data->shortname = $DB->escape($data->shortname.'_'.$data->id); - $DB->update_record('facetoface_session_field', $data); - $replacements[] = array($item['id'], $item['shortname'], $data->shortname); - } - } + // Check for duplicate records and make them unique. + $replacements = []; - $transaction->allow_commit(); - facetoface_send_admin_upgrade_msg($replacements); + $transaction = $DB->start_delegated_transaction(); - // Apply the index. - $dbman->add_index($table, $index); + $sql = 'SELECT + l.id, + l.shortname + FROM + {facetoface_session_field} l, + ( SELECT + MIN(id) AS id, + shortname + FROM + {facetoface_session_field} + GROUP BY + shortname + HAVING COUNT(*)>1 + ) a + WHERE + l.id<>a.id + AND l.shortname = a.shortname + '; + $rs = $DB->get_recordset_sql($sql, null); + + if ($rs !== false) { + foreach ($rs as $item) { + $data = (object)$item; + + // Randomize the value. + $data->shortname = $DB->escape($data->shortname.'_'.$data->id); + $DB->update_record('facetoface_session_field', $data); + $replacements[] = [$item['id'], $item['shortname'], $data->shortname]; + } } + + $transaction->allow_commit(); + facetoface_send_admin_upgrade_msg($replacements); + + // Apply the index. + $dbman->add_index($table, $index); } upgrade_mod_savepoint(true, 2011120702, 'facetoface'); @@ -709,7 +702,7 @@ function xmldb_facetoface_upgrade($oldversion=0) { $sql = 'UPDATE {facetoface} SET showoncalendar = ? WHERE showoncalendar = ?'; - $DB->execute($sql, array(F2F_CAL_SITE, F2F_CAL_COURSE)); + $DB->execute($sql, [F2F_CAL_SITE, F2F_CAL_COURSE]); $f2f = $DB->get_records('facetoface'); foreach ($f2f as $facetoface) { @@ -723,7 +716,16 @@ function xmldb_facetoface_upgrade($oldversion=0) { // Define field allowcancellationsdefault to be added to facetoface. $table = new xmldb_table('facetoface'); - $field = new xmldb_field('allowcancellationsdefault', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'usercalentry'); + $field = new xmldb_field( + 'allowcancellationsdefault', + XMLDB_TYPE_INTEGER, + '1', + null, + XMLDB_NOTNULL, + null, + '1', + 'usercalentry' + ); // Conditionally launch add field allowcancellationsdefault. if (!$dbman->field_exists($table, $field)) { @@ -747,7 +749,16 @@ function xmldb_facetoface_upgrade($oldversion=0) { // Define field confirmationmessageformat to be added to facetoface. $table = new xmldb_table('facetoface'); - $field = new xmldb_field('confirmationmessageformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'confirmationmessage'); + $field = new xmldb_field( + 'confirmationmessageformat', + XMLDB_TYPE_INTEGER, + '2', + null, + XMLDB_NOTNULL, + null, + '0', + 'confirmationmessage' + ); // Conditionally launch add field confirmationmessageformat. if (!$dbman->field_exists($table, $field)) { @@ -760,7 +771,16 @@ function xmldb_facetoface_upgrade($oldversion=0) { if ($oldversion < 2022091900) { $table = new xmldb_table('facetoface'); - $field = new xmldb_field('signuptype', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'allowcancellationsdefault'); + $field = new xmldb_field( + 'signuptype', + XMLDB_TYPE_INTEGER, + '10', + null, + XMLDB_NOTNULL, + null, + '0', + 'allowcancellationsdefault' + ); // Conditionally launch add field signuptype. if (!$dbman->field_exists($table, $field)) { @@ -819,7 +839,16 @@ function xmldb_facetoface_upgrade($oldversion=0) { // Define field completionattendance to be added to facetoface. $table = new xmldb_table('facetoface'); - $field = new xmldb_field('completionattendance', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'multiplesignupmethod'); + $field = new xmldb_field( + 'completionattendance', + XMLDB_TYPE_INTEGER, + '10', + null, + XMLDB_NOTNULL, + null, + '0', + 'multiplesignupmethod' + ); // Conditionally launch add field completionattendance. if (!$dbman->field_exists($table, $field)) { diff --git a/editattendees.php b/editattendees.php index 30dc02d..00058ae 100644 --- a/editattendees.php +++ b/editattendees.php @@ -46,10 +46,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)) { @@ -68,11 +68,18 @@ $strfacetofaces = get_string('modulenameplural', 'facetoface'); $strfacetoface = get_string('modulename', 'facetoface'); -$errors = array(); +$errors = []; // Get the user_selector we will need. -$potentialuserselector = new facetoface_candidate_selector('addselect', array('sessionid' => $session->id, 'courseid' => $course->id, 'accesscontext' => $context)); -$existinguserselector = new facetoface_existing_selector('removeselect', array('sessionid' => $session->id, 'accesscontext' => $context)); +$potentialuserselector = new facetoface_candidate_selector('addselect', [ + 'sessionid' => $session->id, + 'courseid' => $course->id, + 'accesscontext' => $context, +]); +$existinguserselector = new facetoface_existing_selector('removeselect', [ + 'sessionid' => $session->id, + 'accesscontext' => $context, +]); // Process incoming user assignments. if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { @@ -86,12 +93,12 @@ // Make sure that the user is enroled in the course. if (!has_capability('moodle/course:view', $context, $adduser)) { - $user = $DB->get_record('user', array('id' => $adduser)); + $user = $DB->get_record('user', ['id' => $adduser]); // Make sure that the user is enroled in the course. if (!is_enrolled($context, $user)) { $defaultroleid = null; // Get default role ID for manual enrollment. - $conditions = array ('courseid' => $course->id, 'enrol' => 'manual'); + $conditions = ['courseid' => $course->id, 'enrol' => 'manual']; $defaultroleid = $DB->get_field('enrol', 'roleid', $conditions, IGNORE_MISSING); if (!enrol_try_internal_enrol($course->id, $user->id, $defaultroleid)) { $errors[] = get_string('error:enrolmentfailed', 'facetoface', fullname($user)); @@ -102,8 +109,9 @@ } $usernamefields = facetoface_get_all_user_name_fields(true); - if (facetoface_get_user_submissions($facetoface->id, $adduser) && $facetoface->signuptype != MOD_FACETOFACE_SIGNUP_MULTIPLE) { - $erruser = $DB->get_record('user', array('id' => $adduser), "id, {$usernamefields}"); + if (facetoface_get_user_submissions($facetoface->id, $adduser) + && $facetoface->signuptype != MOD_FACETOFACE_SIGNUP_MULTIPLE) { + $erruser = $DB->get_record('user', ['id' => $adduser], "id, {$usernamefields}"); $errors[] = get_string('error:addalreadysignedupattendee', 'facetoface', fullname($erruser)); } else { $now = time(); @@ -123,7 +131,7 @@ } if (!facetoface_user_signup($session, $facetoface, $course, '', MDL_F2F_BOTH, $status, $adduser, !$suppressemail)) { - $erruser = $DB->get_record('user', array('id' => $adduser), "id, {$usernamefields}"); + $erruser = $DB->get_record('user', ['id' => $adduser], "id, {$usernamefields}"); $errors[] = get_string('error:addattendee', 'facetoface', fullname($erruser)); } } @@ -145,16 +153,15 @@ } if (facetoface_user_cancel($session, $removeuser, true, $cancelerr)) { - // Notify the user of the cancellation if the session hasn't started yet. $timenow = time(); - if (!$suppressemail and !facetoface_has_session_started($session, $timenow)) { + if (!$suppressemail && !facetoface_has_session_started($session, $timenow)) { facetoface_send_cancellation_notice($facetoface, $session, $removeuser); } } else { $errors[] = $cancelerr; $usernamefields = facetoface_get_all_user_name_fields(true); - $erruser = $DB->get_record('user', array('id' => $removeuser), "id, {$usernamefields}"); + $erruser = $DB->get_record('user', ['id' => $removeuser], "id, {$usernamefields}"); $errors[] = get_string('error:removeattendee', 'facetoface', fullname($erruser)); } } @@ -170,7 +177,7 @@ $pagetitle = format_string($facetoface->name); $PAGE->set_cm($cm); -$PAGE->set_url('/mod/facetoface/editattendees.php', array('s' => $s, 'backtoallsessions' => $backtoallsessions)); +$PAGE->set_url('/mod/facetoface/editattendees.php', ['s' => $s, 'backtoallsessions' => $backtoallsessions]); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); @@ -180,15 +187,15 @@ echo $OUTPUT->heading(get_string('addremoveattendees', 'facetoface')); // Create user_selector form. -$out = html_writer::start_tag('form', array('id' => 'assignform', 'method' => 'post', 'action' => $PAGE->url)); +$out = html_writer::start_tag('form', ['id' => 'assignform', 'method' => 'post', 'action' => $PAGE->url]); $out .= html_writer::start_tag('div'); -$out .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => "previoussearch", 'value' => $previoussearch)); -$out .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => "backtoallsessions", 'value' => $backtoallsessions)); -$out .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => "sesskey", 'value' => sesskey())); +$out .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => "previoussearch", 'value' => $previoussearch]); +$out .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => "backtoallsessions", 'value' => $backtoallsessions]); +$out .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => "sesskey", 'value' => sesskey()]); $table = new html_table(); $table->attributes['class'] = "generaltable generalbox boxaligncenter"; -$cells = array(); +$cells = []; if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_MULTIPLE) { $content = html_writer::checkbox( @@ -196,39 +203,43 @@ 1, 0, get_string('addtoallsessions', 'facetoface'), - array('id' => 'addtoallsessions') + ['id' => 'addtoallsessions'] ); $content .= $OUTPUT->help_icon('addtoallsessions', 'facetoface'); $cell = new html_table_cell($content); $cell->attributes['colspan'] = '3'; - $table->data[] = new html_table_row(array($cell)); + $table->data[] = new html_table_row([$cell]); } $content = html_writer::checkbox('suppressemail', 1, 0, get_string('suppressemail', 'facetoface'), - array('id' => 'suppressemail')); + ['id' => 'suppressemail']); $content .= $OUTPUT->help_icon('suppressemail', 'facetoface'); $cell = new html_table_cell($content); $cell->attributes['id'] = 'backcell'; $cell->attributes['colspan'] = '3'; -$table->data[] = new html_table_row(array($cell)); +$table->data[] = new html_table_row([$cell]); $content = html_writer::start_tag('p') . html_writer::tag('label', get_string('attendees', 'facetoface'), - array('for' => 'removeselect')) . html_writer::end_tag('p'); + ['for' => 'removeselect']) . html_writer::end_tag('p'); $content .= $existinguserselector->display(true); $cell = new html_table_cell($content); $cell->attributes['id'] = 'existingcell'; $cells[] = $cell; $content = html_writer::tag('div', html_writer::empty_tag('input', - array('type' => 'submit', 'id' => 'add', 'name' => 'add', 'title' => get_string('add'), - 'value' => $OUTPUT->larrow().' '.get_string('add'))), array('id' => 'addcontrols')); + [ + 'type' => 'submit', 'id' => 'add', 'name' => 'add', 'title' => get_string('add'), + 'value' => $OUTPUT->larrow().' '.get_string('add'), +]), ['id' => 'addcontrols']); $content .= html_writer::tag('div', html_writer::empty_tag('input', - array('type' => 'submit', 'id' => 'remove', 'name' => 'remove', 'title' => get_string('remove'), - 'value' => $OUTPUT->rarrow().' '.get_string('remove'))), array('id' => 'removecontrols')); + [ + 'type' => 'submit', 'id' => 'remove', 'name' => 'remove', 'title' => get_string('remove'), + 'value' => $OUTPUT->rarrow().' '.get_string('remove'), +]), ['id' => 'removecontrols']); $cell = new html_table_cell($content); $cell->attributes['id'] = 'buttonscell'; $cells[] = $cell; $content = html_writer::start_tag('p') . html_writer::tag('label', - get_string('potentialattendees', 'facetoface'), array('for' => 'addselect')) . html_writer::end_tag('p'); + get_string('potentialattendees', 'facetoface'), ['for' => 'addselect']) . html_writer::end_tag('p'); $content .= $potentialuserselector->display(true); $cell = new html_table_cell($content); $cell->attributes['id'] = 'potentialcell'; @@ -262,13 +273,13 @@ AND ss.superceded != 1 AND ss.statuscode = ? ORDER BY - u.lastname, u.firstname", array($session->id, MDL_F2F_STATUS_REQUESTED) + u.lastname, u.firstname", [$session->id, MDL_F2F_STATUS_REQUESTED] ); $table = new html_table(); -$table->head = array(get_string('name'), get_string('email'), get_string('status')); +$table->head = [get_string('name'), get_string('email'), get_string('status')]; foreach ($nonattendeesrs as $user) { - $data = array(); + $data = []; $data[] = new html_table_cell(fullname($user)); $data[] = new html_table_cell($user->email); $data[] = new html_table_cell(get_string('status_' . facetoface_get_status($user->statuscode), 'facetoface')); @@ -300,7 +311,7 @@ // Bottom of the page links. echo html_writer::start_tag('p'); -$url = new moodle_url('/mod/facetoface/attendees.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions)); +$url = new moodle_url('/mod/facetoface/attendees.php', ['s' => $session->id, 'backtoallsessions' => $backtoallsessions]); echo html_writer::link($url, get_string('goback', 'facetoface')); echo html_writer::end_tag('p'); echo $OUTPUT->box_end(); diff --git a/example.csv b/example.csv new file mode 100644 index 0000000..b5abd49 --- /dev/null +++ b/example.csv @@ -0,0 +1,5 @@ +email,session,status,discountcode,notificationtype +student1@example.com,1,booked,ORDER66,ical +student2@example.com,2,cancelled,, +student3@example.com,3,booked,, +student4@example.com,4,,, diff --git a/index.php b/index.php index a0dab5d..f35fd73 100644 --- a/index.php +++ b/index.php @@ -33,7 +33,7 @@ $id = required_param('id', PARAM_INT); // Course Module ID. -if (!$course = $DB->get_record('course', array('id' => $id))) { +if (!$course = $DB->get_record('course', ['id' => $id])) { throw new moodle_exception('error:coursemisconfigured', 'facetoface'); } @@ -42,10 +42,10 @@ require_capability('mod/facetoface:view', $context); // Logging and events trigger. -$params = array( +$params = [ 'context' => $context, - 'objectid' => $course->id -); + 'objectid' => $course->id, +]; $event = \mod_facetoface\event\course_viewed::create($params); $event->add_record_snapshot('course', $course); $event->trigger(); @@ -60,7 +60,7 @@ $pagetitle = format_string($strfacetofaces); -$PAGE->set_url('/mod/facetoface/index.php', array('id' => $id)); +$PAGE->set_url('/mod/facetoface/index.php', ['id' => $id]); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); @@ -77,31 +77,30 @@ $table = new html_table(); if ($course->format == 'weeks' && has_capability('mod/facetoface:viewattendees', $context)) { - $table->head = array ($strweek, $strfacetofacename, get_string('sign-ups', 'facetoface')); - $table->align = array ('center', 'left', 'center'); + $table->head = [$strweek, $strfacetofacename, get_string('sign-ups', 'facetoface')]; + $table->align = ['center', 'left', 'center']; } else if ($course->format == 'weeks') { - $table->head = array ($strweek, $strfacetofacename); - $table->align = array ('center', 'left', 'center', 'center'); + $table->head = [$strweek, $strfacetofacename]; + $table->align = ['center', 'left', 'center', 'center']; } else if ($course->format == 'topics' && has_capability('mod/facetoface:viewattendees', $context)) { - $table->head = array ($strcourse, $strfacetofacename, get_string('sign-ups', 'facetoface')); - $table->align = array ('center', 'left', 'center'); + $table->head = [$strcourse, $strfacetofacename, get_string('sign-ups', 'facetoface')]; + $table->align = ['center', 'left', 'center']; } else if ($course->format == 'topics') { - $table->head = array ($strcourse, $strfacetofacename); - $table->align = array ('center', 'left', 'center', 'center'); + $table->head = [$strcourse, $strfacetofacename]; + $table->align = ['center', 'left', 'center', 'center']; } else { - $table->head = array ($strfacetofacename); - $table->align = array ('left', 'left'); + $table->head = [$strfacetofacename]; + $table->align = ['left', 'left']; } $currentsection = ''; foreach ($facetofaces as $facetoface) { - $submitted = get_string('no'); if (!$facetoface->visible) { // Show dimmed if the mod is hidden. - $link = html_writer::link("view.php?f=$facetoface->id", format_string($facetoface->name), array('class' => 'dimmed')); + $link = html_writer::link("view.php?f=$facetoface->id", format_string($facetoface->name), ['class' => 'dimmed']); } else { // Show normal if the mod is visible. $link = html_writer::link("view.php?f=$facetoface->id", format_string($facetoface->name)); @@ -124,16 +123,16 @@ } } } - $url = new moodle_url('/course/view.php', array('id' => $course->id)); - $courselink = html_writer::link($url, $course->shortname, array('title' => $course->shortname)); - if ($course->format == 'weeks' or $course->format == 'topics') { + $url = new moodle_url('/course/view.php', ['id' => $course->id]); + $courselink = html_writer::link($url, $course->shortname, ['title' => $course->shortname]); + if ($course->format == 'weeks' || $course->format == 'topics') { if (has_capability('mod/facetoface:viewattendees', $context)) { - $table->data[] = array ($courselink, $link, $totalsignupcount); + $table->data[] = [$courselink, $link, $totalsignupcount]; } else { - $table->data[] = array ($courselink, $link); + $table->data[] = [$courselink, $link]; } } else { - $table->data[] = array ($link, $submitted); + $table->data[] = [$link, $submitted]; } } diff --git a/lang/en/facetoface.php b/lang/en/facetoface.php index ec7417a..193100d 100644 --- a/lang/en/facetoface.php +++ b/lang/en/facetoface.php @@ -142,6 +142,16 @@ $string['email:subject'] = 'Subject'; $string['emptylocation'] = 'Location was empty'; $string['enrolled'] = 'enrolled'; +$string['error:invalidstatusspecified'] = "Invalid status specified. Expecting 'booked' or 'cancelled', defaults to 'booked' if empty. Value provided was '{\$a}'"; +$string['error:invalidnotificationtypespecified'] = "Invalid notification type specified. Expecting 'ical', 'email', 'both', or '', but actual was '{\$a}'"; +$string['error:sessionalreadystarted'] = 'Unable to use session {$a}, as it which has already started.'; +$string['error:userisnotenrolledintocourse'] = 'User {$a} is not enrolled into this course.'; +$string['error:bookingsuploadfileerrorsfound'] = '{$a} errors were found in the uploaded file. Bookings cannot be processed until they are resolved.'; +$string['error:bookingsuploadfileheaderfieldmismatch'] = 'Mismatched number of fields in the uploaded file on row {$a}.'; +$string['error:sessionoverbooked'] = 'Session ID {$a->session} overbooked by {$a->amount} person(s).'; +$string['error:sessiondoesnotexist'] = 'Session ID {$a} does not exist'; +$string['error:userdoesnotexist'] = 'User {$a} does not exist'; +$string['error:multipleusersmatched'] = 'Multiple users matched to identifier {$a}'; $string['error:addalreadysignedupattendee'] = '{$a} is already signed-up for this Face-to-Face activity.'; $string['error:addattendee'] = 'Could not add {$a} to the session.'; $string['error:cancellationsnotallowed'] = 'You are not allowed to cancel this sign-up.'; @@ -154,6 +164,7 @@ $string['error:cannotsendrequestuser'] = 'There was a problem sending the signup request message to your email account.'; $string['error:cannotsendrequestmanager'] = 'There was a problem sending the signup request message to your manager\'s email account.'; $string['error:cannotsendconfirmationusermanager'] = 'A confirmation message could not be sent to your email address and to your manager\'s email address.'; +$string['error:cannotprocessbookingsvalidationerrorsexist'] = 'There are validation errors that need to be addressed before the file can be fully processed. Please fix them and try again.'; $string['error:canttakeattendanceforunstartedsession'] = 'Can not take attendance for a session that has yet to start.'; $string['error:couldnotaddfield'] = 'Could not add custom session field.'; $string['error:couldnotaddnotice'] = 'Could not add site notice.'; @@ -203,8 +214,8 @@ $string['exporttofile'] = 'Export to file'; $string['exportattendance'] = 'Export attendance'; $string['facetoface'] = 'Face-to-Face'; -$string['facetoface:addinstance'] = 'Add instance'; $string['facetoface:addattendees'] = 'Add attendees to a Face-to-Face session'; +$string['facetoface:addinstance'] = 'Add instance'; $string['facetoface:configurecancellation'] = 'Allow the configuration of sign-up cancellations, upon adding/editing a face-to-face activity.'; $string['facetoface:createsitewideevent'] = 'Allow creation of site wide calendar events'; $string['facetoface:editsessions'] = 'Add, edit, copy and delete Face-to-Face sessions'; @@ -212,6 +223,22 @@ $string['facetoface:removeattendees'] = 'Remove attendees from a Face-to-Face session'; $string['facetoface:signup'] = 'Sign-up for a session'; $string['facetoface:takeattendance'] = 'Take attendance'; +$string['facetoface:examplecsv'] = 'Example text file'; +$string['facetoface:csvprocessed'] = 'Successfully processed records.'; +$string['facetoface:uploadbookings'] = 'Upload bookings'; +$string['facetoface:validatebookings'] = 'Validate bookings'; +$string['facetoface:confirmandprocess'] = 'Confirm and process'; +$string['facetoface:uploadbookingsfile'] = 'Bookings file'; +$string['facetoface:uploadbookingsfiledesc'] = " +Fields expected: +- Email address (required) +- Session number (required) +- Discount code (optional) +- Notification type (optional - valid options are 'email', 'ical', or 'both') +"; + +$string['facetoface:uploadandpreview'] = 'Bookings file'; +$string['facetoface:uploadreadytoprocess'] = 'Uploaded file has been validated and ready to be processed.'; $string['facetoface:view'] = 'View Face-to-Face activities and sessions'; $string['facetoface:viewattendees'] = 'View attendance list and attendees'; $string['facetoface:viewcancellations'] = 'View cancellations'; @@ -580,6 +607,7 @@ $string['status_session_cancelled'] = 'Session Cancelled'; $string['somesessionsfull'] = 'You have not been signed up for some sessions in the stream as they are at capacity.'; $string['summary'] = 'Summary'; +$string['sessionnumber'] = '#'; $string['takeattendance'] = 'Take attendance'; $string['time'] = 'Time'; $string['timedue'] = 'Registration deadline'; @@ -599,6 +627,7 @@ $string['updaterequests'] = 'Update requests'; $string['upgradeinfofacetoface'] = '{$a}: Face to Face upgrade info'; $string['upgradeprocessinggrades'] = 'Processing Face-to-Face grades, this may take a while if there are many sessions...'; +$string['uploadbookings'] = 'Upload bookings'; $string['usercancelledon'] = 'User cancelled on {$a}'; $string['usercalentry'] = 'Show entry on user\'s calendar'; $string['userdeletedcancel'] = 'User has been deleted'; @@ -782,6 +811,7 @@ /* Face-to-face events and logging */ $string['eventaddsession'] = 'Session added'; +$string['eventcsvprocessed'] = 'CSV processed'; $string['eventaddsessionfailed'] = 'Session add (FAILED)'; $string['eventapproverequests'] = 'Session approve requests'; $string['eventattendeesviewed'] = 'Session attendees viewed'; diff --git a/lib.php b/lib.php index 704372e..ed41045 100644 --- a/lib.php +++ b/lib.php @@ -100,7 +100,7 @@ function facetoface_statuses() { // This array must match the status codes above, and the values // must equal the end of the constant name but in lower case. - return array( + return [ MDL_F2F_STATUS_USER_CANCELLED => 'user_cancelled', // MDL_F2F_STATUS_SESSION_CANCELLED => 'session_cancelled', // Not yet implemented. MDL_F2F_STATUS_DECLINED => 'declined', @@ -111,7 +111,7 @@ function facetoface_statuses() { MDL_F2F_STATUS_NO_SHOW => 'no_show', MDL_F2F_STATUS_PARTIALLY_ATTENDED => 'partially_attended', MDL_F2F_STATUS_FULLY_ATTENDED => 'fully_attended', - ); + ]; } /** @@ -155,7 +155,6 @@ function format_cost($amount, $htmloutput=true) { $symbol = $localeinfo['currency_symbol']; if (empty($symbol)) { - // Cannot get the locale information, default to en_US.UTF-8. return '$' . $amount; } @@ -189,7 +188,7 @@ function facetoface_cost($userid, $sessionid, $sessiondata, $htmloutput=true) { WHERE su.sessionid = ? AND su.userid = ? AND su.discountcode IS NOT NULL - AND su.sessionid = se.id", array($sessionid, $userid)); + AND su.sessionid = se.id", [$sessionid, $userid]); if ($count > 0) { return format_cost($sessiondata->discountcost, $htmloutput); } else { @@ -215,13 +214,11 @@ function facetoface_format_duration($duration) { return $string; } - if ($components and count($components) > 1) { - + if ($components && count($components) > 1) { // E.g. "1:30" => "1 hour and 30 minutes". $hours = round($components[0]); $minutes = round($components[1]); } else { - // E.g. "1.5" => "1 hour and 30 minutes". $hours = floor($duration); $minutes = round(($duration - floor($duration)) * 60); @@ -274,8 +271,7 @@ function facetoface_minutes_to_hours($minutes) { */ function facetoface_hours_to_minutes($hours) { $components = explode(':', $hours); - if ($components and count($components) > 1) { - + if ($components && count($components) > 1) { // E.g. "1:45" => 105 minutes. $hours = $components[0]; $minutes = $components[1]; @@ -375,7 +371,7 @@ function facetoface_update_instance($facetoface, $instanceflag = true) { function facetoface_delete_instance($id) { global $CFG, $DB; - if (!$facetoface = $DB->get_record('facetoface', array('id' => $id))) { + if (!$facetoface = $DB->get_record('facetoface', ['id' => $id])) { return false; } @@ -398,14 +394,26 @@ function facetoface_delete_instance($id) { {facetoface_sessions} WHERE facetoface = ? )) - ", array($facetoface->id)); - - $DB->delete_records_select('facetoface_signups', "sessionid IN (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id)); - $DB->delete_records_select('facetoface_sessions_dates', "sessionid in (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", array($facetoface->id)); - $DB->delete_records('facetoface_sessions', array('facetoface' => $facetoface->id)); - $DB->delete_records('facetoface', array('id' => $facetoface->id)); - $DB->delete_records('event', array('modulename' => 'facetoface', 'instance' => $facetoface->id)); // Course events. - $DB->delete_records('event', array('modulename' => '0', 'eventtype' => 'facetofacesession', 'instance' => $facetoface->id)); // User events and Site events. + ", [$facetoface->id]); + + $DB->delete_records_select( + 'facetoface_signups', + "sessionid IN (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", + [$facetoface->id] + ); + $DB->delete_records_select( + 'facetoface_sessions_dates', + "sessionid in (SELECT id FROM {facetoface_sessions} WHERE facetoface = ?)", + [$facetoface->id] + ); + $DB->delete_records('facetoface_sessions', ['facetoface' => $facetoface->id]); + $DB->delete_records('facetoface', ['id' => $facetoface->id]); + $DB->delete_records('event', ['modulename' => 'facetoface', 'instance' => $facetoface->id]); // Course events. + $DB->delete_records('event', [ + 'modulename' => '0', + 'eventtype' => 'facetofacesession', + 'instance' => $facetoface->id, + ]); // User events and Site events. facetoface_grade_item_delete($facetoface); $transaction->allow_commit(); @@ -434,7 +442,6 @@ function facetoface_cleanup_session_data($session) { $localeinfo = localeconv(); $symbol = $localeinfo['decimal_point']; if (empty($symbol)) { - // Cannot get the locale information, default to en_US.UTF-8. $symbol = '.'; } @@ -455,12 +462,11 @@ function facetoface_add_session($session, $sessiondates) { $session->timecreated = time(); $session = facetoface_cleanup_session_data($session); - $eventname = $DB->get_field('facetoface', 'name,id', array('id' => $session->facetoface)); + $eventname = $DB->get_field('facetoface', 'name,id', ['id' => $session->facetoface]); $session->id = $DB->insert_record('facetoface_sessions', $session); if (empty($sessiondates)) { - // Insert a dummy date record. $date = new stdClass(); $date->sessionid = $session->id; @@ -493,10 +499,9 @@ function facetoface_update_session($session, $sessiondates) { $transaction = $DB->start_delegated_transaction(); $DB->update_record('facetoface_sessions', $session); - $DB->delete_records('facetoface_sessions_dates', array('sessionid' => $session->id)); + $DB->delete_records('facetoface_sessions_dates', ['sessionid' => $session->id]); if (empty($sessiondates)) { - // Insert a dummy date record. $date = new stdClass(); $date->sessionid = $session->id; @@ -528,7 +533,7 @@ function facetoface_update_calendar_entries($session, $facetoface=null) { global $USER, $DB; if (empty($facetoface)) { - $facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface)); + $facetoface = $DB->get_record('facetoface', ['id' => $session->facetoface]); } // Remove from all calendars. @@ -544,7 +549,6 @@ function facetoface_update_calendar_entries($session, $facetoface=null) { // Add to NEW calendartype. if ($facetoface->usercalentry) { - // Get ALL enrolled/booked users. $users = facetoface_get_attendees($session->id); // If session creator is not enrolled in the course, add the session to his/her events user calendar. @@ -574,30 +578,33 @@ function facetoface_update_attendees($session) { global $USER, $DB; // Get facetoface. - $facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface)); + $facetoface = $DB->get_record('facetoface', ['id' => $session->facetoface]); // Get course. - $course = $DB->get_record('course', array('id' => $facetoface->course)); + $course = $DB->get_record('course', ['id' => $facetoface->course]); // Update user status'. $users = facetoface_get_attendees($session->id); if ($users) { - // No/deleted session dates. if (empty($session->datetimeknown)) { - // Convert any bookings to waitlists. foreach ($users as $user) { - if ($user->statuscode == MDL_F2F_STATUS_BOOKED) { - - if (!facetoface_user_signup($session, $facetoface, $course, $user->discountcode, $user->notificationtype, MDL_F2F_STATUS_WAITLISTED, $user->id)) { + if ($user->statuscode == MDL_F2F_STATUS_BOOKED + && !facetoface_user_signup( + $session, + $facetoface, + $course, + $user->discountcode, + $user->notificationtype, + MDL_F2F_STATUS_WAITLISTED, + $user->id + )) { return false; - } } } } else { - // Session dates exist. // Convert earliest signed up users to booked, and make the rest waitlisted. $capacity = $session->capacity; @@ -618,8 +625,15 @@ function facetoface_update_attendees($session) { } if ($user->statuscode == MDL_F2F_STATUS_WAITLISTED) { - - if (!facetoface_user_signup($session, $facetoface, $course, $user->discountcode, $user->notificationtype, MDL_F2F_STATUS_BOOKED, $user->id)) { + if (!facetoface_user_signup( + $session, + $facetoface, + $course, + $user->discountcode, + $user->notificationtype, + MDL_F2F_STATUS_BOOKED, + $user->id + )) { return false; } $booked++; @@ -650,7 +664,6 @@ function facetoface_get_facetoface_menu() { } return $facetofacemenu; - } else { return ''; } @@ -665,7 +678,7 @@ function facetoface_get_facetoface_menu() { function facetoface_delete_session($session) { global $CFG, $DB; - $facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface)); + $facetoface = $DB->get_record('facetoface', ['id' => $session->facetoface]); // Cancel user signups (and notify users). $signedupusers = $DB->get_records_sql( @@ -681,9 +694,9 @@ function facetoface_delete_session($session) { s.sessionid = ? AND ss.superceded = 0 AND ss.statuscode >= ? - ", array($session->id, MDL_F2F_STATUS_REQUESTED)); + ", [$session->id, MDL_F2F_STATUS_REQUESTED]); - if ($signedupusers and count($signedupusers) > 0) { + if ($signedupusers && count($signedupusers) > 0) { foreach ($signedupusers as $user) { if (facetoface_user_cancel($session, $user->userid, true)) { facetoface_send_cancellation_notice($facetoface, $session, $user->userid); @@ -699,7 +712,7 @@ function facetoface_delete_session($session) { $DB->delete_records_select('event', "modulename = '0' AND eventtype like 'facetoface%' AND courseid = 0 AND instance = ?", - array($facetoface->id)); + [$facetoface->id]); // Remove entry from course calendar. facetoface_remove_session_from_calendar($session, $facetoface->course); @@ -708,8 +721,8 @@ function facetoface_delete_session($session) { facetoface_remove_session_from_calendar($session, SITEID); // Delete session details. - $DB->delete_records('facetoface_sessions', array('id' => $session->id)); - $DB->delete_records('facetoface_sessions_dates', array('sessionid' => $session->id)); + $DB->delete_records('facetoface_sessions', ['id' => $session->id]); + $DB->delete_records('facetoface_sessions_dates', ['sessionid' => $session->id]); $DB->delete_records_select( 'facetoface_signups_status', "signupid IN @@ -722,7 +735,7 @@ function facetoface_delete_session($session) { sessionid = {$session->id} ) "); - $DB->delete_records('facetoface_signups', array('sessionid' => $session->id)); + $DB->delete_records('facetoface_signups', ['sessionid' => $session->id]); $transaction->allow_commit(); return true; @@ -756,7 +769,6 @@ function facetoface_email_substitutions($msg, $facetofacename, $reminderperiod, } if ($data->datetimeknown) { - // Scheduled session. $sessiondate = \mod_facetoface\session::get_readable_session_datetime($data->sessiondates[0]); $starttime = userdate($data->sessiondates[0]->timestart, get_string('strftimetime')); @@ -770,7 +782,6 @@ function facetoface_email_substitutions($msg, $facetofacename, $reminderperiod, $alldates .= \mod_facetoface\session::get_readable_session_datetime($date); } } else { - // Wait-listed session. $sessiondate = get_string('unknowndate', 'facetoface'); $alldates = get_string('unknowndate', 'facetoface'); @@ -795,11 +806,15 @@ function facetoface_email_substitutions($msg, $facetofacename, $reminderperiod, $msg = str_replace(get_string('placeholder:reminderperiod', 'facetoface'), $reminderperiod, $msg); // Replace more meta data. - $msg = str_replace(get_string('placeholder:attendeeslink', 'facetoface'), $CFG->wwwroot . '/mod/facetoface/attendees.php?s=' . $sessionid, $msg); + $msg = str_replace( + get_string('placeholder:attendeeslink', 'facetoface'), + $CFG->wwwroot . '/mod/facetoface/attendees.php?s=' . $sessionid, + $msg + ); // Custom session fields (they look like "session:shortname" in the templates). $customfields = facetoface_get_session_customfields(); - $customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $sessionid), '', 'fieldid, data'); + $customdata = $DB->get_records('facetoface_session_data', ['sessionid' => $sessionid], '', 'fieldid, data'); foreach ($customfields as $field) { $placeholder = "[session:{$field->shortname}]"; $value = ''; @@ -833,7 +848,6 @@ function facetoface_cron() { $timenow = time(); foreach ($signupsdata as $signupdata) { if (facetoface_has_session_started($signupdata, $timenow)) { - // Too late, the session already started. // Mark the reminder as being sent already. $newsubmission = new stdClass(); @@ -863,7 +877,6 @@ function facetoface_cron() { // Note w runs from Sun=0 to Sat=6. if ($reminderdaycheck == 0 || $reminderdaycheck == 6) { - /* * Saturdays and Sundays are not included in the * reminder period as entered by the user, extend @@ -875,12 +888,11 @@ function facetoface_cron() { $remindertime = $earlieststarttime - ($reminderperiod * 24 * 3600); if ($timenow < $remindertime) { - // Too early to send reminder. continue; } - if (!$user = $DB->get_record('user', array('id' => $signupdata->userid))) { + if (!$user = $DB->get_record('user', ['id' => $signupdata->userid])) { continue; } @@ -888,10 +900,10 @@ function facetoface_cron() { // (i.e. it uses the language and timezone of the recipient of the email). $USER->lang = $user->lang; $USER->timezone = $user->timezone; - if (!$course = $DB->get_record('course', array('id' => $signupdata->course))) { + if (!$course = $DB->get_record('course', ['id' => $signupdata->course])) { continue; } - if (!$facetoface = $DB->get_record('facetoface', array('id' => $signupdata->facetofaceid))) { + if (!$facetoface = $DB->get_record('facetoface', ['id' => $signupdata->facetofaceid])) { continue; } @@ -905,17 +917,34 @@ function facetoface_cron() { } if (empty($posttext)) { - // The reminder message is not set, don't send anything. continue; } - $postsubject = facetoface_email_substitutions($postsubject, format_string($signupdata->facetofacename), $signupdata->reminderperiod, - $user, $signupdata, $signupdata->sessionid); - $posttext = facetoface_email_substitutions($posttext, format_string($signupdata->facetofacename), $signupdata->reminderperiod, - $user, $signupdata, $signupdata->sessionid); - $posttextmgrheading = facetoface_email_substitutions($posttextmgrheading, $signupdata->facetofacename, $signupdata->reminderperiod, - $user, $signupdata, $signupdata->sessionid); + $postsubject = facetoface_email_substitutions( + $postsubject, + format_string($signupdata->facetofacename), + $signupdata->reminderperiod, + $user, + $signupdata, + $signupdata->sessionid + ); + $posttext = facetoface_email_substitutions( + $posttext, + format_string($signupdata->facetofacename), + $signupdata->reminderperiod, + $user, + $signupdata, + $signupdata->sessionid + ); + $posttextmgrheading = facetoface_email_substitutions( + $posttextmgrheading, + $signupdata->facetofacename, + $signupdata->reminderperiod, + $user, + $signupdata, + $signupdata->sessionid + ); $posthtml = ''; // FIXME. if ($fromaddress = get_config('facetoface', 'fromaddress')) { @@ -952,14 +981,15 @@ function facetoface_cron() { if (email_to_user($manager, $from, $postsubject, $managertext, $posthtml)) { echo "\n".get_string('sentremindermanager', 'facetoface').": $user->firstname $user->lastname $manager->email"; } else { - $errormsg = array(); + $errormsg = []; $errormsg['submissionid'] = $signupdata->id; $errormsg['userid'] = $user->id; $errormsg['manageremail'] = $manager->email; - echo get_string('error:cronprefix', 'facetoface').' '.get_string('error:cannotemailmanager', 'facetoface', $errormsg)."\n"; + echo get_string('error:cronprefix', 'facetoface') . ' ' + . get_string('error:cannotemailmanager', 'facetoface', $errormsg) . "\n"; } } else { - $errormsg = array(); + $errormsg = []; $errormsg['submissionid'] = $signupdata->id; $errormsg['userid'] = $user->id; $errormsg['useremail'] = $user->email; @@ -1018,8 +1048,8 @@ function facetoface_is_session_in_progress($session, $timenow) { function facetoface_get_session_dates($sessionid) { global $DB; - $ret = array(); - if ($dates = $DB->get_records('facetoface_sessions_dates', array('sessionid' => $sessionid), 'timestart')) { + $ret = []; + if ($dates = $DB->get_records('facetoface_sessions_dates', ['sessionid' => $sessionid], 'timestart')) { $i = 0; foreach ($dates as $date) { $ret[$i++] = $date; @@ -1037,7 +1067,7 @@ function facetoface_get_session_dates($sessionid) { function facetoface_get_session($sessionid) { global $DB; - $session = $DB->get_record('facetoface_sessions', array('id' => $sessionid)); + $session = $DB->get_record('facetoface_sessions', ['id' => $sessionid]); if ($session) { $session->sessiondates = facetoface_get_session_dates($sessionid); $session->duration = facetoface_minutes_to_hours($session->duration); @@ -1057,7 +1087,7 @@ function facetoface_get_sessions($facetofaceid, $location='') { $fromclause = "FROM {facetoface_sessions} s"; $locationwhere = ''; - $locationparams = array(); + $locationparams = []; if (!empty($location)) { $fromclause = "FROM {facetoface_session_data} d JOIN {facetoface_sessions} s ON s.id = d.sessionid"; @@ -1070,7 +1100,7 @@ function facetoface_get_sessions($facetofaceid, $location='') { FROM {facetoface_sessions_dates} GROUP BY sessionid) m ON m.sessionid = s.id WHERE s.facetoface = ? $locationwhere - ORDER BY s.datetimeknown, m.mintimestart", array_merge(array($facetofaceid), $locationparams)); + ORDER BY s.datetimeknown, m.mintimestart", array_merge([$facetofaceid], $locationparams)); if ($sessions) { foreach ($sessions as $key => $value) { @@ -1132,7 +1162,7 @@ function facetoface_get_attendees($sessionid) { global $CFG, $DB; $usernamefields = facetoface_get_all_user_name_fields(true, 'u'); - $records = $DB->get_records_sql(" + return $DB->get_records_sql(" SELECT u.id, {$usernamefields}, u.email, su.id AS submissionid, @@ -1182,9 +1212,7 @@ function facetoface_get_attendees($sessionid) { ORDER BY sign.timecreated ASC, ss.timecreated ASC - ", array ($sessionid, MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED, $sessionid, MDL_F2F_STATUS_APPROVED)); - - return $records; + ", [$sessionid, MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED, $sessionid, MDL_F2F_STATUS_APPROVED]); } /** @@ -1230,7 +1258,7 @@ function facetoface_get_attendee($sessionid, $userid) { s.id = ? AND ss.superceded != 1 AND u.id = ? - ", array($sessionid, $userid)); + ", [$sessionid, $userid]); if (!$record) { return false; @@ -1247,7 +1275,7 @@ function facetoface_get_userfields() { static $userfields = null; if (null == $userfields) { - $userfields = array(); + $userfields = []; if (function_exists('grade_export_user_fields')) { $fieldnames = grade_export_user_fields(); @@ -1256,8 +1284,10 @@ function facetoface_get_userfields() { } } else { // Set default fields if the grade export patch is not detected (see MDL-17346). - $fieldnames = array('firstname', 'lastname', 'email', 'city', - 'idnumber', 'institution', 'department', 'address'); + $fieldnames = [ + 'firstname', 'lastname', 'email', 'city', + 'idnumber', 'institution', 'department', 'address', + ]; foreach ($fieldnames as $shortname) { $userfields[$shortname] = get_string($shortname); } @@ -1281,13 +1311,11 @@ function facetoface_download_attendance($facetofacename, $facetofaceid, $locatio $dateformat = 0; if ('ods' === $format) { - // OpenDocument format (ISO/IEC 26300). require_once($CFG->dirroot.'/lib/odslib.class.php'); $downloadfilename .= '.ods'; $workbook = new MoodleODSWorkbook('-'); } else { - // Excel format. require_once($CFG->dirroot.'/lib/excellib.class.php'); $downloadfilename .= '.xls'; @@ -1317,13 +1345,11 @@ function facetoface_download_attendees($facetofacename, $session, $attendees, $f $dateformat = 0; if ('ods' === $format) { - // OpenDocument format (ISO/IEC 26300). require_once($CFG->dirroot.'/lib/odslib.class.php'); $downloadfilename .= '.ods'; $workbook = new MoodleODSWorkbook('-'); } else { - // Excel format. require_once($CFG->dirroot.'/lib/excellib.class.php'); $downloadfilename .= '.xlsx'; @@ -1363,7 +1389,7 @@ function facetoface_download_attendees($facetofacename, $session, $attendees, $f unset($profilefields[$key]); } foreach ($fieldnames as $shortname) { - if (substr( $shortname, 0, 14 ) === 'profile_field_') { + if (substr($shortname, 0, 14 ) === 'profile_field_') { $fieldname = $profilefield[$shortname]->name; } else { $fieldname = $shortname == 'lang' ? get_string('language') : get_string($shortname); @@ -1383,11 +1409,11 @@ function facetoface_download_attendees($facetofacename, $session, $attendees, $f $user = $DB->get_record("user", ['id' => $attendee->id]); // Load custom user profile fields. - $user->profile = (array)profile_user_record($user->id, false); + $user->profile = (array) profile_user_record($user->id, false); // Prefix all custom profile field shortnames with 'profile_field_'. $user->profile = array_combine( - array_map(function($key) { + array_map(function ($key) { return 'profile_field_' . $key; }, array_keys($user->profile)), $user->profile ); @@ -1516,14 +1542,14 @@ function facetoface_write_activity_attendance(&$worksheet, $startingrow, $faceto $i = $startingrow; $locationcondition = ''; - $locationparam = array(); + $locationparam = []; if (!empty($location)) { $locationcondition = "AND s.location = ?"; - $locationparam = array($location); + $locationparam = [$location]; } // Fast version of "facetoface_get_attendees()" for all sessions. - $sessionsignups = array(); + $sessionsignups = []; $signups = $DB->get_records_sql(" SELECT su.id AS submissionid, @@ -1572,12 +1598,11 @@ function facetoface_write_activity_attendance(&$worksheet, $startingrow, $faceto AND ss.statuscode >= ? ORDER BY s.id, u.firstname, u.lastname - ", array(MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED, $facetofaceid, MDL_F2F_STATUS_APPROVED)); + ", [MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED, $facetofaceid, MDL_F2F_STATUS_APPROVED]); if ($signups) { - // Get all grades at once. - $userids = array(); + $userids = []; foreach ($signups as $signup) { if ($signup->id > 0) { $userids[] = $signup->id; @@ -1616,7 +1641,7 @@ function facetoface_write_activity_attendance(&$worksheet, $startingrow, $faceto $locationcondition ORDER BY s.datetimeknown, d.timestart"; - $sessions = $DB->get_records_sql($sql, array_merge(array($facetofaceid), $locationparam)); + $sessions = $DB->get_records_sql($sql, array_merge([$facetofaceid], $locationparam)); $i = $i - 1; // Will be incremented BEFORE each row is written. foreach ($sessions as $session) { @@ -1644,11 +1669,20 @@ function facetoface_write_activity_attendance(&$worksheet, $startingrow, $faceto if (!empty($sessionsignups[$session->id])) { foreach ($sessionsignups[$session->id] as $attendee) { $i++; - $j = facetoface_write_activity_attendance_helper($worksheet, $i, $session, $customsessionfields, $status, $dateformat, $session->timestart, $session->timefinish); + $j = facetoface_write_activity_attendance_helper( + $worksheet, + $i, + $session, + $customsessionfields, + $status, + $dateformat, + $session->timestart, + $session->timefinish + ); if ($trainerroles) { foreach (array_keys($trainerroles) as $roleid) { if (!empty($sessiontrainers[$roleid])) { - $trainers = array(); + $trainers = []; foreach ($sessiontrainers[$roleid] as $trainer) { $trainers[] = fullname($trainer); } @@ -1670,14 +1704,14 @@ function facetoface_write_activity_attendance(&$worksheet, $startingrow, $faceto if ('firstaccess' == $shortname || 'lastaccess' == $shortname || 'lastlogin' == $shortname || 'currentlogin' == $shortname) { - $worksheet->write_date($i, $j++, (int)$value, $dateformat); + $worksheet->write_date($i, $j++, (int) $value, $dateformat); } else { $worksheet->write_string($i, $j++, $value); } } $worksheet->write_string($i, $j++, $attendee->grade); - $worksheet->write_date($i, $j++, (int)$attendee->timecreated, $dateformat); + $worksheet->write_date($i, $j++, (int) $attendee->timecreated, $dateformat); if (!empty($coursename)) { $worksheet->write_string($i, $j++, $coursename); @@ -1689,8 +1723,17 @@ function facetoface_write_activity_attendance(&$worksheet, $startingrow, $faceto } else { // No one is sign-up, so let's just print the basic info. $i++; - // helper - $j = facetoface_write_activity_attendance_helper($worksheet, $i, $session, $customsessionfields, $status, $dateformat, $session->timestart, $session->timefinish); + // Helper. + $j = facetoface_write_activity_attendance_helper( + $worksheet, + $i, + $session, + $customsessionfields, + $status, + $dateformat, + $session->timestart, + $session->timefinish + ); foreach ($userfields as $unused) { $worksheet->write_string($i, $j++, '-'); @@ -1719,13 +1762,22 @@ function facetoface_write_activity_attendance(&$worksheet, $startingrow, $faceto * @return int The next Column in the sheet. */ -function facetoface_write_activity_attendance_helper(&$worksheet, $i, $session, $customsessionfields, $status, $dateformat, $starttime, $finishtime) { +function facetoface_write_activity_attendance_helper( + &$worksheet, + $i, + $session, + $customsessionfields, + $status, + $dateformat, + $starttime, + $finishtime +) { global $DB; $j = 0; // Custom session fields. - $customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $session->id), '', 'fieldid, data'); + $customdata = $DB->get_records('facetoface_session_data', ['sessionid' => $session->id], '', 'fieldid, data'); foreach ($customsessionfields as $field) { if (empty($field->showinsummary)) { continue; // Skip. @@ -1753,7 +1805,7 @@ function facetoface_write_activity_attendance_helper(&$worksheet, $i, $session, } $worksheet->write_string($i, $j++, userdate($starttime)); $worksheet->write_string($i, $j++, userdate($finishtime)); - $worksheet->write_number($i, $j++, (int)$session->duration); + $worksheet->write_number($i, $j++, (int) $session->duration); $worksheet->write_string($i, $j++, $status); return $j; @@ -1772,7 +1824,7 @@ function facetoface_get_user_customfields($userid, $fieldstoinclude=false) { // Cache all lookup. static $customfields = null; if (null == $customfields) { - $customfields = array(); + $customfields = []; } if (!empty($customfields[$userid])) { @@ -1785,10 +1837,10 @@ function facetoface_get_user_customfields($userid, $fieldstoinclude=false) { JOIN {user_info_data} id ON id.fieldid = uif.id WHERE id.userid = ?"; - $customfields = $DB->get_records_sql($sql, array($userid)); + $customfields = $DB->get_records_sql($sql, [$userid]); foreach ($customfields as $field) { $fieldname = $field->shortname; - if (false === $fieldstoinclude or !empty($fieldstoinclude[$fieldname])) { + if (false === $fieldstoinclude || !empty($fieldstoinclude[$fieldname])) { $ret->$fieldname = $field->data; } } @@ -1831,7 +1883,7 @@ function facetoface_get_unmailed_reminders() { WHERE su.mailedreminder = 0 AND se.datetimeknown = 1 - ", array(MDL_F2F_STATUS_BOOKED)); + ", [MDL_F2F_STATUS_BOOKED]); if ($submissions) { foreach ($submissions as $key => $value) { @@ -1870,14 +1922,12 @@ function facetoface_user_signup($session, $facetoface, $course, $discountcode, $userid = $USER->id; } - $return = false; $timenow = time(); // Check to see if a signup already exists. - if ($existingsignup = $DB->get_record('facetoface_signups', array('sessionid' => $session->id, 'userid' => $userid))) { + if ($existingsignup = $DB->get_record('facetoface_signups', ['sessionid' => $session->id, 'userid' => $userid])) { $usersignup = $existingsignup; } else { - // Otherwise, prepare a signup object. $usersignup = new stdclass; $usersignup->sessionid = $session->id; @@ -1897,12 +1947,11 @@ function facetoface_user_signup($session, $facetoface, $course, $discountcode, $success = $DB->update_record('facetoface_signups', $usersignup); } else { $usersignup->id = $DB->insert_record('facetoface_signups', $usersignup); - $success = (bool)$usersignup->id; + $success = (bool) $usersignup->id; } if (!$success) { throw new moodle_exception('error:couldnotupdatef2frecord', 'facetoface'); - return false; } // Work out which status to use. @@ -1911,16 +1960,18 @@ function facetoface_user_signup($session, $facetoface, $course, $discountcode, if (!\mod_facetoface\helper::is_approval_required((object) $facetoface)) { $newstatus = $statuscode; } else { - // If approval required. // Get current status (if any). - $currentstatus = $DB->get_field('facetoface_signups_status', 'statuscode', array('signupid' => $usersignup->id, 'superceded' => 0)); + $currentstatus = $DB->get_field( + 'facetoface_signups_status', + 'statuscode', + ['signupid' => $usersignup->id, 'superceded' => 0] + ); // If approved, then no problem. if ($currentstatus == MDL_F2F_STATUS_APPROVED) { $newstatus = $statuscode; } else if ($session->datetimeknown) { - // Otherwise, send manager request. $newstatus = MDL_F2F_STATUS_REQUESTED; } else { @@ -1931,24 +1982,23 @@ function facetoface_user_signup($session, $facetoface, $course, $discountcode, // Update status. if (!facetoface_update_signup_status($usersignup->id, $newstatus, $userid)) { throw new moodle_exception('error:f2ffailedupdatestatus', 'facetoface'); - return false; } // Add to user calendar -- if facetoface usercalentry is set to true. if ($facetoface->usercalentry) { - if (in_array($newstatus, array(MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED))) { + if (in_array($newstatus, [MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED])) { facetoface_add_session_to_calendar($session, $facetoface, 'user', $userid, 'booking'); } } // Course completion. - if (in_array($newstatus, array(MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED))) { + if (in_array($newstatus, [MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED])) { $completion = new completion_info($course); if ($completion->is_enabled()) { - $ccdetails = array( + $ccdetails = [ 'course' => $course->id, 'userid' => $userid, - ); + ]; $cc = new completion_completion($ccdetails); $cc->mark_inprogress($timenow); @@ -1962,7 +2012,6 @@ function facetoface_user_signup($session, $facetoface, $course, $discountcode, // Send notification. if ($notifyuser) { - // If booked/waitlisted. switch ($newstatus) { case MDL_F2F_STATUS_BOOKED: @@ -1980,12 +2029,10 @@ function facetoface_user_signup($session, $facetoface, $course, $discountcode, if (!empty($error)) { throw new moodle_exception($error, 'facetoface'); - return false; } if (!$DB->update_record('facetoface_signups', $usersignup)) { throw new moodle_exception('error:couldnotupdatef2frecord', 'facetoface'); - return false; } } @@ -2007,7 +2054,7 @@ function facetoface_send_request_notice($facetoface, $session, $userid) { return 'error:nomanagersemailset'; } - $user = $DB->get_record('user', array('id' => $userid)); + $user = $DB->get_record('user', ['id' => $userid]); if (!$user) { return 'error:invaliduserid'; } @@ -2062,7 +2109,6 @@ function facetoface_send_request_notice($facetoface, $session, $userid) { return ''; } - /** * Update the signup status of a particular signup * @@ -2074,7 +2120,6 @@ function facetoface_send_request_notice($facetoface, $session, $userid) { * @param bool $usetransaction Set to true if database transactions are to be used * * @returns integer ID of newly created signup status, or false - * */ function facetoface_update_signup_status($signupid, $statuscode, $createdby, $note='', $grade=null) { global $DB; @@ -2093,10 +2138,9 @@ function facetoface_update_signup_status($signupid, $statuscode, $createdby, $no $transaction = $DB->start_delegated_transaction(); if ($statusid = $DB->insert_record('facetoface_signups_status', $signupstatus)) { - // Mark any previous signup_statuses as superceded. $where = "signupid = ? AND ( superceded = 0 OR superceded IS NULL ) AND id != ?"; - $whereparams = array($signupid, $statusid); + $whereparams = [$signupid, $statusid]; $DB->set_field_select('facetoface_signups_status', 'superceded', 1, $where, $whereparams); $transaction->allow_commit(); @@ -2163,7 +2207,7 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $notificationtype, $facetoface, $session, $userid) { global $CFG, $DB; - $user = $DB->get_record('user', array('id' => $userid)); + $user = $DB->get_record('user', ['id' => $userid]); if (!$user) { return 'error:invaliduserid'; } @@ -2174,7 +2218,6 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, // If no notice type is defined (TEXT or ICAL). if (!($notificationtype & MDL_F2F_BOTH)) { - // If none, make sure they at least get a text email. $notificationtype |= MDL_F2F_TEXT; } @@ -2196,25 +2239,39 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, } // Do iCal attachement stuff. - $icalattachments = array(); + $icalattachments = []; if ($notificationtype & MDL_F2F_ICAL) { if (get_config('facetoface', 'oneemailperday')) { - // Keep track of all sessiondates. $sessiondates = $session->sessiondates; foreach ($sessiondates as $sessiondate) { - $session->sessiondates = array($sessiondate); // One day at a time. + $session->sessiondates = [$sessiondate]; // One day at a time. $filename = facetoface_get_ical_attachment($notificationtype, $facetoface, $session, $user); - $subject = facetoface_email_substitutions($postsubject, format_string($facetoface->name), $facetoface->reminderperiod, - $user, $session, $session->id); + $subject = facetoface_email_substitutions( + $postsubject, + format_string($facetoface->name), + $facetoface->reminderperiod, + $user, + $session, + $session->id + ); $body = facetoface_email_substitutions($posttext, format_string($facetoface->name), $facetoface->reminderperiod, $user, $session, $session->id); - $htmlmessage = facetoface_email_substitutions($posttext, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); + $htmlmessage = facetoface_email_substitutions( + $posttext, + $facetoface->name, + $facetoface->reminderperiod, + $user, + $session, + $session->id + ); $htmlbody = $htmlmessage; - $icalattachments[] = array('filename' => $filename, 'subject' => $subject, - 'body' => $body, 'htmlbody' => $htmlbody); + $icalattachments[] = [ + 'filename' => $filename, 'subject' => $subject, + 'body' => $body, 'htmlbody' => $htmlbody, + ]; } // Restore session dates. @@ -2225,10 +2282,19 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $user, $session, $session->id); $body = facetoface_email_substitutions($posttext, format_string($facetoface->name), $facetoface->reminderperiod, $user, $session, $session->id); - $htmlmessage = facetoface_email_substitutions($posttext, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); + $htmlmessage = facetoface_email_substitutions( + $posttext, + $facetoface->name, + $facetoface->reminderperiod, + $user, + $session, + $session->id + ); $htmlbody = $htmlmessage; - $icalattachments[] = array('filename' => $filename, 'subject' => $subject, - 'body' => $body, 'htmlbody' => $htmlbody); + $icalattachments[] = [ + 'filename' => $filename, 'subject' => $subject, + 'body' => $body, 'htmlbody' => $htmlbody, + ]; } } @@ -2238,8 +2304,14 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $posttext = facetoface_email_substitutions($posttext, format_string($facetoface->name), $facetoface->reminderperiod, $user, $session, $session->id); - $posttextmgrheading = facetoface_email_substitutions($posttextmgrheading, format_string($facetoface->name), $facetoface->reminderperiod, - $user, $session, $session->id); + $posttextmgrheading = facetoface_email_substitutions( + $posttextmgrheading, + format_string($facetoface->name), + $facetoface->reminderperiod, + $user, + $session, + $session->id + ); $posthtml = ''; // FIXME. if ($fromaddress = get_config('facetoface', 'fromaddress')) { @@ -2250,14 +2322,11 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $from = null; } - $usercheck = $DB->get_record('user', array('id' => $userid)); - // Send email with iCal attachment. if ($notificationtype & MDL_F2F_ICAL) { foreach ($icalattachments as $attachment) { if (!email_to_user($user, $from, $attachment['subject'], $attachment['body'], $attachment['htmlbody'], $attachment['filename'], $attachmentfilename)) { - return 'error:cannotsendconfirmationuser'; } unlink($CFG->dataroot . '/' . $attachment['filename']); @@ -2265,15 +2334,14 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, } // Send plain text email. - if ($notificationtype & MDL_F2F_TEXT) { - if (!email_to_user($user, $from, $postsubject, $posttext, $posthtml)) { - return 'error:cannotsendconfirmationuser'; - } + if ($notificationtype & MDL_F2F_TEXT + && !email_to_user($user, $from, $postsubject, $posttext, $posthtml)) { + return 'error:cannotsendconfirmationuser'; } // Manager notification. $manageremail = facetoface_get_manageremail($userid); - if (!empty($posttextmgrheading) and !empty($manageremail) and $session->datetimeknown) { + if (!empty($posttextmgrheading) && !empty($manageremail) && $session->datetimeknown) { $managertext = $posttextmgrheading.$posttext; $manager = $user; $manager->email = $manageremail; @@ -2287,7 +2355,6 @@ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, // Third-party notification. if (!empty($facetoface->thirdparty) && ($session->datetimeknown || !empty($facetoface->thirdpartywaitlist))) { - $thirdparty = $user; $recipients = explode(',', $facetoface->thirdparty); foreach ($recipients as $recipient) { @@ -2354,7 +2421,7 @@ function facetoface_send_cancellation_notice($facetoface, $session, $userid) { // Lookup what type of notification to send. $notificationtype = $DB->get_field('facetoface_signups', 'notificationtype', - array('sessionid' => $session->id, 'userid' => $userid)); + ['sessionid' => $session->id, 'userid' => $userid]); // Set cancellation bit. $notificationtype |= MDL_F2F_CANCEL; @@ -2388,9 +2455,9 @@ function facetoface_check_signup($facetofaceid) { */ function facetoface_get_manageremail($userid) { global $DB; - $fieldid = $DB->get_field('user_info_field', 'id', array('shortname' => F2F_MDL_MANAGERSEMAIL_FIELD)); + $fieldid = $DB->get_field('user_info_field', 'id', ['shortname' => F2F_MDL_MANAGERSEMAIL_FIELD]); if ($fieldid) { - return $DB->get_field('user_info_data', 'data', array('userid' => $userid, 'fieldid' => $fieldid)); + return $DB->get_field('user_info_data', 'data', ['userid' => $userid, 'fieldid' => $fieldid]); } else { return ''; // No custom field => no manager's email. } @@ -2419,9 +2486,9 @@ function facetoface_check_manageremail($manageremail) { $addressformat = get_config('facetoface', 'manageraddressformat'); if (empty($addressformat) || strpos($manageremail, $addressformat)) { return true; - } else { - return false; } + + return false; } /** @@ -2440,13 +2507,13 @@ function facetoface_take_attendance($data) { // Load session. if (!$session = facetoface_get_session($sessionid)) { - // error_log('F2F: Could not load facetoface session'); + // F2F: Could not load facetoface session. return false; } // Check facetoface has finished. if ($session->datetimeknown && !facetoface_has_session_started($session, time())) { - // error_log('F2F: Can not take attendance for a session that has not yet started'); + // F2F: Can not take attendance for a session that has not yet started. return false; } @@ -2455,7 +2522,7 @@ function facetoface_take_attendance($data) { * to zero, to indicate non attendance, but only the ticked attendees come through from the web interface. * Hence the need for a diff */ - $selectedsubmissionids = array(); + $selectedsubmissionids = []; /* * FIXME: This is not very efficient, we should do the grade @@ -2487,7 +2554,7 @@ function facetoface_take_attendance($data) { facetoface_update_signup_status($submissionid, $value, $USER->id, '', $grade); if (!facetoface_take_individual_attendance($submissionid, $grade)) { - // error_log("F2F: could not mark '$submissionid' as " . $value); + // F2F: could not mark '$submissionid' as $value. return false; } } @@ -2507,7 +2574,7 @@ function facetoface_approve_requests($data) { // Check request data. if (empty($data->requests) || !is_array($data->requests)) { - // error_log('F2F: No request data supplied'); + // F2F: No request data supplied. return false; } @@ -2515,25 +2582,24 @@ function facetoface_approve_requests($data) { // Load session. if (!$session = facetoface_get_session($sessionid)) { - // error_log('F2F: Could not load facetoface session'); + // F2F: Could not load facetoface session'). return false; } // Load facetoface. - if (!$facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface))) { - // error_log('F2F: Could not load facetoface instance'); + if (!$facetoface = $DB->get_record('facetoface', ['id' => $session->facetoface])) { + // F2F: Could not load facetoface instance. return false; } // Load course. - if (!$course = $DB->get_record('course', array('id' => $facetoface->course))) { - // error_log('F2F: Could not load course'); + if (!$course = $DB->get_record('course', ['id' => $facetoface->course])) { + // F2F: Could not load course. return false; } // Loop through requests. foreach ($data->requests as $key => $value) { - // Check key/value. if (!is_numeric($key) || !is_numeric($value)) { continue; @@ -2541,13 +2607,12 @@ function facetoface_approve_requests($data) { // Load user submission. if (!$attendee = facetoface_get_attendee($sessionid, $key)) { - // error_log('F2F: User '.$key.' not an attendee of this session'); + // F2F: User '.$key.' not an attendee of this session. continue; } // Update status. switch ($value) { - // Decline. case 1: facetoface_update_signup_status( @@ -2626,7 +2691,7 @@ function facetoface_take_individual_attendance($submissionid, $grading) { JOIN {course_modules} cm ON cm.instance = f.id JOIN {modules} m ON m.id = cm.module WHERE s.id = ? AND m.name='facetoface'", - array($submissionid)); + [$submissionid]); $grade = new stdclass(); $grade->userid = $record->userid; @@ -2651,6 +2716,7 @@ function facetoface_take_individual_attendance($submissionid, $grading) { return $result; } + /** * Used in many places to obtain properly-formatted session date and time info * @@ -2664,7 +2730,7 @@ function facetoface_format_session_times($start, $end, $tz) { $displaytimezones = get_config('facetoface', 'displaysessiontimezones'); $formattedsession = new stdClass(); - if (empty($tz) or empty($displaytimezones)) { + if (empty($tz) || empty($displaytimezones)) { $targettz = core_date::get_user_timezone(); } else { $targettz = core_date::get_user_timezone($tz); @@ -2696,7 +2762,7 @@ function facetoface_cm_info_view(cm_info $coursemodule) { global $USER, $DB; $output = ''; - if (!($facetoface = $DB->get_record('facetoface', array('id' => $coursemodule->instance)))) { + if (!($facetoface = $DB->get_record('facetoface', ['id' => $coursemodule->instance]))) { return null; } @@ -2709,23 +2775,29 @@ function facetoface_cm_info_view(cm_info $coursemodule) { // Can view attendees. $viewattendees = has_capability('mod/facetoface:viewattendees', $contextmodule); // Can see "view all sessions" link even if activity is hidden/currently unavailable. - $iseditor = has_any_capability(array('mod/facetoface:viewattendees', 'mod/facetoface:editsessions', + $iseditor = has_any_capability([ + 'mod/facetoface:viewattendees', 'mod/facetoface:editsessions', 'mod/facetoface:addattendees', 'mod/facetoface:addattendees', - 'mod/facetoface:takeattendance'), $contextmodule); + 'mod/facetoface:takeattendance', + ], $contextmodule); $timenow = time(); $strviewallsessions = get_string('viewallsessions', 'facetoface'); - $sessionsurl = new moodle_url('/mod/facetoface/view.php', array('f' => $facetoface->id)); - $htmlviewallsessions = html_writer::link($sessionsurl, $strviewallsessions, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strviewallsessions)); + $sessionsurl = new moodle_url('/mod/facetoface/view.php', ['f' => $facetoface->id]); + $htmlviewallsessions = html_writer::link($sessionsurl, $strviewallsessions, [ + 'class' => 'f2fsessionlinks f2fviewallsessions', + 'title' => $strviewallsessions, + ]); if ($submissions = facetoface_get_user_submissions($facetoface->id, $USER->id)) { // User has signedup for the instance. foreach ($submissions as $submission) { - if ($session = facetoface_get_session($submission->sessionid)) { $userisinwaitlist = facetoface_is_user_on_waitlist($session, $USER->id); - if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) { + if ($session->datetimeknown + && facetoface_has_session_started($session, $timenow) + && facetoface_is_session_in_progress($session, $timenow)) { $status = get_string('sessioninprogress', 'facetoface'); } else if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { $status = get_string('sessionover', 'facetoface'); @@ -2751,30 +2823,36 @@ function facetoface_cm_info_view(cm_info $coursemodule) { $sessiondates = get_string('wait-listed', 'facetoface'); } - $span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice')); + $span = html_writer::tag('span', get_string('options', 'facetoface').':', ['class' => 'f2fsessionnotice']); // Don't include the link to cancel a session if it has already occurred. $moreinfolink = ''; $cancellink = ''; if (!facetoface_has_session_started($session, $timenow)) { $strmoreinfo = get_string('moreinfo', 'facetoface'); - $signupurl = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)); - $moreinfolink = html_writer::link($signupurl, $strmoreinfo, array('class' => 'f2fsessionlinks f2fsessioninfolink', 'title' => $strmoreinfo)); + $signupurl = new moodle_url('/mod/facetoface/signup.php', ['s' => $session->id]); + $moreinfolink = html_writer::link($signupurl, $strmoreinfo, [ + 'class' => 'f2fsessionlinks f2fsessioninfolink', + 'title' => $strmoreinfo, + ]); } // Don't include the link to view attendees if user is lacking capability. $attendeeslink = ''; if ($viewattendees) { $strseeattendees = get_string('seeattendees', 'facetoface'); - $attendeesurl = new moodle_url('/mod/facetoface/attendees.php', array('s' => $session->id)); - $attendeeslink = html_writer::link($attendeesurl, $strseeattendees, array('class' => 'f2fsessionlinks f2fviewattendees', 'title' => $strseeattendees)); + $attendeesurl = new moodle_url('/mod/facetoface/attendees.php', ['s' => $session->id]); + $attendeeslink = html_writer::link($attendeesurl, $strseeattendees, [ + 'class' => 'f2fsessionlinks f2fviewattendees', + 'title' => $strseeattendees, + ]); } - $output .= html_writer::start_tag('div', array('class' => 'f2fsessiongroup')) - . html_writer::tag('span', $status, array('class' => 'f2fsessionnotice')) - . html_writer::start_tag('div', array('class' => 'f2fsession f2fsignedup')) - . html_writer::tag('div', $sessiondates, array('class' => 'f2fsessiontime')) - . html_writer::tag('div', $span . $moreinfolink . $attendeeslink . $cancellink, array('class' => 'f2foptions')) + $output .= html_writer::start_tag('div', ['class' => 'f2fsessiongroup']) + . html_writer::tag('span', $status, ['class' => 'f2fsessionnotice']) + . html_writer::start_tag('div', ['class' => 'f2fsession f2fsignedup']) + . html_writer::tag('div', $sessiondates, ['class' => 'f2fsessiontime']) + . html_writer::tag('div', $span . $moreinfolink . $attendeeslink . $cancellink, ['class' => 'f2foptions']) . html_writer::end_tag('div') . html_writer::end_tag('div'); } @@ -2785,34 +2863,45 @@ function facetoface_cm_info_view(cm_info $coursemodule) { if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_SINGLE) { $output .= $htmlviewallsessions; } - } - if (($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_MULTIPLE || !$submissions) && $sessions = facetoface_get_sessions($facetoface->id)) { + if (($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_MULTIPLE || !$submissions) + && $sessions = facetoface_get_sessions($facetoface->id)) { if ($facetoface->display > 0) { $j = 1; - $sessionsinprogress = array(); - $futuresessions = array(); + $sessionsinprogress = []; + $futuresessions = []; foreach ($sessions as $session) { - if (!facetoface_session_has_capacity($session, $contextmodule, MDL_F2F_STATUS_WAITLISTED) && !$session->allowoverbook) { + if (!facetoface_session_has_capacity($session, $contextmodule, MDL_F2F_STATUS_WAITLISTED) + && !$session->allowoverbook) { continue; } $attendance = facetoface_get_attendee($session->id, $USER->id); - if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_MULTIPLE && $attendance && $attendance->statuscode != MDL_F2F_STATUS_USER_CANCELLED) { + if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_MULTIPLE + && $attendance + && $attendance->statuscode != MDL_F2F_STATUS_USER_CANCELLED) { continue; } - if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && !facetoface_is_session_in_progress($session, $timenow)) { + if ($session->datetimeknown + && facetoface_has_session_started($session, $timenow) + && !facetoface_is_session_in_progress($session, $timenow)) { // Finished session, don't display. continue; } else { - $signupurl = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)); - $signupstr = $facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION ? 'signup' : 'signupforstream'; - $moreinfolink = html_writer::link($signupurl, get_string($signupstr, 'facetoface'), array('class' => 'f2fsessionlinks f2fsessioninfolink')); - $span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice')); + $signupurl = new moodle_url('/mod/facetoface/signup.php', ['s' => $session->id]); + $signupstr = ($facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION) + ? 'signup' + : 'signupforstream'; + $moreinfolink = html_writer::link( + $signupurl, + get_string($signupstr, 'facetoface'), + ['class' => 'f2fsessionlinks f2fsessioninfolink'] + ); + $span = html_writer::tag('span', get_string('options', 'facetoface').':', ['class' => 'f2fsessionnotice']); } $multidate = ''; @@ -2834,7 +2923,9 @@ function facetoface_cm_info_view(cm_info $coursemodule) { $sessionobject->date = $sessiondate; $sessionobject->multidate = $multidate; - if ($session->datetimeknown && (facetoface_has_session_started($session, $timenow)) && facetoface_is_session_in_progress($session, $timenow)) { + if ($session->datetimeknown + && (facetoface_has_session_started($session, $timenow)) + && facetoface_is_session_in_progress($session, $timenow)) { $sessionsinprogress[] = $sessionobject; } else { $sessionobject->options = $span; @@ -2849,37 +2940,45 @@ function facetoface_cm_info_view(cm_info $coursemodule) { } if (!empty($sessionsinprogress)) { - $output .= html_writer::start_tag('div', array('class' => 'f2fsessiongroup')); - $output .= html_writer::tag('span', get_string('sessioninprogress', 'facetoface'), array('class' => 'f2fsessionnotice')); + $output .= html_writer::start_tag('div', ['class' => 'f2fsessiongroup']); + $output .= html_writer::tag('span', get_string('sessioninprogress', 'facetoface'), ['class' => 'f2fsessionnotice']); foreach ($sessionsinprogress as $session) { - $output .= html_writer::start_tag('div', array('class' => 'f2fsession f2finprogress')) - . html_writer::tag('span', $session->date.$session->multidate, array('class' => 'f2fsessiontime')) + $output .= html_writer::start_tag('div', ['class' => 'f2fsession f2finprogress']) + . html_writer::tag('span', $session->date.$session->multidate, ['class' => 'f2fsessiontime']) . html_writer::end_tag('div'); } $output .= html_writer::end_tag('div'); } if (!empty($futuresessions)) { - $output .= html_writer::start_tag('div', array('class' => 'f2fsessiongroup')); + $output .= html_writer::start_tag('div', ['class' => 'f2fsessiongroup']); if ($facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION) { - $output .= html_writer::tag('span', get_string('signupforsession', 'facetoface'), array('class' => 'f2fsessionnotice')); + $output .= html_writer::tag( + 'span', + get_string('signupforsession', 'facetoface'), + ['class' => 'f2fsessionnotice'] + ); } else { - $output .= html_writer::tag('span', get_string('upcomingsessions', 'facetoface'), array('class' => 'f2fsessionnotice')); + $output .= html_writer::tag( + 'span', + get_string('upcomingsessions', 'facetoface'), + ['class' => 'f2fsessionnotice'] + ); if (!empty($futuresessions)) { $firstsession = $futuresessions[array_keys($futuresessions)[0]]; - $output .= html_writer::tag('div', $firstsession->moreinfolink, array('class' => 'f2foptions')); + $output .= html_writer::tag('div', $firstsession->moreinfolink, ['class' => 'f2foptions']); } } foreach ($futuresessions as $session) { - $output .= html_writer::start_tag('div', array('class' => 'f2fsession f2ffuture')) - . html_writer::tag('div', $session->date.$session->multidate, array('class' => 'f2fsessiontime')); + $output .= html_writer::start_tag('div', ['class' => 'f2fsession f2ffuture']) + . html_writer::tag('div', $session->date.$session->multidate, ['class' => 'f2fsessiontime']); if ($facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION) { - $output .= html_writer::tag('div', $session->options . $session->moreinfolink, array('class' => 'f2foptions')); + $output .= html_writer::tag('div', $session->options . $session->moreinfolink, ['class' => 'f2foptions']); } $output .= html_writer::end_tag('div'); @@ -2887,18 +2986,19 @@ function facetoface_cm_info_view(cm_info $coursemodule) { $output .= html_writer::end_tag('div'); } - $output .= ($iseditor || ($coursemodule->visible && $coursemodule->available)) ? $htmlviewallsessions : $strviewallsessions; - + $output .= ($iseditor || ($coursemodule->visible && $coursemodule->available)) + ? $htmlviewallsessions + : $strviewallsessions; } else { // Show only name if session display is set to zero. - $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname')); + $content = html_writer::tag('span', $htmlviewallsessions, ['class' => 'f2fsessionnotice f2factivityname']); $coursemodule->set_content($content); return; } } if (!$submissions && !$sessions && has_capability('mod/facetoface:viewemptyactivities', $contextmodule)) { - $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname')); + $content = html_writer::tag('span', $htmlviewallsessions, ['class' => 'f2fsessionnotice f2factivityname']); $coursemodule->set_content($content); return; } @@ -2926,7 +3026,6 @@ function facetoface_get_ical_attachment($method, $facetoface, $session, $user) { // First, generate all the VEVENT blocks. $vevents = ''; foreach ($session->sessiondates as $date) { - /* * Date that this representation of the calendar information was created - * we use the time the session was created @@ -2943,10 +3042,10 @@ function facetoface_get_ical_attachment($method, $facetoface, $session, $user) { AND su.sessionid = ? AND sus.superceded = 1 AND sus.statuscode = ? "; - $params = array($user->id, $session->id, MDL_F2F_STATUS_USER_CANCELLED); + $params = [$user->id, $session->id, MDL_F2F_STATUS_USER_CANCELLED]; $uid = $dtstamp . - '-' . substr(md5($CFG->siteidentifier . $session->id . $date->id), -8) . // Unique identifier, salted with site identifier. + '-' . substr(md5($CFG->siteidentifier . $session->id . $date->id), -8) . // Unique identifier with salt (site id). '-' . $DB->count_records_sql($sql, $params) . // New UID if this is a re-signup. '@' . $urlbits['host']; // Hostname for this moodle installation. @@ -3001,7 +3100,8 @@ function facetoface_get_ical_attachment($method, $facetoface, $session, $user) { $username = fullname($user); $mailto = $user->email; - // The extra newline at the bottom is so multiple events start on their own lines. The very last one is trimmed outside the loop. + // The extra newline at the bottom is so multiple events start on their + // own lines. The very last one is trimmed outside the loop. $vevents .= <<record_exists_sql($sql, array($session->id, $userid, MDL_F2F_STATUS_WAITLISTED)); + return $DB->record_exists_sql($sql, [$session->id, $userid, MDL_F2F_STATUS_WAITLISTED]); } /** @@ -3153,16 +3253,17 @@ function facetoface_grade_item_update($facetoface, $grades=null) { global $CFG, $DB; if (!isset($facetoface->cmidnumber)) { - $sql = "SELECT cm.idnumber as cmidnumber FROM {course_modules} cm JOIN {modules} m ON m.id = cm.module WHERE m.name='facetoface' AND cm.instance = ?"; - $facetoface->cmidnumber = $DB->get_field_sql($sql, array($facetoface->id)); + $facetoface->cmidnumber = $DB->get_field_sql($sql, [$facetoface->id]); } - $params = array('itemname' => format_string($facetoface->name), - 'idnumber' => $facetoface->cmidnumber); + $params = [ + 'itemname' => format_string($facetoface->name), + 'idnumber' => $facetoface->cmidnumber, + ]; $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademin'] = 0; @@ -3187,7 +3288,7 @@ function facetoface_grade_item_update($facetoface, $grades=null) { */ function facetoface_grade_item_delete($facetoface) { $retcode = grade_update('mod/facetoface', $facetoface->course, 'mod', 'facetoface', - $facetoface->id, 0, null, array('deleted' => 1)); + $facetoface->id, 0, null, ['deleted' => 1]); return ($retcode === GRADE_UPDATE_OK); } @@ -3216,7 +3317,7 @@ function facetoface_get_num_attendees($sessionid, $status=MDL_F2F_STATUS_BOOKED) ss.statuscode >= ?'; // For the session, pick signups that haven't been superceded, or cancelled. - return (int) $DB->count_records_sql($sql, array($sessionid, $status)); + return (int) $DB->count_records_sql($sql, [$sessionid, $status]); } /** @@ -3231,12 +3332,12 @@ function facetoface_get_user_submissions($facetofaceid, $userid, $includecancell global $CFG, $DB; $whereclause = "s.facetoface = ? AND su.userid = ? AND ss.superceded != 1"; - $whereparams = array($facetofaceid, $userid); + $whereparams = [$facetofaceid, $userid]; // If not show cancelled, only show requested and up status'. if (!$includecancellations) { $whereclause .= ' AND ss.statuscode >= ? AND ss.statuscode < ?'; - $whereparams = array_merge($whereparams, array(MDL_F2F_STATUS_REQUESTED, MDL_F2F_STATUS_NO_SHOW)); + $whereparams = array_merge($whereparams, [MDL_F2F_STATUS_REQUESTED, MDL_F2F_STATUS_NO_SHOW]); } // TODO fix mailedconfirmation, timegraded, timecancelled, etc. @@ -3281,7 +3382,7 @@ function facetoface_get_user_submissions($facetofaceid, $userid, $includecancell function facetoface_user_cancel_submission($sessionid, $userid, $cancelreason='') { global $DB; - $signup = $DB->get_record('facetoface_signups', array('sessionid' => $sessionid, 'userid' => $userid)); + $signup = $DB->get_record('facetoface_signups', ['sessionid' => $sessionid, 'userid' => $userid]); if (!$signup) { return true; // Not signed up, nothing to do. } @@ -3293,14 +3394,14 @@ function facetoface_user_cancel_submission($sessionid, $userid, $cancelreason='' * A list of actions in the logs that indicate view activity for participants */ function facetoface_get_view_actions() { - return array('view', 'view all'); + return ['view', 'view all']; } /** * A list of actions in the logs that indicate post activity for participants */ function facetoface_get_post_actions() { - return array('cancel booking', 'signup'); + return ['cancel booking', 'signup']; } /** @@ -3385,7 +3486,7 @@ function facetoface_add_session_to_calendar($session, $facetoface, $calendartype $description .= html_writer::tag('p', clean_param($facetoface->description, PARAM_CLEANHTML)); } $description .= facetoface_print_session($session, false, true, true); - $linkurl = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)); + $linkurl = new moodle_url('/mod/facetoface/signup.php', ['s' => $session->id]); $linktext = get_string('signupforthissession', 'facetoface'); if ($calendartype == 'site' && $facetoface->showoncalendar == F2F_CAL_SITE) { @@ -3431,11 +3532,10 @@ function facetoface_add_session_to_calendar($session, $facetoface, $calendartype $newevent->timemodified = time(); if ($calendartype == 'user' && $eventtype == 'booking') { - // Check for and Delete the 'created' calendar event to reduce multiple entries for the same event. $DB->delete_records_select('event', 'userid = ? AND instance = ? AND ' . $DB->sql_compare_text('eventtype') . ' = ? AND ' . $DB->sql_compare_text('name') . ' = ?', - array($userid, $session->facetoface, 'facetofacesession', $shortname)); + [$userid, $session->facetoface, 'facetofacesession', $shortname]); } $result = $result && $DB->insert_record('event', $newevent); @@ -3459,13 +3559,13 @@ function facetoface_remove_session_from_calendar($session, $courseid=0, $userid= $modulename = 'facetoface'; } if (empty($userid)) { // Match any UserID. - $params = array($modulename, $session->facetoface, $courseid, $session->id); + $params = [$modulename, $session->facetoface, $courseid, $session->id]; return $DB->delete_records_select('event', "modulename = ? AND instance = ? AND courseid = ? AND uuid = ?", $params); } else { - $params = array($modulename, $session->facetoface, $userid, $courseid, $session->id); + $params = [$modulename, $session->facetoface, $userid, $courseid, $session->id]; return $DB->delete_records_select('event', "modulename = ? AND instance = ? AND userid = ? AND @@ -3484,7 +3584,7 @@ function facetoface_remove_session_from_calendar($session, $courseid=0, $userid= function facetoface_update_user_calendar_events($session, $eventtype) { global $DB; - $facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface)); + $facetoface = $DB->get_record('facetoface', ['id' => $session->facetoface]); if (empty($facetoface->usercalentry) || $facetoface->usercalentry == 0) { return true; } @@ -3513,7 +3613,7 @@ function facetoface_delete_user_calendar_events($session, $eventtype) { eventtype = 'facetoface$eventtype' AND instance = ?"; - $whereparams = array($session->facetoface); + $whereparams = [$session->facetoface]; if ('session' == $eventtype) { $likestr = "%attendees.php?s={$session->id}%"; @@ -3529,7 +3629,6 @@ function facetoface_delete_user_calendar_events($session, $eventtype) { WHERE $whereclause", $whereparams); if ($users && count($users) > 0) { - // Delete the existing events. $DB->delete_records_select('event', $whereclause, $whereparams); } @@ -3551,7 +3650,6 @@ function facetoface_session_has_capacity($session, $context=false) { $signupcount = facetoface_get_num_attendees($session->id); if ($signupcount >= $session->capacity) { - // If session is full, check if overbooking is allowed for this user. if (!$context || !has_capability('mod/facetoface:overbook', $context)) { return false; @@ -3575,10 +3673,10 @@ function facetoface_print_session($session, $showcapacity, $calendaroutput=false $table = new html_table(); $table->attributes['class'] = 'generaltable f2fsession'; - $table->align = array('right', 'left'); + $table->align = ['right', 'left']; $customfields = facetoface_get_session_customfields(); - $customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $session->id), '', 'fieldid, data'); + $customdata = $DB->get_records('facetoface_session_data', ['sessionid' => $session->id], '', 'fieldid, data'); foreach ($customfields as $field) { $data = ''; if (!empty($customdata[$field->id])) { @@ -3589,7 +3687,7 @@ function facetoface_print_session($session, $showcapacity, $calendaroutput=false $data = format_string($customdata[$field->id]->data); } } - $table->data[] = array(str_replace(' ', ' ', format_string($field->name)), $data); + $table->data[] = [str_replace(' ', ' ', format_string($field->name)), $data]; } $strdatetime = str_replace(' ', ' ', get_string('sessiondatetime', 'facetoface')); @@ -3601,9 +3699,9 @@ function facetoface_print_session($session, $showcapacity, $calendaroutput=false } $html .= \mod_facetoface\session::get_readable_session_datetime($date); } - $table->data[] = array($strdatetime, $html); + $table->data[] = [$strdatetime, $html]; } else { - $table->data[] = array($strdatetime, html_writer::tag('i', get_string('wait-listed', 'facetoface'))); + $table->data[] = [$strdatetime, html_writer::tag('i', get_string('wait-listed', 'facetoface'))]; } $signupcount = facetoface_get_num_attendees($session->id); @@ -3611,45 +3709,50 @@ function facetoface_print_session($session, $showcapacity, $calendaroutput=false if ($showcapacity) { if ($session->allowoverbook) { - $table->data[] = array(get_string('capacity', 'facetoface'), $session->capacity . ' ('.strtolower(get_string('allowoverbook', 'facetoface')).')'); + $table->data[] = [ + get_string('capacity', 'facetoface'), + $session->capacity . ' ('.strtolower(get_string('allowoverbook', 'facetoface')).')', + ]; } else { - $table->data[] = array(get_string('capacity', 'facetoface'), $session->capacity); + $table->data[] = [get_string('capacity', 'facetoface'), $session->capacity]; } } else if (!$calendaroutput) { - $table->data[] = array(get_string('seatsavailable', 'facetoface'), max(0, $placesleft)); + $table->data[] = [get_string('seatsavailable', 'facetoface'), max(0, $placesleft)]; } // Display requires approval notification. - $facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface)); + $facetoface = $DB->get_record('facetoface', ['id' => $session->facetoface]); if (\mod_facetoface\helper::is_approval_required((object) $facetoface)) { - $table->data[] = array('', get_string('sessionrequiresmanagerapproval', 'facetoface')); + $table->data[] = ['', get_string('sessionrequiresmanagerapproval', 'facetoface')]; } // Display waitlist notification. if (!$hidesignup && $session->allowoverbook && $placesleft < 1) { - $table->data[] = array('', get_string('userwillbewaitlisted', 'facetoface')); + $table->data[] = ['', get_string('userwillbewaitlisted', 'facetoface')]; } if (!empty($session->duration)) { - $table->data[] = array(get_string('duration', 'facetoface'), facetoface_format_duration($session->duration)); + $table->data[] = [get_string('duration', 'facetoface'), facetoface_format_duration($session->duration)]; } if (!empty($session->normalcost)) { - $table->data[] = array(get_string('normalcost', 'facetoface'), format_cost($session->normalcost)); + $table->data[] = [get_string('normalcost', 'facetoface'), format_cost($session->normalcost)]; } if (!empty($session->discountcost)) { - $table->data[] = array(get_string('discountcost', 'facetoface'), format_cost($session->discountcost)); + $table->data[] = [get_string('discountcost', 'facetoface'), format_cost($session->discountcost)]; } if (!empty($session->details)) { $details = clean_text($session->details, FORMAT_HTML); - $table->data[] = array(get_string('details', 'facetoface'), format_text($details, FORMAT_HTML, array('context' => context_system::instance()))); + $table->data[] = [ + get_string('details', 'facetoface'), + format_text($details, FORMAT_HTML, ['context' => context_system::instance()]), + ]; } // Display trainers. $trainerroles = facetoface_get_trainer_roles(); if ($trainerroles) { - // Get trainers. $trainers = facetoface_get_trainers($session->id); foreach ($trainerroles as $role => $rolename) { @@ -3659,13 +3762,13 @@ function facetoface_print_session($session, $showcapacity, $calendaroutput=false continue; } - $trainernames = array(); + $trainernames = []; foreach ($trainers[$role] as $trainer) { - $trainerurl = new moodle_url('/user/view.php', array('id' => $trainer->id)); + $trainerurl = new moodle_url('/user/view.php', ['id' => $trainer->id]); $trainernames[] = html_writer::link($trainerurl, fullname($trainer)); } - $table->data[] = array($rolename, implode(', ', $trainernames)); + $table->data[] = [$rolename, implode(', ', $trainernames)]; } } @@ -3695,11 +3798,10 @@ function facetoface_save_customfield_value($fieldid, $data, $otherid, $table) { $newrecord->data = $dbdata; $fieldname = "{$table}id"; - if ($record = $DB->get_record("facetoface_{$table}_data", array('fieldid' => $fieldid, $fieldname => $otherid))) { + if ($record = $DB->get_record("facetoface_{$table}_data", ['fieldid' => $fieldid, $fieldname => $otherid])) { if (empty($dbdata)) { - // Clear out the existing value. - return $DB->delete_records("facetoface_{$table}_data", array('id' => $record->id)); + return $DB->delete_records("facetoface_{$table}_data", ['id' => $record->id]); } $newrecord->id = $record->id; @@ -3727,7 +3829,7 @@ function facetoface_save_customfield_value($fieldid, $data, $otherid, $table) { function facetoface_get_customfield_value($field, $otherid, $table) { global $DB; - if ($record = $DB->get_record("facetoface_{$table}_data", array('fieldid' => $field->id, "{$table}id" => $otherid))) { + if ($record = $DB->get_record("facetoface_{$table}_data", ['fieldid' => $field->id, "{$table}id" => $otherid])) { if (!empty($record->data)) { if (CUSTOMFIELD_TYPE_MULTISELECT == $field->type) { return explode(CUSTOMFIELD_DELIMITER, $record->data); @@ -3753,9 +3855,7 @@ function facetoface_get_customfielddata($sessionid) { JOIN {facetoface_session_data} d ON f.id = d.fieldid WHERE d.sessionid = ?"; - $records = $DB->get_records_sql($sql, array($sessionid)); - - return $records; + return $DB->get_records_sql($sql, [$sessionid]); } /** @@ -3767,7 +3867,7 @@ function facetoface_get_session_customfields() { static $customfields = null; if (null == $customfields) { if (!$customfields = $DB->get_records('facetoface_session_field')) { - $customfields = array(); + $customfields = []; } } return $customfields; @@ -3779,16 +3879,20 @@ function facetoface_get_session_customfields() { function facetoface_list_of_customfields() { global $CFG, $USER, $DB, $OUTPUT; - if ($fields = $DB->get_records('facetoface_session_field', array(), 'name', 'id, name')) { + if ($fields = $DB->get_records('facetoface_session_field', [], 'name', 'id, name')) { $table = new html_table(); $table->attributes['class'] = 'halfwidthtable'; foreach ($fields as $field) { $fieldname = format_string($field->name); - $editurl = new moodle_url('/mod/facetoface/customfield.php', array('id' => $field->id)); + $editurl = new moodle_url('/mod/facetoface/customfield.php', ['id' => $field->id]); $editlink = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit'))); - $deleteurl = new moodle_url('/mod/facetoface/customfield.php', array('id' => $field->id, 'd' => '1', 'sesskey' => $USER->sesskey)); + $deleteurl = new moodle_url('/mod/facetoface/customfield.php', [ + 'id' => $field->id, + 'd' => '1', + 'sesskey' => $USER->sesskey, + ]); $deletelink = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', get_string('delete'))); - $table->data[] = array($fieldname, $editlink, $deletelink); + $table->data[] = [$fieldname, $editlink, $deletelink]; } return html_writer::table($table, true); } @@ -3811,17 +3915,14 @@ function facetoface_update_trainers($sessionid, $form) { // Loop through form data and add any new trainers. foreach ($form as $roleid => $trainers) { - // Loop through trainers in this role. foreach ($trainers as $trainer) { - if (!$trainer) { continue; } // If the trainer doesn't exist already, create it. if (!isset($oldtrainers[$roleid][$trainer])) { - $newtrainer = new stdClass(); $newtrainer->userid = $trainer; $newtrainer->roleid = $roleid; @@ -3829,9 +3930,6 @@ function facetoface_update_trainers($sessionid, $form) { if (!$DB->insert_record('facetoface_session_roles', $newtrainer)) { throw new moodle_exception('error:couldnotaddtrainer', 'facetoface'); - $transaction->force_transaction_rollback(); - - return false; } } else { unset($oldtrainers[$roleid][$trainer]); @@ -3842,7 +3940,6 @@ function facetoface_update_trainers($sessionid, $form) { // Loop through what is left of old trainers, and remove (as they have been deselected). if ($oldtrainers) { foreach ($oldtrainers as $roleid => $trainers) { - // If no trainers left. if (empty($trainers)) { continue; @@ -3850,10 +3947,12 @@ function facetoface_update_trainers($sessionid, $form) { // Delete any remaining trainers. foreach ($trainers as $trainer) { - if (!$DB->delete_records('facetoface_session_roles', array('sessionid' => $sessionid, 'roleid' => $roleid, 'userid' => $trainer->id))) { + if (!$DB->delete_records('facetoface_session_roles', [ + 'sessionid' => $sessionid, + 'roleid' => $roleid, + 'userid' => $trainer->id, + ])) { throw new moodle_exception('error:couldnotdeletetrainer', 'facetoface'); - $transaction->force_transaction_rollback(); - return false; } } } @@ -3864,7 +3963,6 @@ function facetoface_update_trainers($sessionid, $form) { return true; } - /** * Return array of trainer roles configured for face-to-face * @@ -3898,13 +3996,12 @@ function facetoface_get_trainer_roles() { // Return roles and names. if (!$rolenames) { - return array(); + return []; } return $rolenames; } - /** * Get all trainers associated with a session, optionally * restricted to a certain roleid @@ -3934,7 +4031,7 @@ function facetoface_get_trainers($sessionid, $roleid = null) { WHERE r.sessionid = ? "; - $params = array($sessionid); + $params = [$sessionid]; if ($roleid) { $sql .= "AND r.roleid = ?"; @@ -3942,12 +4039,11 @@ function facetoface_get_trainers($sessionid, $roleid = null) { } $rs = $DB->get_recordset_sql($sql , $params); - $return = array(); + $return = []; foreach ($rs as $record) { - // Create new array for this role. if (!isset($return[$record->roleid])) { - $return[$record->roleid] = array(); + $return[$record->roleid] = []; } $return[$record->roleid][$record->id] = $record; } @@ -3992,17 +4088,21 @@ function facetoface_manager_needed($facetoface) { function facetoface_list_of_sitenotices() { global $CFG, $USER, $DB, $OUTPUT; - if ($notices = $DB->get_records('facetoface_notice', array(), 'name', 'id, name')) { + if ($notices = $DB->get_records('facetoface_notice', [], 'name', 'id, name')) { $table = new html_table(); - $table->data = array(); - $table->size = array('100%'); + $table->data = []; + $table->size = ['100%']; foreach ($notices as $notice) { $noticename = format_string($notice->name); - $editurl = new moodle_url('/mod/facetoface/sitenotice.php', array('id' => $notice->id)); + $editurl = new moodle_url('/mod/facetoface/sitenotice.php', ['id' => $notice->id]); $editlink = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit'))); - $deleteurl = new moodle_url('/mod/facetoface/sitenotice.php', array('id' => $notice->id, 'd' => '1', 'sesskey' => $USER->sesskey)); + $deleteurl = new moodle_url('/mod/facetoface/sitenotice.php', [ + 'id' => $notice->id, + 'd' => '1', + 'sesskey' => $USER->sesskey, + ]); $deletelink = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', get_string('delete'))); - $table->data[] = array($noticename, $editlink, $deletelink); + $table->data[] = [$noticename, $editlink, $deletelink]; } return html_writer::table($table, true); } @@ -4018,7 +4118,7 @@ function facetoface_add_customfields_to_form(&$mform, $customfields, $alloptiona foreach ($customfields as $field) { $fieldname = "custom_$field->shortname"; - $options = array(); + $options = []; if (!$field->required) { $options[''] = get_string('none'); } @@ -4041,13 +4141,13 @@ function facetoface_add_customfields_to_form(&$mform, $customfields, $alloptiona $select->setMultiple(true); break; default: - // error_log("facetoface: invalid field type for custom field ID $field->id"); + // F2F: invalid field type for custom field ID $field->id. continue 2; } $mform->setType($fieldname, PARAM_TEXT); $mform->setDefault($fieldname, $field->defaultvalue); - if ($field->required and !$alloptional) { + if ($field->required && !$alloptional) { $mform->addRule($fieldname, null, 'required', null, 'client'); } } @@ -4065,7 +4165,7 @@ function facetoface_get_cancellations($sessionid) { $fullname = $DB->sql_fullname('u.firstname', 'u.lastname'); $usernamefields = facetoface_get_all_user_name_fields(true, 'u'); - $instatus = array(MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED, MDL_F2F_STATUS_REQUESTED); + $instatus = [MDL_F2F_STATUS_BOOKED, MDL_F2F_STATUS_WAITLISTED, MDL_F2F_STATUS_REQUESTED]; list($insql, $inparams) = $DB->get_in_or_equal($instatus); // Nasty SQL follows: @@ -4104,12 +4204,11 @@ function facetoface_get_cancellations($sessionid) { {$fullname}, c.timecreated "; - $params = array_merge(array(MDL_F2F_STATUS_USER_CANCELLED), $inparams); + $params = array_merge([MDL_F2F_STATUS_USER_CANCELLED], $inparams); $params[] = $sessionid; return $DB->get_records_sql($sql, $params); } - /** * Get session unapproved requests * @@ -4123,7 +4222,7 @@ function facetoface_get_requests($sessionid) { $fullname = $DB->sql_fullname('u.firstname', 'u.lastname'); $usernamefields = facetoface_get_all_user_name_fields(true, 'u'); - $params = array($sessionid, MDL_F2F_STATUS_REQUESTED); + $params = [$sessionid, MDL_F2F_STATUS_REQUESTED]; $sql = "SELECT u.id, su.id AS signupid, {$usernamefields}, ss.timecreated AS timerequested @@ -4136,7 +4235,6 @@ function facetoface_get_requests($sessionid) { return $DB->get_records_sql($sql, $params); } - /** * Get session declined requests * @@ -4150,7 +4248,7 @@ function facetoface_get_declines($sessionid) { $fullname = $DB->sql_fullname('u.firstname', 'u.lastname'); $usernamefields = facetoface_get_all_user_name_fields(true, 'u'); - $params = array($sessionid, MDL_F2F_STATUS_DECLINED); + $params = [$sessionid, MDL_F2F_STATUS_DECLINED]; $sql = "SELECT u.id, su.id AS signupid, {$usernamefields}, ss.timecreated AS timerequested @@ -4162,13 +4260,12 @@ function facetoface_get_declines($sessionid) { return $DB->get_records_sql($sql, $params); } - /** * Returns all other caps used in module * @return array */ function facetoface_get_extra_capabilities() { - return array('moodle/site:viewfullnames'); + return ['moodle/site:viewfullnames']; } /** @@ -4205,7 +4302,7 @@ function facetoface_get_coursemodule_info($coursemodule) { * @return mixed True if module supports feature, null if doesn't know */ function facetoface_supports($feature) { - switch($feature) { + switch ($feature) { case FEATURE_BACKUP_MOODLE2: return true; case FEATURE_GRADE_HAS_GRADE: @@ -4292,10 +4389,10 @@ public function find_users($search) { "; $order = " ORDER BY u.lastname ASC, u.firstname ASC"; $params = array_merge($params, - array( + [ 'sessid' => $this->sessionid, - 'statuswaitlisted' => MDL_F2F_STATUS_WAITLISTED - )); + 'statuswaitlisted' => MDL_F2F_STATUS_WAITLISTED, + ]); if (!$this->is_validating()) { $potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params); @@ -4307,12 +4404,12 @@ public function find_users($search) { $availableusers = $DB->get_records_sql($fields . $sql . $order, $params); if (empty($availableusers)) { - return array(); + return []; } $groupname = get_string('potentialusers', 'role', count($availableusers)); - return array($groupname => $availableusers); + return [$groupname => $availableusers]; } protected function get_options() { @@ -4388,7 +4485,11 @@ public function find_users($search) { AND ss.statuscode >= :statusapproved "; $order = " ORDER BY sign.timecreated ASC, ss.timecreated ASC"; - $params = array ('sessid1' => $this->sessionid, 'statusbooked' => MDL_F2F_STATUS_BOOKED, 'statuswaitlisted' => MDL_F2F_STATUS_WAITLISTED); + $params = [ + 'sessid1' => $this->sessionid, + 'statusbooked' => MDL_F2F_STATUS_BOOKED, + 'statuswaitlisted' => MDL_F2F_STATUS_WAITLISTED, + ]; $params = array_merge($params, $whereparams); $params['sessid2'] = $this->sessionid; $params['statusapproved'] = MDL_F2F_STATUS_APPROVED; @@ -4401,11 +4502,11 @@ public function find_users($search) { $availableusers = $DB->get_records_sql($fields . $sql . $order, $params); if (empty($availableusers)) { - return array(); + return []; } $groupname = get_string('existingusers', 'role', count($availableusers)); - return array($groupname => $availableusers); + return [$groupname => $availableusers]; } protected function get_options() { diff --git a/mod_form.php b/mod_form.php index de9e772..b8cc19a 100644 --- a/mod_form.php +++ b/mod_form.php @@ -43,7 +43,7 @@ public function definition() { // General. $mform->addElement('header', 'general', get_string('general', 'form')); - $mform->addElement('text', 'name', get_string('name'), array('size' => '64')); + $mform->addElement('text', 'name', get_string('name'), ['size' => '64']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { @@ -53,14 +53,14 @@ public function definition() { $this->standard_intro_elements(); - $mform->addElement('text', 'thirdparty', get_string('thirdpartyemailaddress', 'facetoface'), array('size' => '64')); + $mform->addElement('text', 'thirdparty', get_string('thirdpartyemailaddress', 'facetoface'), ['size' => '64']); $mform->setType('thirdparty', PARAM_NOTAGS); $mform->addHelpButton('thirdparty', 'thirdpartyemailaddress', 'facetoface'); $mform->addElement('checkbox', 'thirdpartywaitlist', get_string('thirdpartywaitlist', 'facetoface')); $mform->addHelpButton('thirdpartywaitlist', 'thirdpartywaitlist', 'facetoface'); - $display = array(); + $display = []; for ($i = 0; $i <= 18; $i += 2) { $display[$i] = $i; } @@ -82,19 +82,24 @@ public function definition() { $mform->addHelpButton('allowcancellationsdefault', 'allowcancellationsdefault', 'facetoface'); } - $signupoptions = array( + $signupoptions = [ MOD_FACETOFACE_SIGNUP_SINGLE => get_string('single', 'facetoface'), MOD_FACETOFACE_SIGNUP_MULTIPLE => get_string('multiple', 'facetoface'), - ); + ]; $mform->addElement('select', 'signuptype', get_string('signuptype', 'facetoface'), $signupoptions); $mform->setDefault('signuptype', MOD_FACETOFACE_SIGNUP_SINGLE); $mform->addHelpButton('signuptype', 'signuptype', 'facetoface'); - $multiplesignupmethods = array( + $multiplesignupmethods = [ MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION => get_string('multiplesignuppersession', 'facetoface'), MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_ACTIVITY => get_string('multiplesignupperactivity', 'facetoface'), + ]; + $mform->addElement( + 'select', + 'multiplesignupmethod', + get_string('multiplesignupmethod', 'facetoface'), + $multiplesignupmethods ); - $mform->addElement('select', 'multiplesignupmethod', get_string('multiplesignupmethod', 'facetoface'), $multiplesignupmethods); $mform->setDefault('signuptype', MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_SESSION); $mform->addHelpButton('multiplesignupmethod', 'multiplesignupmethod', 'facetoface'); $mform->hideIf('multiplesignupmethod', 'signuptype', 'eq', MOD_FACETOFACE_SIGNUP_SINGLE); @@ -103,7 +108,7 @@ public function definition() { $calendaroptions = [ F2F_CAL_NONE => get_string('none'), - F2F_CAL_COURSE => get_string('course') + F2F_CAL_COURSE => get_string('course'), ]; if (has_capability('mod/facetoface:createsitewideevent', $this->context)) { @@ -118,7 +123,7 @@ public function definition() { $mform->setDefault('usercalentry', true); $mform->addHelpButton('usercalentry', 'usercalentry', 'facetoface'); - $mform->addElement('text', 'shortname', get_string('shortname'), array('size' => 32, 'maxlength' => 32)); + $mform->addElement('text', 'shortname', get_string('shortname'), ['size' => 32, 'maxlength' => 32]); $mform->setType('shortname', PARAM_TEXT); $mform->addHelpButton('shortname', 'shortname', 'facetoface'); $mform->addRule('shortname', null, 'maxlength', 32); @@ -129,18 +134,28 @@ public function definition() { $mform->addHelpButton('request', 'requestmessage', 'facetoface'); } - $mform->addElement('text', 'requestsubject', get_string('email:subject', 'facetoface'), array('size' => '55')); + $mform->addElement('text', 'requestsubject', get_string('email:subject', 'facetoface'), ['size' => '55']); $mform->setType('requestsubject', PARAM_TEXT); $mform->setDefault('requestsubject', get_string('setting:defaultrequestsubjectdefault', 'facetoface')); $mform->disabledIf('requestsubject', 'approvalreqd'); $mform->hideIf('requestsubject', 'enableapprovals', 'eq', 0); - $mform->addElement('textarea', 'requestmessage', get_string('email:message', 'facetoface'), 'wrap="virtual" rows="15" cols="70"'); + $mform->addElement( + 'textarea', + 'requestmessage', + get_string('email:message', 'facetoface'), + 'wrap="virtual" rows="15" cols="70"' + ); $mform->setDefault('requestmessage', get_string('setting:defaultrequestmessagedefault', 'facetoface')); $mform->disabledIf('requestmessage', 'approvalreqd'); $mform->hideIf('requestmessage', 'enableapprovals', 'eq', 0); - $mform->addElement('textarea', 'requestinstrmngr', get_string('email:instrmngr', 'facetoface'), 'wrap="virtual" rows="10" cols="70"'); + $mform->addElement( + 'textarea', + 'requestinstrmngr', + get_string('email:instrmngr', 'facetoface'), + 'wrap="virtual" rows="10" cols="70"' + ); $mform->setDefault('requestinstrmngr', get_string('setting:defaultrequestinstrmngrdefault', 'facetoface')); $mform->disabledIf('requestinstrmngr', 'approvalreqd'); $mform->hideIf('requestinstrmngr', 'enableapprovals', 'eq', 0); @@ -149,7 +164,7 @@ public function definition() { $mform->addElement('header', 'confirmation', get_string('confirmationmessage', 'facetoface')); $mform->addHelpButton('confirmation', 'confirmationmessage', 'facetoface'); - $mform->addElement('text', 'confirmationsubject', get_string('email:subject', 'facetoface'), array('size' => '55')); + $mform->addElement('text', 'confirmationsubject', get_string('email:subject', 'facetoface'), ['size' => '55']); $mform->setType('confirmationsubject', PARAM_TEXT); $mform->setDefault('confirmationsubject', get_string('setting:defaultconfirmationsubjectdefault', 'facetoface')); @@ -157,12 +172,17 @@ public function definition() { $mform->setType('confirmationmessage', PARAM_RAW); $confirmationmessagedata = [ 'text' => get_string('setting:defaultconfirmationmessagedefault2', 'facetoface'), - 'format' => FORMAT_HTML + 'format' => FORMAT_HTML, ]; $mform->addElement('checkbox', 'emailmanagerconfirmation', get_string('emailmanager', 'facetoface')); $mform->addHelpButton('emailmanagerconfirmation', 'emailmanagerconfirmation', 'facetoface'); - $mform->addElement('textarea', 'confirmationinstrmngr', get_string('email:instrmngr', 'facetoface'), 'wrap="virtual" rows="4" cols="70"'); + $mform->addElement( + 'textarea', + 'confirmationinstrmngr', + get_string('email:instrmngr', 'facetoface'), + 'wrap="virtual" rows="4" cols="70"' + ); $mform->addHelpButton('confirmationinstrmngr', 'confirmationinstrmngr', 'facetoface'); $mform->disabledIf('confirmationinstrmngr', 'emailmanagerconfirmation'); $mform->setDefault('confirmationinstrmngr', get_string('setting:defaultconfirmationinstrmngrdefault', 'facetoface')); @@ -171,22 +191,32 @@ public function definition() { $mform->addElement('header', 'reminder', get_string('remindermessage', 'facetoface')); $mform->addHelpButton('reminder', 'remindermessage', 'facetoface'); - $mform->addElement('text', 'remindersubject', get_string('email:subject', 'facetoface'), array('size' => '55')); + $mform->addElement('text', 'remindersubject', get_string('email:subject', 'facetoface'), ['size' => '55']); $mform->setType('remindersubject', PARAM_TEXT); $mform->setDefault('remindersubject', get_string('setting:defaultremindersubjectdefault', 'facetoface')); - $mform->addElement('textarea', 'remindermessage', get_string('email:message', 'facetoface'), 'wrap="virtual" rows="15" cols="70"'); + $mform->addElement( + 'textarea', + 'remindermessage', + get_string('email:message', 'facetoface'), + 'wrap="virtual" rows="15" cols="70"' + ); $mform->setDefault('remindermessage', get_string('setting:defaultremindermessagedefault', 'facetoface')); $mform->addElement('checkbox', 'emailmanagerreminder', get_string('emailmanager', 'facetoface')); $mform->addHelpButton('emailmanagerreminder', 'emailmanagerreminder', 'facetoface'); - $mform->addElement('textarea', 'reminderinstrmngr', get_string('email:instrmngr', 'facetoface'), 'wrap="virtual" rows="4" cols="70"'); + $mform->addElement( + 'textarea', + 'reminderinstrmngr', + get_string('email:instrmngr', 'facetoface'), + 'wrap="virtual" rows="4" cols="70"' + ); $mform->addHelpButton('reminderinstrmngr', 'reminderinstrmngr', 'facetoface'); $mform->disabledIf('reminderinstrmngr', 'emailmanagerreminder'); $mform->setDefault('reminderinstrmngr', get_string('setting:defaultreminderinstrmngrdefault', 'facetoface')); - $reminderperiod = array(); + $reminderperiod = []; for ($i = 1; $i <= 20; $i += 1) { $reminderperiod[$i] = $i; } @@ -198,34 +228,47 @@ public function definition() { $mform->addElement('header', 'waitlisted', get_string('waitlistedmessage', 'facetoface')); $mform->addHelpButton('waitlisted', 'waitlistedmessage', 'facetoface'); - $mform->addElement('text', 'waitlistedsubject', get_string('email:subject', 'facetoface'), array('size' => '55')); + $mform->addElement('text', 'waitlistedsubject', get_string('email:subject', 'facetoface'), ['size' => '55']); $mform->setType('waitlistedsubject', PARAM_TEXT); $mform->setDefault('waitlistedsubject', get_string('setting:defaultwaitlistedsubjectdefault', 'facetoface')); - $mform->addElement('textarea', 'waitlistedmessage', get_string('email:message', 'facetoface'), 'wrap="virtual" rows="15" cols="70"'); + $mform->addElement( + 'textarea', + 'waitlistedmessage', + get_string('email:message', 'facetoface'), + 'wrap="virtual" rows="15" cols="70"' + ); $mform->setDefault('waitlistedmessage', get_string('setting:defaultwaitlistedmessagedefault', 'facetoface')); // Cancellation message. $mform->addElement('header', 'cancellation', get_string('cancellationmessage', 'facetoface')); $mform->addHelpButton('cancellation', 'cancellationmessage', 'facetoface'); - $mform->addElement('text', 'cancellationsubject', get_string('email:subject', 'facetoface'), array('size' => '55')); + $mform->addElement('text', 'cancellationsubject', get_string('email:subject', 'facetoface'), ['size' => '55']); $mform->setType('cancellationsubject', PARAM_TEXT); $mform->setDefault('cancellationsubject', get_string('setting:defaultcancellationsubjectdefault', 'facetoface')); - $mform->addElement('textarea', 'cancellationmessage', get_string('email:message', 'facetoface'), 'wrap="virtual" rows="15" cols="70"'); + $mform->addElement( + 'textarea', + 'cancellationmessage', + get_string('email:message', 'facetoface'), + 'wrap="virtual" rows="15" cols="70"' + ); $mform->setDefault('cancellationmessage', get_string('setting:defaultcancellationmessagedefault', 'facetoface')); $mform->addElement('checkbox', 'emailmanagercancellation', get_string('emailmanager', 'facetoface')); $mform->addHelpButton('emailmanagercancellation', 'emailmanagercancellation', 'facetoface'); - $mform->addElement('textarea', 'cancellationinstrmngr', get_string('email:instrmngr', 'facetoface'), 'wrap="virtual" rows="4" cols="70"'); + $mform->addElement( + 'textarea', + 'cancellationinstrmngr', + get_string('email:instrmngr', 'facetoface'), + 'wrap="virtual" rows="4" cols="70"' + ); $mform->addHelpButton('cancellationinstrmngr', 'cancellationinstrmngr', 'facetoface'); $mform->disabledIf('cancellationinstrmngr', 'emailmanagercancellation'); $mform->setDefault('cancellationinstrmngr', get_string('setting:defaultcancellationinstrmngrdefault', 'facetoface')); - $data = (object) [ - 'confirmationmessage' => $confirmationmessagedata - ]; + $data = (object) ['confirmationmessage' => $confirmationmessagedata]; $this->set_data($data); $features = new stdClass; $features->groups = false; @@ -261,13 +304,13 @@ public function data_preprocessing(&$defaultvalues) { $defaultvalues['emailmanagercancellation'] = 1; } - if ($this->current->instance) { - if (isset($defaultvalues['confirmationmessage']) && !is_array($defaultvalues['confirmationmessage'])) { + if ($this->current->instance + && isset($defaultvalues['confirmationmessage']) + && !is_array($defaultvalues['confirmationmessage'])) { $defaultvalues['confirmationmessage'] = [ 'format' => $defaultvalues['confirmationmessageformat'] ?? FORMAT_HTML, 'text' => $defaultvalues['confirmationmessage'], ]; - } } } diff --git a/renderer.php b/renderer.php index d8e2780..e0e46e2 100644 --- a/renderer.php +++ b/renderer.php @@ -28,8 +28,6 @@ * @author Francois Marier */ -defined('MOODLE_INTERNAL') || die(); - class mod_facetoface_renderer extends plugin_renderer_base { /** @@ -38,12 +36,13 @@ class mod_facetoface_renderer extends plugin_renderer_base { public function print_session_list_table($customfields, $sessions, $viewattendees, $editsessions, $signuplinks = true) { $output = ''; - $tableheader = array(); + $tableheader = []; foreach ($customfields as $field) { if (!empty($field->showinsummary)) { $tableheader[] = format_string($field->name); } } + $tableheader[] = get_string('sessionnumber', 'facetoface'); $tableheader[] = get_string('date', 'facetoface'); $tableheader[] = get_string('time', 'facetoface'); if ($viewattendees) { @@ -59,7 +58,7 @@ public function print_session_list_table($customfields, $sessions, $viewattendee $table = new html_table(); $table->attributes['class'] = 'f2fsessionlist'; $table->head = $tableheader; - $table->data = array(); + $table->data = []; foreach ($sessions as $session) { $isbookedsession = false; @@ -67,7 +66,7 @@ public function print_session_list_table($customfields, $sessions, $viewattendee $sessionstarted = false; $sessionfull = false; - $sessionrow = array(); + $sessionrow = []; // Custom fields. $customdata = $session->customfielddata; @@ -80,14 +79,19 @@ public function print_session_list_table($customfields, $sessions, $viewattendee $sessionrow[] = ' '; } else { if (CUSTOMFIELD_TYPE_MULTISELECT == $field->type) { - $sessionrow[] = str_replace(CUSTOMFIELD_DELIMITER, html_writer::empty_tag('br'), format_string($customdata[$field->id]->data)); + $sessionrow[] = str_replace( + CUSTOMFIELD_DELIMITER, + html_writer::empty_tag('br'), + format_string($customdata[$field->id]->data) + ); } else { $sessionrow[] = format_string($customdata[$field->id]->data); } - } } + $sessionrow[] = html_writer::tag('span', $session->id, ['class' => 'mr-3']); + // Dates/times. $allsessiondates = ''; $allsessiontimes = ''; @@ -105,7 +109,6 @@ public function print_session_list_table($customfields, $sessions, $viewattendee } else { $allsessiondates = get_string('wait-listed', 'facetoface'); $allsessiontimes = get_string('wait-listed', 'facetoface'); - $sessionwaitlisted = true; } $sessionrow[] = $allsessiondates; $sessionrow[] = $allsessiontimes; @@ -122,7 +125,9 @@ public function print_session_list_table($customfields, $sessions, $viewattendee // Status. $status = get_string('bookingopen', 'facetoface'); - if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) { + if ($session->datetimeknown + && facetoface_has_session_started($session, $timenow) + && facetoface_is_session_in_progress($session, $timenow)) { $status = get_string('sessioninprogress', 'facetoface'); $sessionstarted = true; } else if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { @@ -142,34 +147,37 @@ public function print_session_list_table($customfields, $sessions, $viewattendee // Options. $options = ''; if ($editsessions) { - $options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id)), + $options .= $this->output->action_icon(new moodle_url('sessions.php', ['s' => $session->id]), new pix_icon('t/edit', get_string('edit', 'facetoface')), null, - array('title' => get_string('editsession', 'facetoface'))) . ' '; - $options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id, 'c' => 1)), + ['title' => get_string('editsession', 'facetoface')]) . ' '; + $options .= $this->output->action_icon(new moodle_url('sessions.php', ['s' => $session->id, 'c' => 1]), new pix_icon('t/copy', get_string('copy', 'facetoface')), null, - array('title' => get_string('copysession', 'facetoface'))) . ' '; - $options .= $this->output->action_icon(new moodle_url('sessions.php', array('s' => $session->id, 'd' => 1)), + ['title' => get_string('copysession', 'facetoface')]) . ' '; + $options .= $this->output->action_icon(new moodle_url('sessions.php', ['s' => $session->id, 'd' => 1]), new pix_icon('t/delete', get_string('delete', 'facetoface')), null, - array('title' => get_string('deletesession', 'facetoface'))) . ' '; + ['title' => get_string('deletesession', 'facetoface')]) . ' '; } if ($viewattendees) { $options .= html_writer::link('attendees.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('attendees', 'facetoface'), - array('title' => get_string('seeattendees', 'facetoface'))) . '   '; - $options .= $this->output->action_icon(new moodle_url('attendees.php', array('s' => $session->id, 'download' => 'xlsx')), + ['title' => get_string('seeattendees', 'facetoface')]) . '   '; + $options .= $this->output->action_icon(new moodle_url('attendees.php', ['s' => $session->id, 'download' => 'xlsx']), new pix_icon('f/spreadsheet', get_string('downloadexcel')), null, - array('title' => get_string('downloadexcel'))) . ' '; - $options .= $this->output->action_icon(new moodle_url('attendees.php', array('s' => $session->id, 'download' => 'ods')), + ['title' => get_string('downloadexcel')]) . ' '; + $options .= $this->output->action_icon(new moodle_url('attendees.php', ['s' => $session->id, 'download' => 'ods']), new pix_icon('f/calc', get_string('downloadods')), null, - array('title' => get_string('downloadods'))) . ' ' . html_writer::empty_tag('br'); + ['title' => get_string('downloadods')]) . ' ' . html_writer::empty_tag('br'); } if ($isbookedsession) { $options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, get_string('moreinfo', 'facetoface'), - array('title' => get_string('moreinfo', 'facetoface'))) . html_writer::empty_tag('br'); + ['title' => get_string('moreinfo', 'facetoface')]) . html_writer::empty_tag('br'); if ($session->allowcancellations) { - $options .= html_writer::link('cancelsignup.php?s=' . $session->id . '&backtoallsessions=' . $session->facetoface, - get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface'))); + $options .= html_writer::link( + 'cancelsignup.php?s=' . $session->id . '&backtoallsessions=' . $session->facetoface, + get_string('cancelbooking', 'facetoface'), + ['title' => get_string('cancelbooking', 'facetoface')] + ); } } else if (!$sessionstarted && !$bookedsession && $signuplinks) { $options .= html_writer::link('signup.php?s='.$session->id.'&backtoallsessions='.$session->facetoface, @@ -184,11 +192,11 @@ public function print_session_list_table($customfields, $sessions, $viewattendee // Set the CSS class for the row. if ($sessionstarted) { - $row->attributes = array('class' => 'dimmed_text'); + $row->attributes = ['class' => 'dimmed_text']; } else if ($isbookedsession) { - $row->attributes = array('class' => 'highlight'); + $row->attributes = ['class' => 'highlight']; } else if ($sessionfull) { - $row->attributes = array('class' => 'dimmed_text'); + $row->attributes = ['class' => 'dimmed_text']; } // Add row to table. diff --git a/sessions.php b/sessions.php index 60459dd..ecbcbb0 100644 --- a/sessions.php +++ b/sessions.php @@ -32,8 +32,8 @@ require_once('lib.php'); $id = optional_param('id', 0, PARAM_INT); // Course Module ID. -$f = optional_param('f', 0, PARAM_INT); // facetoface Module ID. -$s = optional_param('s', 0, PARAM_INT); // facetoface session ID. +$f = optional_param('f', 0, PARAM_INT); // Facetoface Module ID. +$s = optional_param('s', 0, PARAM_INT); // Facetoface session ID. $c = optional_param('c', 0, PARAM_INT); // Copy session. $d = optional_param('d', 0, PARAM_INT); // Delete session. $confirm = optional_param('confirm', false, PARAM_BOOL); // Delete confirmation. @@ -42,23 +42,23 @@ $session = null; if ($id && !$s) { - if (!$cm = $DB->get_record('course_modules', array('id' => $id))) { + if (!$cm = $DB->get_record('course_modules', ['id' => $id])) { throw new moodle_exception('error:incorrectcoursemoduleid', 'facetoface'); } - if (!$course = $DB->get_record('course', array('id' => $cm->course))) { + if (!$course = $DB->get_record('course', ['id' => $cm->course])) { throw new moodle_exception('error:coursemisconfigured', 'facetoface'); } - if (!$facetoface = $DB->get_record('facetoface', array('id' => $cm->instance))) { + if (!$facetoface = $DB->get_record('facetoface', ['id' => $cm->instance])) { throw new moodle_exception('error:incorrectcoursemodule', 'facetoface'); } } else if ($s) { 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)) { @@ -67,10 +67,10 @@ $nbdays = count($session->sessiondates); } else { - if (!$facetoface = $DB->get_record('facetoface', array('id' => $f))) { + if (!$facetoface = $DB->get_record('facetoface', ['id' => $f])) { 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)) { @@ -84,42 +84,39 @@ require_capability('mod/facetoface:editsessions', $context); $PAGE->set_cm($cm); -$PAGE->set_url('/mod/facetoface/sessions.php', array('f' => $f)); +$PAGE->set_url('/mod/facetoface/sessions.php', ['f' => $f]); $returnurl = "view.php?f=$facetoface->id"; -$editoroptions = array( +$editoroptions = [ 'noclean' => false, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $course->maxbytes, 'context' => $modulecontext, -); - +]; // Handle deletions. -if ($d and $confirm) { +if ($d && $confirm) { if (!confirm_sesskey()) { throw new moodle_exception('confirmsesskeybad', 'error'); } if (facetoface_delete_session($session)) { - // Logging and events trigger. - $params = array( + $params = [ 'context' => $modulecontext, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\delete_session::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' => $modulecontext, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\delete_session_failed::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -137,16 +134,26 @@ $details->id = isset($session) ? $session->id : 0; $details->details = isset($session->details) ? $session->details : ''; $details->detailsformat = FORMAT_HTML; -$details = file_prepare_standard_editor($details, 'details', $editoroptions, $modulecontext, 'mod_facetoface', 'session', $sessionid); +$details = file_prepare_standard_editor( + $details, + 'details', + $editoroptions, + $modulecontext, + 'mod_facetoface', + 'session', + $sessionid +); -$mform = new mod_facetoface_session_form(null, compact('id', 'facetoface', 'f', 's', 'c', 'nbdays', 'customfields', 'course', 'editoroptions')); +$mform = new mod_facetoface_session_form( + null, + compact('id', 'facetoface', 'f', 's', 'c', 'nbdays', 'customfields', 'course', 'editoroptions') +); if ($mform->is_cancelled()) { redirect($returnurl); } if ($fromform = $mform->get_data()) { // Form submitted. - if (empty($fromform->submitbutton)) { throw new moodle_exception('error:unknownbuttonclicked', 'facetoface', $returnurl); } @@ -165,13 +172,13 @@ $fromform->discountcost = 0; } - $sessiondates = array(); + $sessiondates = []; for ($i = 0; $i < $fromform->date_repeats; $i++) { if (!empty($fromform->datedelete[$i])) { continue; // Skip this date. } - if (!empty($fromform->timestart[$i]) and !empty($fromform->timefinish[$i])) { + if (!empty($fromform->timestart[$i]) && !empty($fromform->timefinish[$i])) { $date = new stdClass(); $date->timestart = $fromform->timestart[$i]; $date->timefinish = $fromform->timefinish[$i]; @@ -195,7 +202,7 @@ $transaction = $DB->start_delegated_transaction(); $update = false; - if (!$c and $session != null) { + if (!$c && $session != null) { $update = true; $sessionid = $session->id; @@ -204,10 +211,10 @@ $transaction->force_transaction_rollback(); // Logging and events trigger. - $params = array( + $params = [ 'context' => $modulecontext, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\update_session_failed::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -225,10 +232,10 @@ $transaction->force_transaction_rollback(); // Logging and events trigger. - $params = array( + $params = [ 'context' => $modulecontext, - 'objectid' => $facetoface->id - ); + 'objectid' => $facetoface->id, + ]; $event = \mod_facetoface\event\add_session_failed::create($params); $event->add_record_snapshot('facetoface', $facetoface); $event->trigger(); @@ -262,23 +269,21 @@ // Update calendar entries. facetoface_update_calendar_entries($session, $facetoface); if ($update) { - // Logging and events trigger. - $params = array( + $params = [ 'context' => $modulecontext, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\update_session::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' => $modulecontext, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\add_session::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -287,15 +292,30 @@ $transaction->allow_commit(); - $data = file_postupdate_standard_editor($fromform, 'details', $editoroptions, $modulecontext, 'mod_facetoface', 'session', $session->id); - $DB->set_field('facetoface_sessions', 'details', $data->details, array('id' => $session->id)); + $data = file_postupdate_standard_editor( + $fromform, + 'details', + $editoroptions, + $modulecontext, + 'mod_facetoface', + 'session', + $session->id + ); + $DB->set_field('facetoface_sessions', 'details', $data->details, ['id' => $session->id]); redirect($returnurl); } else if ($session != null) { // Edit mode. - // Set values for the form. $toform = new stdClass(); - $toform = file_prepare_standard_editor($details, 'details', $editoroptions, $modulecontext, 'mod_facetoface', 'session', $session->id); + $toform = file_prepare_standard_editor( + $details, + 'details', + $editoroptions, + $modulecontext, + 'mod_facetoface', + 'session', + $session->id + ); $toform->datetimeknown = (1 == $session->datetimeknown); $toform->capacity = $session->capacity; @@ -340,7 +360,6 @@ $pagetitle = format_string($facetoface->name); - $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); @@ -352,7 +371,7 @@ if ($d) { $viewattendees = has_capability('mod/facetoface:viewattendees', $context); facetoface_print_session($session, $viewattendees); - $optionsyes = array('sesskey' => sesskey(), 's' => $session->id, 'd' => 1, 'confirm' => 1); + $optionsyes = ['sesskey' => sesskey(), 's' => $session->id, 'd' => 1, 'confirm' => 1]; echo $OUTPUT->confirm(get_string('deletesessionconfirm', 'facetoface', format_string($facetoface->name)), new moodle_url('sessions.php', $optionsyes), new moodle_url($returnurl)); diff --git a/settings.php b/settings.php index 121f42d..8f34543 100644 --- a/settings.php +++ b/settings.php @@ -43,7 +43,7 @@ )); // Load roles. -$choices = array(); +$choices = []; if ($roles = role_fix_names(get_all_roles(), context_system::instance())) { foreach ($roles as $role) { $choices[$role->id] = format_string($role->localname); @@ -54,7 +54,7 @@ 'facetoface/session_roles', get_string('setting:sessionroles_caption', 'facetoface'), get_string('setting:sessionroles', 'facetoface'), - array(), + [], $choices )); @@ -138,11 +138,15 @@ // List of user profile fields to optionally be included in attendees export. -$settings->add(new admin_setting_heading('facetoface_attendeesexporttofile_header', get_string('attendeesexporttofileheading', 'facetoface'), '')); +$settings->add(new admin_setting_heading( + 'facetoface_attendeesexporttofile_header', + get_string('attendeesexporttofileheading', 'facetoface'), + '' +)); // Load profile fields. // Basic fields. -$choices = array( +$choices = [ 'middlename' => new lang_string('middlename'), 'alternatename' => new lang_string('alternatename'), 'username' => new lang_string('username'), @@ -157,26 +161,27 @@ 'lang' => new lang_string('language'), 'firstnamephonetic' => new lang_string('firstnamephonetic'), 'lastnamephonetic' => new lang_string('lastnamephonetic'), -); +]; // Custom profile fields. $profilefields = profile_get_custom_fields(); foreach ($profilefields as $field) { - $choices['profile_field_' . $field->shortname] = format_string($field->name) . ' (' . get_string('customfield', 'customfield'). ')'; + $choices['profile_field_' . $field->shortname] = format_string($field->name) + . ' (' . get_string('customfield', 'customfield'). ')'; } $settings->add(new admin_setting_configmultiselect( 'facetoface_attendeesexportfields', new lang_string('setting:attendeesexportfields_caption', 'facetoface'), new lang_string('setting:attendeesexportfields', 'facetoface'), - array(), + [], $choices )); // List of existing custom fields. $html = facetoface_list_of_customfields(); $html .= html_writer::start_tag('p'); -$url = new moodle_url('/mod/facetoface/customfield.php', array('id' => 0)); +$url = new moodle_url('/mod/facetoface/customfield.php', ['id' => 0]); $html .= html_writer::link($url, get_string('addnewfieldlink', 'facetoface')); $html .= html_writer::end_tag('p'); @@ -185,7 +190,7 @@ // List of existing site notices. $html = facetoface_list_of_sitenotices(); $html .= html_writer::start_tag('p'); -$url = new moodle_url('/mod/facetoface/sitenotice.php', array('id' => 0)); +$url = new moodle_url('/mod/facetoface/sitenotice.php', ['id' => 0]); $html .= html_writer::link($url, get_string('addnewnoticelink', 'facetoface')); $html .= html_writer::end_tag('p'); diff --git a/signup.php b/signup.php index 6fefced..ad4dd14 100644 --- a/signup.php +++ b/signup.php @@ -37,10 +37,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)) { @@ -60,7 +60,7 @@ $pagetitle = format_string($facetoface->name); $PAGE->set_cm($cm); -$PAGE->set_url('/mod/facetoface/signup.php', array('s' => $s, 'backtoallsessions' => $backtoallsessions)); +$PAGE->set_url('/mod/facetoface/signup.php', ['s' => $s, 'backtoallsessions' => $backtoallsessions]); $PAGE->set_title($pagetitle); $PAGE->set_heading($course->fullname); @@ -95,19 +95,17 @@ $isbulksignup = $facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_ACTIVITY; if ($fromform = $mform->get_data()) { // Form submitted. - if (empty($fromform->submitbutton)) { throw new moodle_exception('error:unknownbuttonclicked', 'facetoface', $returnurl); } // User can not update Manager's email (depreciated functionality). if (!empty($fromform->manageremail)) { - // Logging and events trigger. - $params = array( + $params = [ 'context' => $contextmodule, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\update_manageremail_failed::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -118,7 +116,6 @@ if (!$session->datetimeknown) { $statuscode = MDL_F2F_STATUS_WAITLISTED; } else if (facetoface_get_num_attendees($session->id) < $session->capacity) { - // Save available. $statuscode = MDL_F2F_STATUS_BOOKED; } else { @@ -136,7 +133,8 @@ } // This shouldn't happen. Bulk signup can only be enabled when multiple signups are allowed. - if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_SINGLE && facetoface_get_user_submissions($facetoface->id, $USER->id)) { + if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_SINGLE + && facetoface_get_user_submissions($facetoface->id, $USER->id)) { throw new moodle_exception('alreadysignedup', 'facetoface', $returnurl); } @@ -144,12 +142,21 @@ throw new moodle_exception('error:manageremailaddressmissing', 'facetoface', $returnurl); } - if ($submissionid = facetoface_user_signup($session, $facetoface, $course, $fromform->discountcode, $fromform->notificationtype, $statuscode, false, false)) { + if ($submissionid = facetoface_user_signup( + $session, + $facetoface, + $course, + $fromform->discountcode, + $fromform->notificationtype, + $statuscode, + false, + false + )) { // Logging and events trigger. - $params = array( + $params = [ 'context' => $contextmodule, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\signup_success::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -163,17 +170,24 @@ if (!facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) { throw new moodle_exception('sessionisfull', 'facetoface', $returnurl); - } else if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_SINGLE && facetoface_get_user_submissions($facetoface->id, $USER->id)) { + } else if ($facetoface->signuptype == MOD_FACETOFACE_SIGNUP_SINGLE + && facetoface_get_user_submissions($facetoface->id, $USER->id)) { throw new moodle_exception('alreadysignedup', 'facetoface', $returnurl); } else if (facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id)) { throw new moodle_exception('error:manageremailaddressmissing', 'facetoface', $returnurl); - } else if ($submissionid = facetoface_user_signup($session, $facetoface, $course, $fromform->discountcode, $fromform->notificationtype, $statuscode)) { - + } else if ($submissionid = facetoface_user_signup( + $session, + $facetoface, + $course, + $fromform->discountcode, + $fromform->notificationtype, + $statuscode + )) { // Logging and events trigger. - $params = array( + $params = [ 'context' => $contextmodule, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\signup_success::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -190,12 +204,11 @@ $timemessage = 4; redirect($returnurl, $message, $timemessage); } else { - // Logging and events trigger. - $params = array( + $params = [ 'context' => $contextmodule, - 'objectid' => $session->id - ); + 'objectid' => $session->id, + ]; $event = \mod_facetoface\event\signup_failed::create($params); $event->add_record_snapshot('facetoface_sessions', $session); $event->add_record_snapshot('facetoface', $facetoface); @@ -206,7 +219,6 @@ redirect($returnurl); } else if ($manageremail !== false) { - // Set values for the form. $toform = new stdClass(); $toform->manageremail = $manageremail; @@ -243,9 +255,6 @@ if (!$isbulksignup && !$signedup && !facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) { throw new moodle_exception('sessionisfull', 'facetoface', $returnurl); - echo $OUTPUT->box_end(); - echo $OUTPUT->footer($course); - exit; } if (!$isbulksignup) { @@ -254,30 +263,37 @@ if (!$isbulksignup && $signedup) { if (!($session->datetimeknown && facetoface_has_session_started($session, $timenow)) && $session->allowcancellations) { - // Cancellation link. - $cancellationurl = new moodle_url('cancelsignup.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions)); - echo html_writer::link($cancellationurl, get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface'))); + $cancellationurl = new moodle_url('cancelsignup.php', ['s' => $session->id, 'backtoallsessions' => $backtoallsessions]); + echo html_writer::link( + $cancellationurl, + get_string('cancelbooking', 'facetoface'), + ['title' => get_string('cancelbooking', 'facetoface')] + ); echo ' – '; } // See attendees link. if ($viewattendees) { - $attendeesurl = new moodle_url('attendees.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions)); - echo html_writer::link($attendeesurl, get_string('seeattendees', 'facetoface'), array('title' => get_string('seeattendees', 'facetoface'))); + $attendeesurl = new moodle_url('attendees.php', ['s' => $session->id, 'backtoallsessions' => $backtoallsessions]); + echo html_writer::link( + $attendeesurl, + get_string('seeattendees', 'facetoface'), + ['title' => get_string('seeattendees', 'facetoface')] + ); } - echo html_writer::empty_tag('br') . html_writer::link($returnurl, get_string('goback', 'facetoface'), array('title' => get_string('goback', 'facetoface'))); + echo html_writer::empty_tag('br'); + echo html_writer::link($returnurl, get_string('goback', 'facetoface'), ['title' => get_string('goback', 'facetoface')]); } $managerrequired = facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id); if (!$signedup && $managerrequired) { - // Don't allow signup to proceed if a manager is required. // Check to see if the user has a managers email set. echo html_writer::tag('p', html_writer::tag('strong', get_string('error:manageremailaddressmissing', 'facetoface'))); - echo html_writer::empty_tag('br') . html_writer::link($returnurl, get_string('goback', 'facetoface'), array('title' => get_string('goback', 'facetoface'))); - + echo html_writer::empty_tag('br'); + echo html_writer::link($returnurl, get_string('goback', 'facetoface'), ['title' => get_string('goback', 'facetoface')]); } $hascap = has_capability('mod/facetoface:signup', $context); @@ -286,7 +302,7 @@ echo html_writer::empty_tag('br') . html_writer::link( $returnurl, get_string('goback', 'facetoface'), - array('title' => get_string('goback', 'facetoface')) + ['title' => get_string('goback', 'facetoface')] ); } diff --git a/sitenotice.php b/sitenotice.php index b610cc6..f09ae40 100644 --- a/sitenotice.php +++ b/sitenotice.php @@ -37,10 +37,10 @@ $notice = null; if ($id > 0) { - $notice = $DB->get_record('facetoface_notice', array('id' => $id)); + $notice = $DB->get_record('facetoface_notice', ['id' => $id]); } -$PAGE->set_url('/mod/facetoface/sitenotice.php', array('id' => $id, 'd' => $d, 'confirm' => $confirm)); +$PAGE->set_url('/mod/facetoface/sitenotice.php', ['id' => $id, 'd' => $d, 'confirm' => $confirm]); admin_externalpage_setup('managemodules'); // This is hacky, tehre should be a special hidden page for it. @@ -70,7 +70,7 @@ $info = new stdClass(); $info->name = format_string($notice->name); $info->text = format_text($notice->text, FORMAT_HTML); - $optionsyes = array('id' => $id, 'sesskey' => $USER->sesskey, 'd' => 1, 'confirm' => 1); + $optionsyes = ['id' => $id, 'sesskey' => $USER->sesskey, 'd' => 1, 'confirm' => 1]; echo $OUTPUT->confirm(get_string('noticedeleteconfirm', 'facetoface', $info), new moodle_url("sitenotice.php", $optionsyes), new moodle_url($returnurl)); @@ -78,8 +78,8 @@ exit; } else { $transaction = $DB->start_delegated_transaction(); - $DB->delete_records('facetoface_notice', array('id' => $id)); - $DB->delete_records('facetoface_notice_data', array('noticeid' => $id)); + $DB->delete_records('facetoface_notice', ['id' => $id]); + $DB->delete_records('facetoface_notice_data', ['noticeid' => $id]); $transaction->allow_commit(); redirect($returnurl); } @@ -93,13 +93,10 @@ } if ($fromform = $mform->get_data()) { // Form submitted. - if (empty($fromform->submitbutton)) { throw new moodle_exception('error:unknownbuttonclicked', 'facetoface', $returnurl); } - - $todb = new stdClass(); $todb->name = trim($fromform->name); $todb->text = trim($fromform->text['text']); @@ -122,7 +119,6 @@ } $transaction->allow_commit(); redirect($returnurl); - } else if ($notice != null) { // Edit mode. // Set values for the form. $toform = new stdClass(); diff --git a/styles.css b/styles.css index fec1821..ecb05e4 100644 --- a/styles.css +++ b/styles.css @@ -63,3 +63,7 @@ body#page-mod-facetoface-view div#page-content .formlocation { float: right; margin-bottom: 6px; } + +.path-mod-facetoface .table-responsive table.f2fbookingsuploadlist .c1 { + width: auto; +} diff --git a/tests/custom_completion_test.php b/tests/custom_completion_test.php index 1646551..2a175e1 100644 --- a/tests/custom_completion_test.php +++ b/tests/custom_completion_test.php @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace mod_facetoface\completion; +namespace mod_facetoface; + +use mod_facetoface\completion\custom_completion; /** * Test for attendance completion in facetoface. @@ -25,6 +27,7 @@ * @covers \mod_facetoface\completion\custom_completion */ class custom_completion_test extends \advanced_testcase { + public function setUp(): void { $this->resetAfterTest(); } @@ -41,31 +44,35 @@ public function test_completionattendance_disabled() { $facetoface = $generator->create_instance([ 'course' => $course->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, - 'completionattendance' => 0]); + 'completionattendance' => 0, + ]); $cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id); $this->setAdminUser(); $cm = \cm_info::create($cm); - $customcompletion = new custom_completion($cm, (int)$student->id); + $customcompletion = new custom_completion($cm, (int) $student->id); try { $customcompletion->get_state('completionattendance'); $this->fail('Exception expected'); } catch (\moodle_exception $ex) { - $this->assertStringContainsString('error/Custom completion rule \'completionattendance\' is not used by this activity', $ex->getMessage()); + $this->assertStringContainsString( + 'error/Custom completion rule \'completionattendance\' is not used by this activity', + $ex->getMessage() + ); } } - public function completionattendance_provider(): array { + public static function completionattendance_provider(): array { global $CFG, $DB; require_once("$CFG->dirroot/mod/facetoface/lib.php"); return [ 'Full attendance' => [ - MDL_F2F_STATUS_FULLY_ATTENDED, COMPLETION_INCOMPLETE, COMPLETION_COMPLETE + MDL_F2F_STATUS_FULLY_ATTENDED, COMPLETION_INCOMPLETE, COMPLETION_COMPLETE, ], 'Partial attendance' => [ - MDL_F2F_STATUS_PARTIALLY_ATTENDED, COMPLETION_COMPLETE, COMPLETION_COMPLETE + MDL_F2F_STATUS_PARTIALLY_ATTENDED, COMPLETION_COMPLETE, COMPLETION_COMPLETE, ], ]; } @@ -92,53 +99,54 @@ public function test_completionattendance($completionattendance, $partiastate, $ $facetoface = $generator->create_instance([ 'course' => $course->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, - 'completionattendance' => $completionattendance]); + 'completionattendance' => $completionattendance, + ]); $cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id); $this->getDataGenerator()->enrol_user($student->id, $course->id, 'student'); $this->setAdminUser(); $cm = \cm_info::create($cm); - $customcompletion = new custom_completion($cm, (int)$student->id); + $customcompletion = new custom_completion($cm, (int) $student->id); $this->assertSame(COMPLETION_INCOMPLETE, $customcompletion->get_state('completionattendance')); $now = time(); $session = $generator->create_session([ 'facetoface' => $facetoface->id, 'sessiondates' => [ - ['timestart' => $now - 3 * DAYSECS, 'timefinish' => $now - 2 * DAYSECS] - ] + ['timestart' => $now - 3 * DAYSECS, 'timefinish' => $now - 2 * DAYSECS], + ], ]); $cm = \cm_info::create($cm); - $customcompletion = new custom_completion($cm, (int)$student->id); + $customcompletion = new custom_completion($cm, (int) $student->id); $this->assertSame(COMPLETION_INCOMPLETE, $customcompletion->get_state('completionattendance')); facetoface_user_signup($session, $facetoface, $course, '', MDL_F2F_BOTH, MDL_F2F_STATUS_BOOKED, $student->id, false); $signup = $DB->get_record('facetoface_signups', ['sessionid' => $session->id, 'userid' => $student->id], '*', MUST_EXIST); $cm = \cm_info::create($cm); - $customcompletion = new custom_completion($cm, (int)$student->id); + $customcompletion = new custom_completion($cm, (int) $student->id); $this->assertSame(COMPLETION_INCOMPLETE, $customcompletion->get_state('completionattendance')); - $result = facetoface_take_attendance((object)[ + $result = facetoface_take_attendance((object) [ 's' => $session->id, 'submissionid_' . $signup->id => MDL_F2F_STATUS_PARTIALLY_ATTENDED, ]); $this->assertTrue($result); $cm = \cm_info::create($cm); - $customcompletion = new custom_completion($cm, (int)$student->id); + $customcompletion = new custom_completion($cm, (int) $student->id); $this->assertSame($partiastate, $customcompletion->get_state('completionattendance')); - $result = facetoface_take_attendance((object)[ + $result = facetoface_take_attendance((object) [ 's' => $session->id, 'submissionid_' . $signup->id => MDL_F2F_STATUS_FULLY_ATTENDED, ]); $this->assertTrue($result); $cm = \cm_info::create($cm); - $customcompletion = new custom_completion($cm, (int)$student->id); + $customcompletion = new custom_completion($cm, (int) $student->id); $this->assertSame($fullstate, $customcompletion->get_state('completionattendance')); } } diff --git a/tests/facetoface_test.php b/tests/facetoface_test.php index 462b9d5..a313d1a 100644 --- a/tests/facetoface_test.php +++ b/tests/facetoface_test.php @@ -24,11 +24,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - -global $CFG; - -require_once($CFG->dirroot . '/course/modlib.php'); +namespace mod_facetoface; /** * Class for unit testing mod_facetoface. @@ -37,14 +33,17 @@ * @author Ghaly Marc-Alexandre * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class facetoface_test extends advanced_testcase { +class facetoface_test extends \advanced_testcase { + /** * Test to check facetoface is added properly. * * @covers \facetoface_add_instance */ public function test_add_facetofaceactivity() { - global $DB; + global $DB, $CFG; + + require_once($CFG->dirroot . '/course/modlib.php'); $this->resetAfterTest(); $this->setAdminUser(); diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 8650c8c..de1a19d 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -23,8 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - class mod_facetoface_generator extends testing_module_generator { /** @@ -76,7 +74,7 @@ public function create_instance($record = null, array $options = null) { public function create_session($record): stdClass { global $DB, $CFG; require_once("$CFG->dirroot/mod/facetoface/lib.php"); - $record = (object)(array)$record; + $record = (object) (array) $record; if (empty($record->facetoface) && !empty($record->facetofaceid)) { $record->facetoface = $record->facetofaceid; @@ -98,16 +96,16 @@ public function create_session($record): stdClass { $sessiondate = new stdClass(); $sessiondate->timestart = $time; $sessiondate->timefinish = $time + (DAYSECS * 2); - $sessiondates = array($sessiondate); + $sessiondates = [$sessiondate]; } else { $sessiondates = array_map(function ($date): stdClass { if (is_number($date)) { $sessiondate = new stdClass(); - $sessiondate->timestart = (int)$date; - $sessiondate->timefinish = (int)$date + (DAYSECS * 2); + $sessiondate->timestart = (int) $date; + $sessiondate->timefinish = (int) $date + (DAYSECS * 2); return $sessiondate; } else { - return (object)(array)$date; + return (object) (array) $date; } }, $record->sessiondates); unset($record->sessiondates); diff --git a/tests/generator_test.php b/tests/generator_test.php index 8e8dfcd..8ffc233 100644 --- a/tests/generator_test.php +++ b/tests/generator_test.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace mod_facetoface\completion; +namespace mod_facetoface; /** * Test for attendance completion in facetoface. @@ -25,6 +25,7 @@ * @covers \mod_facetoface_generator */ class generator_test extends \advanced_testcase { + public function setUp(): void { $this->resetAfterTest(); } @@ -76,9 +77,9 @@ public function test_create_instance() { 'signuptype' => '0', 'multiplesignupmethod' => '0', 'completionattendance' => '0', - 'cmid' => (int)$cm->id, + 'cmid' => (int) $cm->id, ]; - $this->assertSame($expected, (array)$facetoface); + $this->assertSame($expected, (array) $facetoface); } public function test_create_session() { @@ -123,8 +124,8 @@ public function test_create_session() { 'discountcost' => '11', 'allowcancellations' => '0', 'sessiondates' => [ - ['timestart' => $now - 3 * DAYSECS, 'timefinish' => $now - 2 * DAYSECS] - ] + ['timestart' => $now - 3 * DAYSECS, 'timefinish' => $now - 2 * DAYSECS], + ], ]); $this->assertInstanceOf(\stdClass::class, $session2); $this->assertSame($facetoface->id, $session2->facetoface); @@ -141,8 +142,8 @@ public function test_create_session() { $this->assertIsArray($session2->sessiondates); $this->assertCount(1, $session2->sessiondates); $this->assertSame($session2->id, $session2->sessiondates[0]->sessionid); - $this->assertSame((string)($now - 3 * DAYSECS), $session2->sessiondates[0]->timestart); - $this->assertSame((string)($now - 2 * DAYSECS), $session2->sessiondates[0]->timefinish); + $this->assertSame((string) ($now - 3 * DAYSECS), $session2->sessiondates[0]->timestart); + $this->assertSame((string) ($now - 2 * DAYSECS), $session2->sessiondates[0]->timefinish); $now = time(); $this->setCurrentTimeStart(); @@ -173,7 +174,7 @@ public function test_create_session() { $this->assertIsArray($session3->sessiondates); $this->assertCount(1, $session3->sessiondates); $this->assertSame($session3->id, $session3->sessiondates[0]->sessionid); - $this->assertSame((string)($now + 10 * DAYSECS), $session3->sessiondates[0]->timestart); - $this->assertSame((string)($now + 11 * DAYSECS), $session3->sessiondates[0]->timefinish); + $this->assertSame((string) ($now + 10 * DAYSECS), $session3->sessiondates[0]->timestart); + $this->assertSame((string) ($now + 11 * DAYSECS), $session3->sessiondates[0]->timefinish); } } diff --git a/tests/helper_test.php b/tests/helper_test.php index b55a2c3..f424e6d 100644 --- a/tests/helper_test.php +++ b/tests/helper_test.php @@ -23,6 +23,7 @@ * @author Andrew Madden * @copyright 2023 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \mod_facetoface\helper */ class helper_test extends \advanced_testcase { diff --git a/tests/session_test.php b/tests/session_test.php index 80adfe1..83ba463 100644 --- a/tests/session_test.php +++ b/tests/session_test.php @@ -103,7 +103,7 @@ public function test_get_readable_session_time_with_multiple_date() { * Test getting full session dates and times with user's timezone. */ public function test_get_readable_session_time_with_users_timezone() { - set_config( 'displaysessiontimezones', 1, 'facetoface'); + set_config('displaysessiontimezones', 1, 'facetoface'); $date = (object) [ 'timestart' => $this->starttime, 'timefinish' => $this->starttime + 80 * HOURSECS, diff --git a/tests/upload_test.php b/tests/upload_test.php new file mode 100644 index 0000000..f4be435 --- /dev/null +++ b/tests/upload_test.php @@ -0,0 +1,392 @@ +. + +namespace mod_facetoface; + +use mod_facetoface\booking_manager; +use lang_string; + +/** + * Test the upload helper class. + * + * @package mod_facetoface + * @author Kevin Pham + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \mod_facetoface\booking_manager + */ +class upload_test extends \advanced_testcase { + + /** + * This method runs before every test. + */ + public function setUp(): void { + $this->resetAfterTest(); + } + + /** + * Test permissions to ensure a user can only for sessions they have editing rights to. + * - those who see the edit button and actions on the view page. + */ + public function test_session_validation() { + /** @var \mod_facetoface_generator $generator */ + $generator = $this->getDataGenerator()->get_plugin_generator('mod_facetoface'); + + $course = $this->getDataGenerator()->create_course(); + $facetoface = $generator->create_instance(['course' => $course->id]); + // Generate users. + $student1 = $this->getDataGenerator()->create_and_enrol($course, 'student'); + $student2 = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + $this->setCurrentTimeStart(); + $now = time(); + // Overbooking a session should not be allowed, if allowoverbook is set to 0. + $nooverbooksession = $generator->create_session([ + 'facetoface' => $facetoface->id, + 'capacity' => '1', + 'allowoverbook' => '0', + 'details' => 'xyz', + 'duration' => '1.5', // One and half hours. + 'normalcost' => '111', + 'discountcost' => '11', + 'allowcancellations' => '0', + 'sessiondates' => [ + ['timestart' => $now + 3 * DAYSECS, 'timefinish' => $now + 2 * DAYSECS], + ], + ]); + $overbookablesession = $generator->create_session([ + 'facetoface' => $facetoface->id, + 'capacity' => '1', + 'allowoverbook' => '1', + 'details' => 'xyz', + 'duration' => '1.5', // One and half hours. + 'normalcost' => '111', + 'discountcost' => '11', + 'allowcancellations' => '0', + 'sessiondates' => [ + ['timestart' => $now + 3 * DAYSECS, 'timefinish' => $now + 2 * DAYSECS], + ], + ]); + + $bm = new booking_manager($facetoface->id); + + // Expect an error for overbooking. + $records = [ + // Test user does not exist. + (object) [ + 'email' => $student1->email, + 'session' => $nooverbooksession->id, + ], + // Test user exist, but is not enrolled into the course. + (object) [ + 'email' => $student2->email, + 'session' => $nooverbooksession->id, + ], + ]; + $bm->load_from_array($records); + $errors = $bm->validate(); + $expectederr = new lang_string( + 'error:sessionoverbooked', + 'mod_facetoface', + (object) ['session' => $nooverbooksession->id, 'amount' => 1] + ); + $this->assertCount(1, $errors); + $this->assertEquals($expectederr, $errors[0][1]); + + // Expect no errors for a session which allows overbookings. + $records = [ + // Test user does not exist. + (object) [ + 'email' => $student1->email, + 'session' => $overbookablesession->id, + ], + // Test user exist, but is not enrolled into the course. + (object) [ + 'email' => $student2->email, + 'session' => $overbookablesession->id, + ], + ]; + $bm->load_from_array($records); + $errors = $bm->validate(); + $this->assertCount(0, $errors); + } + + /** + * Test user validation to ensure that details and fields are valid and can be booked into a session. + */ + public function test_user_validation() { + /** @var \mod_facetoface_generator $generator */ + $generator = $this->getDataGenerator()->get_plugin_generator('mod_facetoface'); + + $course = $this->getDataGenerator()->create_course(); + $facetoface = $generator->create_instance(['course' => $course->id]); + // Generate users. + $user = $this->getDataGenerator()->create_user(); + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + $this->setCurrentTimeStart(); + $now = time(); + $session = $generator->create_session([ + 'facetoface' => $facetoface->id, + 'capacity' => '3', + 'allowoverbook' => '0', + 'details' => 'xyz', + 'duration' => '1.5', // One and half hours. + 'normalcost' => '111', + 'discountcost' => '11', + 'allowcancellations' => '0', + 'sessiondates' => [ + ['timestart' => $now + 3 * DAYSECS, 'timefinish' => $now + 2 * DAYSECS], + ], + ]); + + $bm = new booking_manager($facetoface->id); + + $records = [ + // Test user does not exist. + (object) [ + 'email' => 'whoami@example.com', + 'session' => $session->id, + 'status' => '', + 'notificationtype' => '', + 'discountcode' => '', + ], + // Test user exist, but is not enrolled into the course. + (object) [ + 'email' => $user->email, + 'session' => $session->id, + 'status' => '', + 'notificationtype' => '', + 'discountcode' => '', + ], + // Test student who is enrolled into the course (no issues). + (object) [ + 'email' => $student->email, + 'session' => $session->id, + 'status' => '', + 'notificationtype' => '', + 'discountcode' => '', + ], + // Test invalid options. + (object) [ + 'email' => $student->email, + 'session' => $session->id, + 'status' => 'helloworld', + 'notificationtype' => 'phone', + 'discountcode' => '', + ], + ]; + + $bm->load_from_array($records); + + $errors = $bm->validate(); + $this->assertTrue( + $this->check_row_validation_error_exists( + $errors, + 1, + new lang_string('error:userdoesnotexist', 'mod_facetoface', $records[0]->email) + ), + 'Expecting user to not exist.' + ); + + $this->assertTrue( + $this->check_row_validation_error_exists( + $errors, + 2, + new lang_string('error:userisnotenrolledintocourse', 'mod_facetoface', $user->email) + ), + 'Expected error for user not enrolled in a course.' + ); + + $this->assertFalse( + $this->check_row_validation_error_exists( + $errors, + 3, + '' + ), + 'Expecting no specific errors for this user.' + ); + + $this->assertTrue( + $this->check_row_validation_error_exists( + $errors, + 4, + new lang_string('error:invalidnotificationtypespecified', 'mod_facetoface', $records[3]->notificationtype) + ), + 'Expecting notification type error, as an invalid type was provided.' + ); + + $this->assertTrue( + $this->check_row_validation_error_exists( + $errors, + 4, + new lang_string('error:invalidstatusspecified', 'mod_facetoface', $records[3]->status) + ), + 'Expecting status error, since the status should be either booked or cancelled.' + ); + } + + /** + * Helper function to check if a specific error exists in the array of errors. + * + * @param array $errors Array of errors. + * @param int $expectedrownumber Expected row number. + * @param string $expectederrormsg Expected error message. + * @return bool True if the error exists, false otherwise. + */ + private function check_row_validation_error_exists(array $errors, int $expectedrownumber, string $expectederrormsg): bool { + foreach ($errors as $error) { + // Note: row number is based on a CSV file human readable format, where there is a header and row data. + [$rownumber, $errormsg] = $error; + // Check if the error exists in the array. + if ($rownumber == $expectedrownumber && $errormsg == $expectederrormsg) { + return true; + } + } + return false; + } + + /** + * Test upload processing to ensure the happy path is working as expected, and users can be booked into a session. + */ + public function test_processing_booking() { + /** @var \mod_facetoface_generator $generator */ + $generator = $this->getDataGenerator()->get_plugin_generator('mod_facetoface'); + + $course = $this->getDataGenerator()->create_course(); + $facetoface = $generator->create_instance(['course' => $course->id]); + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + $this->setCurrentTimeStart(); + $now = time(); + $session = $generator->create_session([ + 'facetoface' => $facetoface->id, + 'capacity' => '3', + 'allowoverbook' => '0', + 'details' => 'xyz', + 'duration' => '1.5', // One and half hours. + 'normalcost' => '111', + 'discountcost' => '11', + 'allowcancellations' => '0', + 'sessiondates' => [ + ['timestart' => $now + 3 * DAYSECS, 'timefinish' => $now + 2 * DAYSECS], + ], + ]); + + $bm = new booking_manager($facetoface->id); + $record = (object) [ + 'email' => $student->email, + 'session' => $session->id, + 'status' => 'booked', + 'notificationtype' => 'ical', + 'discountcode' => 'MYSPECIALCODE', + ]; + $records = [$record]; + + $bm->load_from_array($records); + + $errors = $bm->validate(); + $this->assertEmpty($errors); + $this->assertTrue($bm->process()); + + // Check users are as expected. + $users = facetoface_get_attendees($session->id); + $this->assertCount(1, $users); + $this->assertEquals($record->email, current($users)->email); + $this->assertEquals($record->discountcode, current($users)->discountcode); + $this->assertEquals(MDL_F2F_ICAL, current($users)->notificationtype); + $this->assertEquals(MDL_F2F_STATUS_BOOKED, current($users)->statuscode); + + // Re-booking the same user shouldn't cause any isssues. Run the validate again and check. + $errors = $bm->validate(); + $this->assertEmpty($errors); + } + + /** + * Test upload processing to ensure the happy path is working as expected, and users can be cancelled from a session. + * + * To do this, we will book the user, then cancel them. There should be no + * errors, and we should confirm they are booked and are removed + * afterwards. + */ + public function test_processing_cancellation() { + /** @var \mod_facetoface_generator $generator */ + $generator = $this->getDataGenerator()->get_plugin_generator('mod_facetoface'); + + $course = $this->getDataGenerator()->create_course(); + $facetoface = $generator->create_instance(['course' => $course->id]); + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); + + $this->setCurrentTimeStart(); + $now = time(); + $session = $generator->create_session([ + 'facetoface' => $facetoface->id, + 'capacity' => '5', + 'allowoverbook' => '0', + 'details' => 'xyz', + 'duration' => '1.5', // One and half hours. + 'normalcost' => '111', + 'discountcost' => '11', + 'allowcancellations' => '0', + 'sessiondates' => [ + ['timestart' => $now + 3 * DAYSECS, 'timefinish' => $now + 2 * DAYSECS], + ], + ]); + + $bm = new booking_manager($facetoface->id); + $record = (object) [ + 'email' => $student->email, + 'session' => $session->id, + 'status' => 'booked', + ]; + $records = [$record]; + + $bm->load_from_array($records); + + $errors = $bm->validate(); + $this->assertEmpty($errors); + $this->assertTrue($bm->process()); + + // Check users are as expected. + $users = facetoface_get_attendees($session->id); + $this->assertCount(1, $users); + $this->assertEquals($record->email, current($users)->email); + $this->assertEquals(MDL_F2F_STATUS_BOOKED, current($users)->statuscode); + + // Now, let's cancel their booking via the booking manager. + $record = (object) [ + 'email' => $student->email, + 'session' => $session->id, + 'status' => 'cancelled', + ]; + $records = [$record]; + $bm->load_from_array($records); + + $errors = $bm->validate(); + $this->assertEmpty($errors); + $this->assertTrue($bm->process()); + + // Check the users are removed (since their booking was cancelled). + $users = facetoface_get_attendees($session->id); + $this->assertEmpty($users); + + // Check and ensure the users were properly cancelled. + $users = facetoface_get_cancellations($session->id); + $this->assertCount(1, $users); + $this->assertEquals($student->id, current($users)->id); + $this->assertNotEmpty(current($users)->timecancelled); + } +} diff --git a/upload.php b/upload.php new file mode 100644 index 0000000..c720401 --- /dev/null +++ b/upload.php @@ -0,0 +1,147 @@ +. + +/** + * Upload form for csv file to handle enrolment of bookings in bulk. + * + * @package mod_facetoface + * @author Kevin Pham + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../../config.php'); +require_once($CFG->dirroot . '/mod/facetoface/lib.php'); + +use core\output\notification; +use mod_facetoface\form\upload_bookings_form; +use mod_facetoface\form\confirm_bookings_form; +use mod_facetoface\booking_manager; +use mod_facetoface\event\csv_processed; + +$f = optional_param('f', 0, PARAM_INT); // The facetoface module ID. +$fileid = optional_param('fileid', 0, PARAM_INT); // The fileid of the file uploaded. +$validate = optional_param('validate', 0, PARAM_INT); // Whether or not the user wants to process the upload (after verification). +$process = optional_param('process', 0, PARAM_INT); // Whether or not the user wants to process the upload (after verification). +$step = optional_param('step', '', PARAM_ALPHA); // The current step in the process. + +if (!$facetoface = $DB->get_record('facetoface', ['id' => $f])) { + throw new moodle_exception('error:incorrectfacetofaceid', 'facetoface'); +} +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)) { + throw new moodle_exception('error:incorrectcoursemoduleid', 'facetoface'); +} + +require_course_login($course, true, $cm); +$context = context_course::instance($course->id); +$modulecontext = context_module::instance($cm->id); +require_capability('mod/facetoface:editsessions', $context); +require_capability('mod/facetoface:uploadbookings', $context); + +echo $OUTPUT->header(); + +// Render form, which should only consist of an upload element. +if ($validate) { + // Form submitted, but not ready for processing -> validate. + $heading = get_string('facetoface:validatebookings', 'facetoface'); + + $mform = new upload_bookings_form(null); + $data = $mform->get_data(); + $fileid = $data->csvfile ?: 0; + + $mform = new confirm_bookings_form(null, ['f' => $f, 'fileid' => $fileid]); + + $bm = new booking_manager($f); + $bm->load_from_file($fileid); + + // Validate entries. + $errors = $bm->validate(); + + // List out any issues in a table. + if (!empty($errors)) { + // Print summary statement. + echo \core\notification::error(get_string('error:bookingsuploadfileerrorsfound', 'mod_facetoface', count($errors))); + + $table = new html_table(); + $table->attributes['class'] = 'f2fbookingsuploadlist m-auto generaltable mb-2'; + + $table->head[] = get_string('uucsvline', 'tool_uploaduser'); + $table->head[] = get_string('status'); + $table->data = $errors; + + echo html_writer::tag('div', html_writer::table($table), ['class' => 'flexible-wrap mb-4']); + } else { + // Bonus: show a preview/summary for good records (e.g. 40 records will be processed). + echo \core\notification::success(get_string('facetoface:uploadreadytoprocess', 'mod_facetoface')); + } + + // Set form data to allow user to continue and process the uploaded file on their next form submit. +} else if ($process && $fileid && $f) { + // Form submitted, and ready for processing -> process. + $bm = new booking_manager($f); + $bm->load_from_file($fileid); + + // Validate entries. + $errors = $bm->validate(); + if (empty($errors)) { + // Process entries. + $bm->process(); + + // Logging and events trigger. + $params = [ + 'context' => $modulecontext, + 'objectid' => $f, + ]; + $event = \mod_facetoface\event\csv_processed::create($params); + $event->add_record_snapshot('facetoface_sessions', $session); + $event->add_record_snapshot('facetoface', $facetoface); + $event->trigger(); + + // Redirect back to start with notification. + redirect( + new moodle_url('/mod/facetoface/upload.php', ['f' => $f]), + get_string('facetoface:csvprocessed', 'mod_facetoface'), + null, + notification::NOTIFY_SUCCESS); + } + + $errmsg = get_string('error:bookingsuploadfileerrorsfound', 'mod_facetoface', count($errors)); + redirect( + new moodle_url('/mod/facetoface/upload.php', ['f' => $f]), + $errmsg, + null, + notification::NOTIFY_ERROR); +} else { + $mform = new upload_bookings_form(null); + $mform->set_data(['f' => $f, 'validate' => 1]); + + // Form not subumitted -> prep the form with current context (f2f module id). + $heading = get_string('facetoface:uploadbookings', 'facetoface'); +} + +$PAGE->set_url(new moodle_url('/mod/facetoface/upload.php', ['courseid' => $courseid, 'cmid' => $cm->id])); +$PAGE->set_context($context); +$PAGE->set_pagelayout('standard'); +$PAGE->set_title($heading); +$PAGE->set_heading($heading); + +$mform->display(); + +// Display footer. +echo $OUTPUT->footer(); diff --git a/version.php b/version.php index b588174..21eb0de 100644 --- a/version.php +++ b/version.php @@ -30,9 +30,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024030700; -$plugin->release = 2024030700; -$plugin->requires = 2023100900; // Requires 4.3 +$plugin->version = 2024050900; +$plugin->release = 2024050900; +$plugin->requires = 2023100900; // Requires 4.3. $plugin->component = 'mod_facetoface'; $plugin->maturity = MATURITY_STABLE; $plugin->supported = [403, 403]; diff --git a/view.php b/view.php index 807d86d..8953e8e 100644 --- a/view.php +++ b/view.php @@ -40,20 +40,20 @@ $download = optional_param('download', '', PARAM_ALPHA); // Download attendance. if ($id) { - if (!$cm = $DB->get_record('course_modules', array('id' => $id))) { + if (!$cm = $DB->get_record('course_modules', ['id' => $id])) { throw new moodle_exception('error:incorrectcoursemoduleid', 'facetoface'); } - if (!$course = $DB->get_record('course', array('id' => $cm->course))) { + if (!$course = $DB->get_record('course', ['id' => $cm->course])) { throw new moodle_exception('error:coursemisconfigured', 'facetoface'); } - if (!$facetoface = $DB->get_record('facetoface', array('id' => $cm->instance))) { + if (!$facetoface = $DB->get_record('facetoface', ['id' => $cm->instance])) { throw new moodle_exception('error:incorrectcoursemodule', 'facetoface'); } } else if ($f) { - if (!$facetoface = $DB->get_record('facetoface', array('id' => $f))) { + if (!$facetoface = $DB->get_record('facetoface', ['id' => $f])) { 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)) { @@ -64,7 +64,7 @@ } $context = context_module::instance($cm->id); -$PAGE->set_url('/mod/facetoface/view.php', array('id' => $cm->id)); +$PAGE->set_url('/mod/facetoface/view.php', ['id' => $cm->id]); $PAGE->set_context($context); $PAGE->set_cm($cm); $PAGE->set_pagelayout('standard'); @@ -79,10 +79,10 @@ require_capability('mod/facetoface:view', $context); // Logging and events trigger. -$params = array( +$params = [ 'context' => $context, - 'objectid' => $facetoface->id -); + 'objectid' => $facetoface->id, +]; $event = \mod_facetoface\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); $event->add_record_snapshot('course', $course); @@ -103,7 +103,7 @@ echo $OUTPUT->header(); -if (empty($cm->visible) and !has_capability('mod/facetoface:viewemptyactivities', $context)) { +if (empty($cm->visible) && !has_capability('mod/facetoface:viewemptyactivities', $context)) { notice(get_string('activityiscurrentlyhidden')); } echo $OUTPUT->box_start(); @@ -118,10 +118,10 @@ } $locations = get_locations($facetoface->id); if (count($locations) > 2) { - echo html_writer::start_tag('form', array('action' => 'view.php', 'method' => 'get', 'class' => 'formlocation')); + echo html_writer::start_tag('form', ['action' => 'view.php', 'method' => 'get', 'class' => 'formlocation']); echo html_writer::start_tag('div'); - echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'f', 'value' => $facetoface->id)); - echo html_writer::select($locations, 'location', $location, '', array('onchange' => 'this.form.submit();')); + echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'f', 'value' => $facetoface->id]); + echo html_writer::select($locations, 'location', $location, '', ['onchange' => 'this.form.submit();']); echo html_writer::end_tag('div'). html_writer::end_tag('form'); } @@ -129,14 +129,16 @@ if (has_capability('mod/facetoface:viewattendees', $context)) { echo $OUTPUT->heading(get_string('exportattendance', 'facetoface')); - echo html_writer::start_tag('form', array('action' => 'view.php', 'method' => 'get')); + echo html_writer::start_tag('form', ['action' => 'view.php', 'method' => 'get']); echo html_writer::start_tag('div'); - echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'f', 'value' => $facetoface->id)); + echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'f', 'value' => $facetoface->id]); echo get_string('format', 'facetoface') . ' '; - $formats = array('excel' => get_string('excelformat', 'facetoface'), - 'ods' => get_string('odsformat', 'facetoface')); + $formats = [ + 'excel' => get_string('excelformat', 'facetoface'), + 'ods' => get_string('odsformat', 'facetoface'), + ]; echo html_writer::select($formats, 'download', 'excel', ''); - echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('exporttofile', 'facetoface'))); + echo html_writer::empty_tag('input', ['type' => 'submit', 'value' => get_string('exporttofile', 'facetoface')]); echo html_writer::end_tag('div'). html_writer::end_tag('form'); } @@ -153,6 +155,7 @@ function print_session_list($courseid, $facetoface, $location) { $context = context_course::instance($courseid); $viewattendees = has_capability('mod/facetoface:viewattendees', $context); $editsessions = has_capability('mod/facetoface:editsessions', $context); + $uploadbookings = has_capability('mod/facetoface:uploadbookings', $context); $multiplesignups = $facetoface->signuptype == MOD_FACETOFACE_SIGNUP_MULTIPLE; $bulksignup = $facetoface->multiplesignupmethod == MOD_FACETOFACE_SIGNUP_MULTIPLE_PER_ACTIVITY; @@ -169,13 +172,12 @@ function print_session_list($courseid, $facetoface, $location) { $customfields = facetoface_get_session_customfields(); - $upcomingarray = array(); - $previousarray = array(); - $upcomingtbdarray = array(); + $upcomingarray = []; + $previousarray = []; + $upcomingtbdarray = []; if ($sessions = facetoface_get_sessions($facetoface->id, $location) ) { foreach ($sessions as $session) { - $sessionstarted = false; $sessionfull = false; $sessionwaitlisted = false; @@ -185,7 +187,7 @@ function print_session_list($courseid, $facetoface, $location) { $sessiondata->bookedsession = $multiplesignups ? ($bookedsessionmap[$session->id] ?? []) : $bookedsession; // Add custom fields to sessiondata. - $customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $session->id), '', 'fieldid, data'); + $customdata = $DB->get_records('facetoface_session_data', ['sessionid' => $session->id], '', 'fieldid, data'); $sessiondata->customfielddata = $customdata; // Is session waitlisted. @@ -233,12 +235,20 @@ function print_session_list($courseid, $facetoface, $location) { if ($editsessions) { $addsessionlink = html_writer::link( - new moodle_url('sessions.php', array('f' => $facetoface->id)), + new moodle_url('sessions.php', ['f' => $facetoface->id]), get_string('addsession', 'facetoface') ); echo html_writer::tag('p', $addsessionlink); } + if ($uploadbookings) { + $adduploadlink = html_writer::link( + new moodle_url('upload.php', ['f' => $facetoface->id]), + get_string('uploadbookings', 'facetoface') + ); + echo html_writer::tag('p', $adduploadlink); + } + // Previous sessions. if (!empty($previousarray)) { echo $OUTPUT->heading(get_string('previoussessions', 'facetoface')); @@ -255,9 +265,9 @@ function print_session_list($courseid, $facetoface, $location) { function get_locations($facetofaceid) { global $CFG, $DB; - $locationfieldid = $DB->get_field('facetoface_session_field', 'id', array('shortname' => 'location')); + $locationfieldid = $DB->get_field('facetoface_session_field', 'id', ['shortname' => 'location']); if (!$locationfieldid) { - return array(); + return []; } $sql = "SELECT DISTINCT d.data AS location @@ -266,7 +276,7 @@ function get_locations($facetofaceid) { JOIN {facetoface_session_data} d ON d.sessionid = s.id WHERE f.id = ? AND d.fieldid = ?"; - if ($records = $DB->get_records_sql($sql, array($facetofaceid, $locationfieldid))) { + if ($records = $DB->get_records_sql($sql, [$facetofaceid, $locationfieldid])) { $locationmenu[''] = get_string('alllocations', 'facetoface'); $i = 1; @@ -278,5 +288,5 @@ function get_locations($facetofaceid) { return $locationmenu; } - return array(); + return []; }