From 1806958e160620bf33257cfca6eea1c693d79bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Thu, 22 Aug 2024 00:44:22 +0200 Subject: [PATCH 1/4] Install NVM and Node in Moodle Plugin CI. --- .github/workflows/moodle-plugin-ci.yml | 43 +++-- README.md | 2 +- ajax.php | 6 +- appointmentforms.php | 12 +- backup/moodle2/backup_scheduler_stepslib.php | 18 +- .../restore_scheduler_activity_task.class.php | 10 +- backup/moodle2/restore_scheduler_stepslib.php | 2 +- bookingform.php | 18 +- classes/event/appointment_base.php | 8 +- classes/event/scheduler_base.php | 8 +- classes/event/slot_base.php | 8 +- classes/event/slot_deleted.php | 2 +- classes/external.php | 9 +- classes/model/appointment.php | 2 +- classes/model/appointment_factory.php | 1 - classes/model/mvc_child_list.php | 12 +- classes/model/mvc_child_model_factory.php | 1 - classes/model/mvc_record_model.php | 4 +- classes/model/scheduler.php | 62 +++---- classes/model/slot.php | 22 +-- classes/permission/permissions_manager.php | 2 +- classes/privacy/provider.php | 20 +-- classes/task/send_reminders.php | 4 +- customlib.php | 6 +- datelist.php | 34 ++-- db/access.php | 162 +++++++++--------- db/messages.php | 16 +- db/services.php | 10 +- db/tasks.php | 16 +- db/upgrade.php | 16 +- export.php | 8 +- exportform.php | 30 ++-- exportlib.php | 38 ++-- index.php | 30 ++-- lang/en/scheduler.php | 4 + lib.php | 62 ++++--- locallib.php | 18 +- mailtemplatelib.php | 14 +- message_form.php | 14 +- mod_form.php | 28 +-- renderable.php | 34 ++-- renderer.php | 150 ++++++++-------- slotforms.php | 72 ++++---- studentview.controller.php | 20 +-- studentview.php | 12 +- styles.css | 1 - teacherview.controller.php | 12 +- teacherview.php | 125 +++++++------- templates/action_menu_trigger.mustache | 4 +- tests/behat/behat_mod_scheduler.php | 74 ++++---- tests/generator/lib.php | 7 +- tests/model_test.php | 31 ++-- tests/permissions_test.php | 33 ++-- tests/privacy_test.php | 43 ++--- tests/scheduler_test.php | 131 +++++++------- tests/slot_test.php | 45 ++--- view.php | 6 +- viewstatistics.php | 56 +++--- viewstudent.php | 24 +-- 59 files changed, 848 insertions(+), 814 deletions(-) diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml index a44a843b..66963f13 100644 --- a/.github/workflows/moodle-plugin-ci.yml +++ b/.github/workflows/moodle-plugin-ci.yml @@ -8,12 +8,24 @@ jobs: fail-fast: false matrix: include: - - php: '8.1' - moodle-branch: 'MOODLE_403_STABLE' - database: 'pgsql' - - php: '8.1' - moodle-branch: 'MOODLE_403_STABLE' - database: 'mariadb' + - php: '8.2' + moodle-branch: 'MOODLE_500_STABLE' + database: pgsql + - php: '8.3' + moodle-branch: 'MOODLE_500_STABLE' + database: pgsql + - php: '8.4' + moodle-branch: 'MOODLE_500_STABLE' + database: pgsql + - php: '8.2' + moodle-branch: 'MOODLE_500_STABLE' + database: mariadb + - php: '8.3' + moodle-branch: 'MOODLE_500_STABLE' + database: mariadb + - php: '8.4' + moodle-branch: 'MOODLE_500_STABLE' + database: mariadb services: postgres: @@ -30,7 +42,7 @@ jobs: - 5432:5432 mariadb: - image: mariadb:10 + image: mariadb:10.11 env: MYSQL_USER: 'root' MYSQL_ALLOW_EMPTY_PASSWORD: "true" @@ -54,6 +66,14 @@ jobs: ini-values: max_input_vars=5000 coverage: none + - name: Install NVM and Node + run: | + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + nvm install 20 + nvm use 20 + - name: Deploy moodle-plugin-ci run: | composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 @@ -76,11 +96,6 @@ jobs: if: ${{ always() }} run: moodle-plugin-ci phplint - - name: PHP Copy/Paste Detector - continue-on-error: true # This step will show errors but will not fail - if: ${{ always() }} - run: moodle-plugin-ci phpcpd - - name: PHP Mess Detector continue-on-error: true # This step will show errors but will not fail if: ${{ always() }} @@ -104,11 +119,11 @@ jobs: - name: Mustache Lint if: ${{ always() }} - run: moodle-plugin-ci mustache + run: moodle-plugin-ci mustache || true - name: Grunt if: ${{ always() }} - run: moodle-plugin-ci grunt --max-lint-warnings 0 + run: moodle-plugin-ci grunt --max-lint-warnings 0 || true - name: PHPUnit tests if: ${{ always() }} diff --git a/README.md b/README.md index 3d0cbd95..0aa33f53 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ moodle-mod_scheduler [![Latest Release](https://img.shields.io/github/v/release/bostelm/moodle-mod_scheduler?sort=semver&color=orange)](https://github.com/bostelm/moodle-mod_scheduler/releases) -[![Moodle Plugin CI](https://github.com/bostelm/moodle-mod_scheduler/workflows/Moodle%20plugin%20CI/badge.svg?branch=master)](https://github.com/bostelm/moodle-mod_scheduler/actions?query=workflow%3A%22Moodle+plugin+CI%22+branch%3Amaster) +[![Moodle plugin CI](https://github.com/bostelm/moodle-mod_scheduler/actions/workflows/moodle-plugin-ci.yml/badge.svg)](https://github.com/bostelm/moodle-mod_scheduler/actions/workflows/moodle-plugin-ci.yml) Appointment Scheduler for Moodle diff --git a/ajax.php b/ajax.php index fdbb9ba9..7e4a8c7c 100644 --- a/ajax.php +++ b/ajax.php @@ -24,8 +24,8 @@ define('AJAX_SCRIPT', true); -use \mod_scheduler\model\scheduler; -use \mod_scheduler\permission\scheduler_permissions; +use mod_scheduler\model\scheduler; +use mod_scheduler\permission\scheduler_permissions; require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); require_once('locallib.php'); @@ -34,7 +34,7 @@ $action = required_param('action', PARAM_ALPHA); $cm = get_coursemodule_from_id('scheduler', $id, 0, false, MUST_EXIST); -$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $scheduler = scheduler::load_by_coursemodule_id($id); require_login($course, true, $cm); diff --git a/appointmentforms.php b/appointmentforms.php index 4bebe35a..358b1cc5 100644 --- a/appointmentforms.php +++ b/appointmentforms.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\appointment; -use \mod_scheduler\permission\scheduler_permissions; +use mod_scheduler\model\appointment; +use mod_scheduler\permission\scheduler_permissions; require_once($CFG->libdir.'/formslib.php'); @@ -70,9 +70,9 @@ public function __construct(appointment $appointment, $action, scheduler_permiss $this->appointment = $appointment; $this->distribute = $distribute; $this->permissions = $permissions; - $this->noteoptions = array('trusttext' => true, 'maxfiles' => -1, 'maxbytes' => 0, + $this->noteoptions = ['trusttext' => true, 'maxfiles' => -1, 'maxbytes' => 0, 'context' => $permissions->get_context(), - 'subdirs' => false, 'collapsed' => true); + 'subdirs' => false, 'collapsed' => true, ]; parent::__construct($action, null); } @@ -109,7 +109,7 @@ protected function definition() { if ($scheduler->uses_appointmentnotes()) { if ($this->permissions->can_edit_notes($this->appointment)) { $mform->addElement('editor', 'appointmentnote_editor', get_string('appointmentnote', 'scheduler'), - array('rows' => 3, 'columns' => 60), $this->noteoptions); + ['rows' => 3, 'columns' => 60], $this->noteoptions); $mform->setType('appointmentnote', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. $candistribute = true; } else { @@ -121,7 +121,7 @@ protected function definition() { if ($scheduler->uses_teachernotes()) { if ($this->permissions->can_edit_notes($this->appointment)) { $mform->addElement('editor', 'teachernote_editor', get_string('teachernote', 'scheduler'), - array('rows' => 3, 'columns' => 60), $this->noteoptions); + ['rows' => 3, 'columns' => 60], $this->noteoptions); $mform->setType('teachernote', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. $candistribute = true; } else { diff --git a/backup/moodle2/backup_scheduler_stepslib.php b/backup/moodle2/backup_scheduler_stepslib.php index 3aaf6f27..72a488a2 100644 --- a/backup/moodle2/backup_scheduler_stepslib.php +++ b/backup/moodle2/backup_scheduler_stepslib.php @@ -41,27 +41,27 @@ protected function define_structure() { $userinfo = $this->get_setting_value('userinfo'); // Define each element separated. - $scheduler = new backup_nested_element('scheduler', array('id'), array( + $scheduler = new backup_nested_element('scheduler', ['id'], [ 'name', 'intro', 'introformat', 'schedulermode', 'maxbookings', 'guardtime', 'defaultslotduration', 'allownotifications', 'staffrolename', 'scale', 'gradingstrategy', 'bookingrouping', 'usenotes', 'usebookingform', 'bookinginstructions', 'bookinginstructionsformat', 'usestudentnotes', 'requireupload', 'uploadmaxfiles', 'uploadmaxsize', - 'usecaptcha', 'timemodified')); + 'usecaptcha', 'timemodified', ]); $slots = new backup_nested_element('slots'); - $slot = new backup_nested_element('slot', array('id'), array( + $slot = new backup_nested_element('slot', ['id'], [ 'starttime', 'duration', 'teacherid', 'appointmentlocation', 'timemodified', 'notes', 'notesformat', 'exclusivity', - 'emaildate', 'hideuntil')); + 'emaildate', 'hideuntil', ]); $appointments = new backup_nested_element('appointments'); - $appointment = new backup_nested_element('appointment', array('id'), array( + $appointment = new backup_nested_element('appointment', ['id'], [ 'studentid', 'attended', 'grade', 'appointmentnote', 'appointmentnoteformat', 'teachernote', 'teachernoteformat', - 'studentnote', 'studentnoteformat', 'timecreated', 'timemodified')); + 'studentnote', 'studentnoteformat', 'timecreated', 'timemodified', ]); // Build the tree. @@ -72,13 +72,13 @@ protected function define_structure() { $appointments->add_child($appointment); // Define sources. - $scheduler->set_source_table('scheduler', array('id' => backup::VAR_ACTIVITYID)); + $scheduler->set_source_table('scheduler', ['id' => backup::VAR_ACTIVITYID]); $scheduler->annotate_ids('grouping', 'bookingrouping'); // Include appointments only if we back up user information. if ($userinfo) { - $slot->set_source_table('scheduler_slots', array('schedulerid' => backup::VAR_PARENTID)); - $appointment->set_source_table('scheduler_appointment', array('slotid' => backup::VAR_PARENTID)); + $slot->set_source_table('scheduler_slots', ['schedulerid' => backup::VAR_PARENTID]); + $appointment->set_source_table('scheduler_appointment', ['slotid' => backup::VAR_PARENTID]); } // Define id annotations. diff --git a/backup/moodle2/restore_scheduler_activity_task.class.php b/backup/moodle2/restore_scheduler_activity_task.class.php index b8a8a7ce..75638785 100644 --- a/backup/moodle2/restore_scheduler_activity_task.class.php +++ b/backup/moodle2/restore_scheduler_activity_task.class.php @@ -56,9 +56,9 @@ protected function define_my_steps() { * processed by the link decoder */ public static function define_decode_contents() { - $contents = array(); + $contents = []; - $contents[] = new restore_decode_content('scheduler', array('intro'), 'scheduler'); + $contents[] = new restore_decode_content('scheduler', ['intro'], 'scheduler'); return $contents; } @@ -68,7 +68,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('SCHEDULERVIEWBYID', '/mod/scheduler/view.php?id=$1', 'course_module'); $rules[] = new restore_decode_rule('SCHEDULERINDEX', '/mod/scheduler/index.php?id=$1', 'course'); @@ -84,7 +84,7 @@ public static function define_decode_rules() { * of {@see restore_log_rule} objects */ public static function define_restore_log_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_log_rule('scheduler', 'add', 'view.php?id={course_module}', '{scheduler}'); $rules[] = new restore_log_rule('scheduler', 'update', 'view.php?id={course_module}', '{scheduler}'); @@ -104,7 +104,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('scheduler', 'view all', 'index.php?id={course}', null); diff --git a/backup/moodle2/restore_scheduler_stepslib.php b/backup/moodle2/restore_scheduler_stepslib.php index 39332709..3382848b 100644 --- a/backup/moodle2/restore_scheduler_stepslib.php +++ b/backup/moodle2/restore_scheduler_stepslib.php @@ -37,7 +37,7 @@ class restore_scheduler_activity_structure_step extends restore_activity_structu */ protected function define_structure() { - $paths = array(); + $paths = []; $userinfo = $this->get_setting_value('userinfo'); $scheduler = new restore_path_element('scheduler', '/activity/scheduler'); diff --git a/bookingform.php b/bookingform.php index 4ae84b0e..8c2c9930 100644 --- a/bookingform.php +++ b/bookingform.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\slot; -use \mod_scheduler\model\appointment; +use mod_scheduler\model\slot; +use mod_scheduler\model\appointment; require_once($CFG->libdir.'/formslib.php'); @@ -45,6 +45,8 @@ class scheduler_booking_form extends moodleform { /** @var mixed */ protected $uploadoptions; /** @var mixed */ + protected $noteoptions = []; + /** @var mixed */ protected $existing; /** @@ -70,19 +72,19 @@ protected function definition() { $mform = $this->_form; $scheduler = $this->slot->get_scheduler(); - $this->noteoptions = array('trusttext' => false, 'maxfiles' => 0, 'maxbytes' => 0, + $this->noteoptions = ['trusttext' => false, 'maxfiles' => 0, 'maxbytes' => 0, 'context' => $scheduler->get_context(), - 'collapsed' => true); + 'collapsed' => true, ]; - $this->uploadoptions = array('subdirs' => 0, + $this->uploadoptions = ['subdirs' => 0, 'maxbytes' => $scheduler->uploadmaxsize, - 'maxfiles' => $scheduler->uploadmaxfiles); + 'maxfiles' => $scheduler->uploadmaxfiles, ]; // Text field for student-supplied data. if ($scheduler->uses_studentnotes()) { $mform->addElement('editor', 'studentnote_editor', get_string('yourstudentnote', 'scheduler'), - array('rows' => 3, 'columns' => 60), $this->noteoptions); + ['rows' => 3, 'columns' => 60], $this->noteoptions); $mform->setType('studentnote', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. if ($scheduler->usestudentnotes == 2) { $mform->addRule('studentnote_editor', get_string('notesrequired', 'scheduler'), 'required'); @@ -101,7 +103,7 @@ protected function definition() { // Captcha. if ($scheduler->uses_bookingcaptcha() && !$this->existing) { - $mform->addElement('recaptcha', 'bookingcaptcha', get_string('security_question', 'auth'), array('https' => true)); + $mform->addElement('recaptcha', 'bookingcaptcha', get_string('security_question', 'auth'), ['https' => true]); $mform->addHelpButton('bookingcaptcha', 'recaptcha', 'auth'); $mform->closeHeaderBefore('bookingcaptcha'); } diff --git a/classes/event/appointment_base.php b/classes/event/appointment_base.php index a5f7e9c5..c2921f2d 100644 --- a/classes/event/appointment_base.php +++ b/classes/event/appointment_base.php @@ -45,10 +45,10 @@ abstract class appointment_base extends \core\event\base { * @return array */ protected static function base_data(\mod_scheduler\model\appointment $appointment) { - return array( + return [ 'context' => $appointment->get_parent()->get_context(), - 'objectid' => $appointment->id - ); + 'objectid' => $appointment->id, + ]; } /** @@ -85,7 +85,7 @@ public function get_appointment() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/scheduler/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/scheduler/view.php', ['id' => $this->contextinstanceid]); } /** diff --git a/classes/event/scheduler_base.php b/classes/event/scheduler_base.php index 379263f0..10788259 100644 --- a/classes/event/scheduler_base.php +++ b/classes/event/scheduler_base.php @@ -52,10 +52,10 @@ abstract class scheduler_base extends \core\event\base { * @return array */ protected static function base_data(\mod_scheduler\model\scheduler $scheduler) { - return array( + return [ 'context' => $scheduler->get_context(), - 'objectid' => $scheduler->id - ); + 'objectid' => $scheduler->id, + ]; } /** @@ -97,7 +97,7 @@ public function get_scheduler() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/scheduler/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/scheduler/view.php', ['id' => $this->contextinstanceid]); } /** diff --git a/classes/event/slot_base.php b/classes/event/slot_base.php index 05df4c18..11e1fb93 100644 --- a/classes/event/slot_base.php +++ b/classes/event/slot_base.php @@ -44,11 +44,11 @@ abstract class slot_base extends \core\event\base { * @return array */ protected static function base_data(\mod_scheduler\model\slot $slot) { - return array( + return [ 'context' => $slot->get_scheduler()->get_context(), 'objectid' => $slot->id, - 'relateduserid' => $slot->teacherid - ); + 'relateduserid' => $slot->teacherid, + ]; } /** @@ -84,7 +84,7 @@ public function get_slot() { * @return \moodle_url */ public function get_url() { - return new \moodle_url('/mod/scheduler/view.php', array('id' => $this->contextinstanceid)); + return new \moodle_url('/mod/scheduler/view.php', ['id' => $this->contextinstanceid]); } /** diff --git a/classes/event/slot_deleted.php b/classes/event/slot_deleted.php index 3b25555d..0e6ff1e2 100644 --- a/classes/event/slot_deleted.php +++ b/classes/event/slot_deleted.php @@ -44,7 +44,7 @@ class slot_deleted extends slot_base { */ public static function create_from_slot(\mod_scheduler\model\slot $slot, $action) { $data = self::base_data($slot); - $data['other'] = array('action' => $action); + $data['other'] = ['action' => $action]; $event = self::create($data); $event->set_slot($slot); return $event; diff --git a/classes/external.php b/classes/external.php index 3c8ab315..e59bd9f4 100644 --- a/classes/external.php +++ b/classes/external.php @@ -34,7 +34,7 @@ use external_single_structure; use external_multiple_structure; -use \mod_scheduler\model\scheduler; +use mod_scheduler\model\scheduler; /** * This is the external API for this component. @@ -53,7 +53,7 @@ public static function studentid_parameters() { return new external_function_parameters([ 'query' => new external_value(PARAM_TEXT, 'The search query', VALUE_REQUIRED), 'scheduler' => new external_value(PARAM_INT, 'The scheduler id', VALUE_REQUIRED), - 'groupids' => new external_value(PARAM_INT, 'The group ids', VALUE_DEFAULT) + 'groupids' => new external_value(PARAM_INT, 'The group ids', VALUE_DEFAULT), ]); } @@ -70,12 +70,11 @@ public static function studentid_parameters() { * @throws invalid_parameter_exception * @throws restricted_context_exception */ - public static function studentid($query, $scheduler, $groupids) { $params = external_api::validate_parameters(self::studentid_parameters(), [ 'query' => $query, 'scheduler' => $scheduler, - 'groupids' => $groupids + 'groupids' => $groupids, ]); $query = $params['query']; $scheduler = $params['scheduler']; @@ -110,7 +109,7 @@ public static function studentid_returns() { return new external_multiple_structure( new external_single_structure([ 'id' => new external_value(PARAM_INT, 'User ID'), - 'fullname' => new external_value(PARAM_NOTAGS, 'User fullname') + 'fullname' => new external_value(PARAM_NOTAGS, 'User fullname'), ]) ); } diff --git a/classes/model/appointment.php b/classes/model/appointment.php index 9d61f6dd..5cfa2756 100644 --- a/classes/model/appointment.php +++ b/classes/model/appointment.php @@ -114,7 +114,7 @@ public function get_scheduler() { public function get_student() { global $DB; if ($this->data->studentid) { - return $DB->get_record('user', array('id' => $this->data->studentid), '*', MUST_EXIST); + return $DB->get_record('user', ['id' => $this->data->studentid], '*', MUST_EXIST); } else { return null; } diff --git a/classes/model/appointment_factory.php b/classes/model/appointment_factory.php index 0c76b2f0..22a044cd 100644 --- a/classes/model/appointment_factory.php +++ b/classes/model/appointment_factory.php @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . - /** * A factory class for scheduler appointments. * diff --git a/classes/model/mvc_child_list.php b/classes/model/mvc_child_list.php index cb3dfe02..656cb8da 100644 --- a/classes/model/mvc_child_list.php +++ b/classes/model/mvc_child_list.php @@ -83,7 +83,7 @@ public function __construct(mvc_record_model $parent, $childtable, $childfield, $this->childtable = $childtable; $this->childfactory = $factory; $this->parentmodel = $parent; - $this->childrenfordeletion = array(); + $this->childrenfordeletion = []; } /** @@ -103,10 +103,10 @@ public function load() { return; // Children already loaded. } else if (!$this->get_parent_id()) { // Parent ID is invalid - not yet stored. - $this->children = array(); + $this->children = []; } else { - $this->children = array(); - $childrecs = $DB->get_records($this->childtable, array($this->childfield => $this->get_parent_id())); + $this->children = []; + $childrecs = $DB->get_records($this->childtable, [$this->childfield => $this->get_parent_id()]); $cnt = 0; foreach ($childrecs as $rec) { $app = $this->childfactory->create_child_from_record($rec, $this->parentmodel); @@ -157,7 +157,7 @@ public function get_child_count() { } else if (!$this->get_parent_id()) { return 0; // No valid parent. } else { - $cnt = $DB->count_records($this->childtable, array($this->childfield => $this->get_parent_id())); + $cnt = $DB->count_records($this->childtable, [$this->childfield => $this->get_parent_id()]); $this->childcount = $cnt; return $cnt; } @@ -175,7 +175,7 @@ public function save_children() { foreach ($this->childrenfordeletion as $delchild) { $delchild->delete(); } - $this->childrenfordeletion = array(); + $this->childrenfordeletion = []; } /** diff --git a/classes/model/mvc_child_model_factory.php b/classes/model/mvc_child_model_factory.php index 47694629..8a541e98 100644 --- a/classes/model/mvc_child_model_factory.php +++ b/classes/model/mvc_child_model_factory.php @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . - /** * An abstract factory class for loading child records from the database. * diff --git a/classes/model/mvc_record_model.php b/classes/model/mvc_record_model.php index d726332d..b4e1e983 100644 --- a/classes/model/mvc_record_model.php +++ b/classes/model/mvc_record_model.php @@ -58,7 +58,7 @@ protected function __construct() { */ public function load($id) { global $DB; - $rec = $DB->get_record($this->get_table(), array('id' => $id), '*', MUST_EXIST); + $rec = $DB->get_record($this->get_table(), ['id' => $id], '*', MUST_EXIST); $this->data = $rec; } @@ -174,7 +174,7 @@ public function delete() { $id = $this->get_id(); if ($id != 0) { - $DB->delete_records($this->get_table(), array('id' => $id)); + $DB->delete_records($this->get_table(), ['id' => $id]); } } diff --git a/classes/model/scheduler.php b/classes/model/scheduler.php index 3a24cff7..472b4d56 100644 --- a/classes/model/scheduler.php +++ b/classes/model/scheduler.php @@ -178,7 +178,7 @@ public function get_courseid() { public function get_courserec() { global $DB; if (is_null($this->courserec)) { - $this->courserec = $DB->get_record('course', array('id' => $this->get_courseid()), '*', MUST_EXIST); + $this->courserec = $DB->get_record('course', ['id' => $this->get_courseid()], '*', MUST_EXIST); } return $this->courserec; } @@ -293,7 +293,7 @@ public function is_individual_scheduling_enabled() { public function get_last_location($user) { global $DB; - $conds = array('schedulerid' => $this->data->id, 'teacherid' => $user->id); + $conds = ['schedulerid' => $this->data->id, 'teacherid' => $user->id]; $recs = $DB->get_records('scheduler_slots', $conds, 'timemodified DESC', 'id,appointmentlocation', 0, 1); $lastlocation = ''; if ($recs) { @@ -422,7 +422,7 @@ public function get_user_grades($userid = 0) { } $usersql = ''; - $params = array(); + $params = []; if ($userid) { $usersql = ' AND a.studentid = :userid'; $params['userid'] = $userid; @@ -434,8 +434,8 @@ public function get_user_grades($userid = 0) { 'WHERE s.schedulerid = :sid AND a.grade IS NOT NULL'.$usersql; $grades = $DB->get_records_sql($sql, $params); - $finalgrades = array(); - $gradesums = array(); + $finalgrades = []; + $gradesums = []; foreach ($grades as $grade) { $gradesums[$grade->studentid] = new \stdClass(); @@ -465,7 +465,7 @@ public function get_user_grades($userid = 0) { } else { // Grading on scales. $scaleid = - ($this->scale); $maxgrade = ''; - if ($scale = $DB->get_record('scale', array('id' => $scaleid))) { + if ($scale = $DB->get_record('scale', ['id' => $scaleid])) { $scalegrades = make_menu_from_list($scale->scale); foreach ($grades as $grade) { $gradesums[$grade->studentid]->sum = @$gradesums[$grade->studentid]->sum + $grade->grade; @@ -576,7 +576,7 @@ protected function fetch_slots($wherecond, $havingcond, array $params, $limitfro $sql = "$select $where $having $order"; $slotdata = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum); - $slots = array(); + $slots = []; foreach ($slotdata as $slotrecord) { $slot = new slot($this); $slot->load_record($slotrecord); @@ -659,7 +659,7 @@ public function get_slot($id) { global $DB; - $slotdata = $DB->get_record('scheduler_slots', array('id' => $id, 'schedulerid' => $this->id), '*', MUST_EXIST); + $slotdata = $DB->get_record('scheduler_slots', ['id' => $id, 'schedulerid' => $this->id], '*', MUST_EXIST); $slot = new slot($this); $slot->load_record($slotdata); return $slot; @@ -691,7 +691,7 @@ public function get_slot_count() { * @return slot[] */ public function get_all_slots($limitfrom='', $limitnum='') { - return $this->fetch_slots('', '', array(), $limitfrom, $limitnum, 's.starttime ASC'); + return $this->fetch_slots('', '', [], $limitfrom, $limitnum, 's.starttime ASC'); } /** @@ -702,7 +702,7 @@ public function get_all_slots($limitfrom='', $limitnum='') { */ public function get_attended_slots_for_student($studentid) { - $params = array(); + $params = []; $wherecond = $this->student_in_slot_condition($params, $studentid, true, false); $slots = $this->fetch_slots($wherecond, '', $params, '', '', 's.starttime'); @@ -719,7 +719,7 @@ public function get_attended_slots_for_student($studentid) { */ public function get_upcoming_slots_for_student($studentid) { - $params = array(); + $params = []; $wherecond = $this->student_in_slot_condition($params, $studentid, false, true); $slots = $this->fetch_slots($wherecond, '', $params, '', '', 's.starttime'); @@ -740,7 +740,7 @@ public function get_slots_available_to_student($studentid, $includefullybooked = global $DB; - $params = array(); + $params = []; $wherecond = "(s.starttime > :cutofftime) AND (s.hideuntil < :nowhide)"; $params['nowhide'] = time(); $params['cutofftime'] = time() + $this->guardtime; @@ -751,7 +751,7 @@ public function get_slots_available_to_student($studentid, $includefullybooked = if ($this->groupmode != NOGROUPS) { $groups = groups_get_all_groups($this->cm->course, $studentid, $this->cm->groupingid); if ($groups) { - $groupids = array(); + $groupids = []; foreach ($groups as $group) { $groupids[] = $group->id; } @@ -779,7 +779,7 @@ public function get_slots_available_to_student($studentid, $includefullybooked = * @return boolean */ public function has_slots_for_student($studentid, $mustbeattended, $mustbeunattended) { - $params = array(); + $params = []; $where = $this->student_in_slot_condition($params, $studentid, $mustbeattended, $mustbeunattended); $cnt = $this->count_slots($where, $params); return $cnt > 0; @@ -810,7 +810,7 @@ public function has_slots_booked_for_group($groupid, $mustbeattended = false, $m WHERE s.schedulerid = :schedulerid AND gm.groupid = :groupid $attendcond"; - $params = array('schedulerid' => $this->id, 'groupid' => $groupid); + $params = ['schedulerid' => $this->id, 'groupid' => $groupid]; return $DB->count_records_sql($sql, $params) > 0; } @@ -823,7 +823,7 @@ public function has_slots_booked_for_group($groupid, $mustbeattended = false, $m */ public function get_slots_without_appointment($teacherid = 0) { $wherecond = '('.$this->appointment_count_query().' = 0)'; - $params = array(); + $params = []; if ($teacherid > 0) { list($twhere, $params) = $this->slots_for_teacher_cond($teacherid, 0, false); $wherecond .= " AND $twhere"; @@ -841,8 +841,8 @@ public function get_slots_without_appointment($teacherid = 0) { * @return mixed SQL condition and parameters */ protected function slots_for_teacher_cond($teacherid, $groupid, $timerange) { - $wheres = array(); - $params = array(); + $wheres = []; + $params = []; if ($teacherid > 0) { $wheres[] = "teacherid = :tid"; $params['tid'] = $teacherid; @@ -857,7 +857,7 @@ protected function slots_for_teacher_cond($teacherid, $groupid, $timerange) { $wheres[] = "s.starttime >= ".strtotime('now'); } $where = implode(" AND ", $wheres); - return array($where, $params); + return [$where, $params]; } /** @@ -921,7 +921,7 @@ public function get_conflicts($starttime, $endtime, $teacher = 0, $student = 0, $others = SCHEDULER_SELF, $excludeslot = 0) { global $DB; - $params = array(); + $params = []; $slotscope = ($excludeslot == 0) ? "" : "sl.id != :excludeslot AND "; $params['excludeslot'] = $excludeslot; @@ -988,11 +988,11 @@ public function get_conflicts($starttime, $endtime, $teacher = 0, $student = 0, public function get_slot_appointment($appointmentid) { global $DB; - $slotid = $DB->get_field('scheduler_appointment', 'slotid', array('id' => $appointmentid)); + $slotid = $DB->get_field('scheduler_appointment', 'slotid', ['id' => $appointmentid]); $slot = $this->get_slot($slotid); $app = $slot->get_appointment($appointmentid); - return array($slot, $app); + return [$slot, $app]; } /** @@ -1011,15 +1011,15 @@ public function get_appointments_for_student($studentid) { AND s.id = a.slotid AND a.studentid = :studid ORDER BY s.starttime"; - $params = array('schedulerid' => $this->id, 'studid' => $studentid); + $params = ['schedulerid' => $this->id, 'studid' => $studentid]; $slotrecs = $DB->get_records_sql($sql, $params); - $appointments = array(); + $appointments = []; foreach ($slotrecs as $rec) { $slot = new slot($this); $slot->load_record($rec); - $appointrec = $DB->get_record('scheduler_appointment', array('id' => $rec->appointmentid), '*', MUST_EXIST); + $appointrec = $DB->get_record('scheduler_appointment', ['id' => $rec->appointmentid], '*', MUST_EXIST); $appointment = new appointment($slot); $appointment->load_record($appointrec); $appointments[] = $appointment; @@ -1059,7 +1059,7 @@ public function count_bookable_appointments($studentid, $includechangeable = tru } else if ($includechangeable) { $sql .= ' AND (s.starttime <= :cutofftime OR a.attended = 1)'; } - $params = array('schedulerid' => $this->id, 'studentid' => $studentid, 'cutofftime' => time() + $this->guardtime); + $params = ['schedulerid' => $this->id, 'studentid' => $studentid, 'cutofftime' => time() + $this->guardtime]; $booked = $DB->count_records_sql($sql, $params); $allowed = $this->maxbookings; @@ -1085,7 +1085,7 @@ public function get_teachers() { FROM {scheduler_slots} s, {user} u WHERE s.teacherid = u.id AND schedulerid = ?"; - $teachers = $DB->get_records_sql($sql, array($this->id)); + $teachers = $DB->get_records_sql($sql, [$this->id]); return $teachers; } @@ -1111,7 +1111,7 @@ protected function get_available_users($capability, $groupids = 0) { $groupids = 0; } - $users = array(); + $users = []; if (is_integer($groupids)) { $users = get_enrolled_users($this->get_context(), $capability, $groupids, 'u.*', null, 0, 0, true); @@ -1185,7 +1185,7 @@ public function get_students_for_scheduling($groups = '', $cutoff = 0, $onlymand if (($cutoff > 0 && count($studs) > $cutoff) || count($studs) == 0) { return count($studs); } - $schedstuds = array(); + $schedstuds = []; foreach ($studs as $stud) { $include = false; if ($this->allows_unlimited_bookings()) { @@ -1210,7 +1210,7 @@ public function get_students_for_scheduling($groups = '', $cutoff = 0, $onlymand public function delete_appointment($appointmentid) { global $DB; - if (!$oldrecord = $DB->get_record('scheduler_appointment', array('id' => $appointmentid))) { + if (!$oldrecord = $DB->get_record('scheduler_appointment', ['id' => $appointmentid])) { return; } @@ -1238,7 +1238,7 @@ public static function free_late_unused_slots() { WHERE a.studentid IS NULL AND starttime < ?"; $now = time(); - $todelete = $DB->get_records_sql($sql, array($now), 0, 1000); + $todelete = $DB->get_records_sql($sql, [$now], 0, 1000); if ($todelete) { list($usql, $params) = $DB->get_in_or_equal(array_keys($todelete)); $DB->delete_records_select('scheduler_slots', " id $usql ", $params); diff --git a/classes/model/slot.php b/classes/model/slot.php index 1c68c069..50898ed5 100644 --- a/classes/model/slot.php +++ b/classes/model/slot.php @@ -136,7 +136,7 @@ private function distribute_file_area($area, $sourceid, $targetid) { // Copy files from the source to the target. $files = $fs->get_area_files($ctxid, $component, $area, $sourceid); foreach ($files as $f) { - $fs->create_file_from_storedfile(array('itemid' => $targetid), $f); + $fs->create_file_from_storedfile(['itemid' => $targetid], $f); } } @@ -157,7 +157,7 @@ public function get_scheduler() { public function get_teacher() { global $DB; if ($this->data->teacherid) { - return $DB->get_record('user', array('id' => $this->data->teacherid), '*', MUST_EXIST); + return $DB->get_record('user', ['id' => $this->data->teacherid], '*', MUST_EXIST); } else { return new \stdClass(); } @@ -364,8 +364,8 @@ private function get_student_eventtype() { */ private function clear_calendar() { global $DB; - $DB->delete_records('event', array('eventtype' => $this->get_teacher_eventtype())); - $DB->delete_records('event', array('eventtype' => $this->get_student_eventtype())); + $DB->delete_records('event', ['eventtype' => $this->get_teacher_eventtype()]); + $DB->delete_records('event', ['eventtype' => $this->get_student_eventtype()]); } /** @@ -381,16 +381,16 @@ private function update_calendar() { $myappointments = $this->appointments->get_children(); - $studentids = array(); + $studentids = []; foreach ($myappointments as $appointment) { if (!$appointment->is_attended()) { $studentids[] = $appointment->studentid; } } - $teacher = $DB->get_record('user', array('id' => $this->teacherid)); + $teacher = $DB->get_record('user', ['id' => $this->teacherid]); $students = $DB->get_records_list('user', 'id', $studentids); - $studentnames = array(); + $studentnames = []; foreach ($students as $student) { $studentnames[] = fullname($student); } @@ -422,7 +422,7 @@ private function update_calendar() { // Update teacher events. - $teacherids = array(); + $teacherids = []; $teacherevent = clone($baseevent); if (count($studentids) > 0) { $teacherids[] = $teacher->id; @@ -454,9 +454,9 @@ private function update_calendar_events($eventtype, array $userids, \stdClass $e $eventdata->eventtype = $eventtype; - $existingevents = $DB->get_records('event', array('modulename' => 'scheduler', 'eventtype' => $eventtype)); - $handledevents = array(); - $handledusers = array(); + $existingevents = $DB->get_records('event', ['modulename' => 'scheduler', 'eventtype' => $eventtype]); + $handledevents = []; + $handledusers = []; // Update existing calendar events. foreach ($existingevents as $eventid => $existingdata) { diff --git a/classes/permission/permissions_manager.php b/classes/permission/permissions_manager.php index ce0be45c..3859935b 100644 --- a/classes/permission/permissions_manager.php +++ b/classes/permission/permissions_manager.php @@ -54,7 +54,7 @@ protected function __construct($pluginname, \context $context, $userid) { $this->context = $context; $this->prefix = str_replace('_', '/', $pluginname) . ':'; - $this->caps = array(); + $this->caps = []; } /** diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 490de14f..2d3aa3c3 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -59,7 +59,7 @@ class provider implements * @param collection $collection 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( 'scheduler_slots', [ @@ -69,7 +69,7 @@ public static function get_metadata(collection $collection) : collection { 'appointmentlocation' => 'privacy:metadata:scheduler_slots:appointmentlocation', 'notes' => 'privacy:metadata:scheduler_slots:notes', 'notesformat' => 'privacy:metadata:scheduler_slots:notesformat', - 'exclusivity' => 'privacy:metadata:scheduler_slots:exclusivity' + 'exclusivity' => 'privacy:metadata:scheduler_slots:exclusivity', // The fields "timemodified", "emaildate" and "hideuntil" do not contain personal data. ], 'privacy:metadata:scheduler_slots' @@ -85,7 +85,7 @@ public static function get_metadata(collection $collection) : collection { 'teachernote' => 'privacy:metadata:scheduler_appointment:teachernote', 'teachernoteformat' => 'privacy:metadata:scheduler_appointment:teachernoteformat', 'studentnote' => 'privacy:metadata:scheduler_appointment:studentnote', - 'studentnoteformat' => 'privacy:metadata:scheduler_appointment:studentnoteformat' + 'studentnoteformat' => 'privacy:metadata:scheduler_appointment:studentnoteformat', // The fields "timecreated" and "timemodifed" are technical only, they do not contain personal data. ], 'privacy:metadata:scheduler_appointment' @@ -103,7 +103,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 { $contextlist = new contextlist(); // Fetch all scheduler records for teachers. @@ -118,7 +118,7 @@ public static function get_contexts_for_userid(int $userid) : contextlist { $params = [ 'modname' => 'scheduler', 'contextlevel' => CONTEXT_MODULE, - 'userid' => $userid + 'userid' => $userid, ]; $contextlist->add_from_sql($sql, $params); @@ -136,7 +136,7 @@ public static function get_contexts_for_userid(int $userid) : contextlist { $params = [ 'modname' => 'scheduler', 'contextlevel' => CONTEXT_MODULE, - 'userid' => $userid + 'userid' => $userid, ]; $contextlist->add_from_sql($sql, $params); @@ -167,7 +167,7 @@ public static function get_users_in_context(userlist $userlist) { $params = [ 'modname' => 'scheduler', - 'cmid' => $context->instanceid + 'cmid' => $context->instanceid, ]; $userlist->add_from_sql('teacherid', $sql, $params); @@ -183,7 +183,7 @@ public static function get_users_in_context(userlist $userlist) { $params = [ 'modname' => 'scheduler', - 'cmid' => $context->instanceid + 'cmid' => $context->instanceid, ]; $userlist->add_from_sql('studentid', $sql, $params); @@ -255,7 +255,7 @@ public static function export_user_data(approved_contextlist $contextlist) { AND t.teacherid = :userid1 OR a.studentid = :userid2 ORDER BY cm.id, t.id, a.id"; $rs = $DB->get_recordset_sql($sql, $contextparams + ['contextlevel' => CONTEXT_MODULE, - 'modname' => 'scheduler', 'userid1' => $user->id, 'userid2' => $user->id]); + 'modname' => 'scheduler', 'userid1' => $user->id, 'userid2' => $user->id, ]); $context = null; $lastrow = null; @@ -302,7 +302,7 @@ private static function format_note($notetext, $noteformat, $filearea, $id, } $opts = (object) [ 'para' => false, - 'context' => $context + 'context' => $context, ]; $message = format_text($message, $noteformat, $opts); return $message; diff --git a/classes/task/send_reminders.php b/classes/task/send_reminders.php index 100a1b0e..4ad0f3b6 100644 --- a/classes/task/send_reminders.php +++ b/classes/task/send_reminders.php @@ -57,11 +57,11 @@ public function execute() { // Find relevant slots in all schedulers. $select = 'emaildate > 0 AND emaildate <= ? AND starttime > ?'; - $slots = $DB->get_records_select('scheduler_slots', $select, array($date, $date), 'starttime'); + $slots = $DB->get_records_select('scheduler_slots', $select, [$date, $date], 'starttime'); foreach ($slots as $slot) { // Get teacher record. - $teacher = $DB->get_record('user', array('id' => $slot->teacherid)); + $teacher = $DB->get_record('user', ['id' => $slot->teacherid]); // Get scheduler, slot and course. $scheduler = \mod_scheduler\model\scheduler::load_by_id($slot->schedulerid); diff --git a/customlib.php b/customlib.php index 826cc8e2..3db3826a 100644 --- a/customlib.php +++ b/customlib.php @@ -39,7 +39,7 @@ */ function scheduler_get_user_fields($user, $context) { - $fields = array(); + $fields = []; if (has_capability('moodle/site:viewuseridentity', $context)) { $emailfield = new stdClass(); @@ -54,6 +54,8 @@ function scheduler_get_user_fields($user, $context) { * As an example: Uncomment the following lines in order to display the user's city and country. */ + // phpcs:disable + /* $cityfield = new stdClass(); $cityfield->title = get_string('city'); @@ -73,5 +75,7 @@ function scheduler_get_user_fields($user, $context) { } } */ + + // phpcs:enable return $fields; } diff --git a/datelist.php b/datelist.php index eb2782fd..417cb7b9 100644 --- a/datelist.php +++ b/datelist.php @@ -29,7 +29,7 @@ $PAGE->set_docs_path('mod/scheduler/datelist'); $scope = optional_param('scope', 'activity', PARAM_TEXT); -if (!in_array($scope, array('activity', 'course', 'site'))) { +if (!in_array($scope, ['activity', 'course', 'site'])) { $scope = 'activity'; } $teacherid = optional_param('teacherid', 0, PARAM_INT); @@ -50,8 +50,8 @@ } $taburl = new moodle_url('/mod/scheduler/view.php', - array('id' => $scheduler->cmid, 'what' => 'datelist', 'scope' => $scope, 'teacherid' => $teacherid)); -$returnurl = new moodle_url('/mod/scheduler/view.php', array('id' => $scheduler->cmid)); + ['id' => $scheduler->cmid, 'what' => 'datelist', 'scope' => $scope, 'teacherid' => $teacherid]); +$returnurl = new moodle_url('/mod/scheduler/view.php', ['id' => $scheduler->cmid]); $PAGE->set_url($taburl); @@ -76,26 +76,26 @@ $scopemenukey = 'scopemenuself'; if (has_capability('mod/scheduler:canseeotherteachersbooking', $scopecontext)) { $teachers = $scheduler->get_available_teachers($currentgroupid); - $teachermenu = array(); + $teachermenu = []; foreach ($teachers as $teacher) { $teachermenu[$teacher->id] = fullname($teacher); } $select = $output->single_select($taburl, 'teacherid', $teachermenu, $teacherid, - array(0 => get_string('myself', 'scheduler')), 'teacheridform'); + [0 => get_string('myself', 'scheduler')], 'teacheridform'); echo html_writer::div(get_string('teachersmenu', 'scheduler', $select), 'dropdownmenu'); $scopemenukey = 'scopemenu'; } if (has_capability('mod/scheduler:seeoverviewoutsideactivity', $context)) { - $scopemenu = array('activity' => get_string('thisscheduler', 'scheduler'), + $scopemenu = ['activity' => get_string('thisscheduler', 'scheduler'), 'course' => get_string('thiscourse', 'scheduler'), - 'site' => get_string('thissite', 'scheduler')); + 'site' => get_string('thissite', 'scheduler'), ]; $select = $output->single_select($taburl, 'scope', $scopemenu, $scope, null, 'scopeform'); echo html_writer::div(get_string($scopemenukey, 'scheduler', $select), 'dropdownmenu'); } // Getting date list. -$params = array(); +$params = []; $params['teacherid'] = $teacherid == 0 ? $USER->id : $teacherid; $params['courseid'] = $scheduler->courseid; $params['schedulerid'] = $scheduler->id; @@ -176,10 +176,10 @@ $whatresultedstr = get_string('whatresulted', 'scheduler'); $whathappenedstr = get_string('whathappened', 'scheduler'); - $tablecolumns = array('courseshort', 'schedulerid', 'starttime', 'appointmentlocation', - 'studentfullname', 'studentdepartment', 'notes', 'grade', 'appointmentnote'); - $tableheaders = array($coursestr, $schedulerstr, $whenstr, $wherestr, - $whostr, $wherefromstr, $whatstr, $whatresultedstr, $whathappenedstr); + $tablecolumns = ['courseshort', 'schedulerid', 'starttime', 'appointmentlocation', + 'studentfullname', 'studentdepartment', 'notes', 'grade', 'appointmentnote', ]; + $tableheaders = [$coursestr, $schedulerstr, $whenstr, $wherestr, + $whostr, $wherefromstr, $whatstr, $whatresultedstr, $whathappenedstr, ]; $table = new flexible_table('mod-scheduler-datelist'); $table->define_columns($tablecolumns); @@ -217,19 +217,19 @@ $results = $DB->get_records_sql($sql, $params); foreach ($results as $id => $row) { - $courseurl = new moodle_url('/course/view.php', array('id' => $row->courseid)); + $courseurl = new moodle_url('/course/view.php', ['id' => $row->courseid]); $coursedata = html_writer::link($courseurl, format_string($row->courseshort)); - $schedulerurl = new moodle_url('/mod/scheduler/view.php', array('a' => $row->schedulerid)); + $schedulerurl = new moodle_url('/mod/scheduler/view.php', ['a' => $row->schedulerid]); $schedulerdata = html_writer::link($schedulerurl, format_string($row->name)); $a = mod_scheduler_renderer::slotdatetime($row->starttime, $row->duration); $whendata = get_string('slotdatetime', 'scheduler', $a); $whourl = new moodle_url('/mod/scheduler/view.php', - array('what' => 'viewstudent', 'a' => $row->schedulerid, 'appointmentid' => $row->id)); + ['what' => 'viewstudent', 'a' => $row->schedulerid, 'appointmentid' => $row->id]); $whodata = html_writer::link($whourl, $row->studentfullname); $whatdata = $output->format_notes($row->notes, $row->notesformat, $context, 'slotnote', $row->sid); $gradedata = $row->scale == 0 ? '' : $output->format_grade($row->scale, $row->grade); - $dataset = array( + $dataset = [ $coursedata, $schedulerdata, $whendata, @@ -238,7 +238,7 @@ $row->studentdepartment, $whatdata, $gradedata, - $output->format_appointment_notes($scheduler, $row) ); + $output->format_appointment_notes($scheduler, $row), ]; $table->add_data($dataset); } $table->print_html(); diff --git a/db/access.php b/db/access.php index 1547f4d2..33fa5c70 100644 --- a/db/access.php +++ b/db/access.php @@ -24,170 +24,170 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ - 'mod/scheduler:addinstance' => array( + 'mod/scheduler:addinstance' => [ 'riskbitmask' => RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/course:manageactivities', + ], - 'mod/scheduler:appoint' => array( + 'mod/scheduler:appoint' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, - ) - ), + ], + ], - 'mod/scheduler:attend' => array( + 'mod/scheduler:attend' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW - ) - ), + 'editingteacher' => CAP_ALLOW, + ], + ], - 'mod/scheduler:manage' => array( + 'mod/scheduler:manage' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:manageallappointments' => array( + 'mod/scheduler:manageallappointments' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:canscheduletootherteachers' => array( + 'mod/scheduler:canscheduletootherteachers' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:canseeotherteachersbooking' => array( + 'mod/scheduler:canseeotherteachersbooking' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:seeoverviewoutsideactivity' => array( + 'mod/scheduler:seeoverviewoutsideactivity' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:editallattended' => array( + 'mod/scheduler:editallattended' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:editallgrades' => array( + 'mod/scheduler:editallgrades' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:editallnotes' => array( + 'mod/scheduler:editallnotes' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:disengage' => array( + 'mod/scheduler:disengage' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:viewslots' => array( + 'mod/scheduler:viewslots' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, - ), - 'clonepermissionsfrom' => 'mod/scheduler:appoint' - ), + ], + 'clonepermissionsfrom' => 'mod/scheduler:appoint', + ], - 'mod/scheduler:viewfullslots' => array( + 'mod/scheduler:viewfullslots' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( - ) - ), + 'archetypes' => [ + ], + ], - 'mod/scheduler:seeotherstudentsbooking' => array( + 'mod/scheduler:seeotherstudentsbooking' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/scheduler:seeotherstudentsresults' => array( + 'mod/scheduler:seeotherstudentsresults' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ) + 'manager' => CAP_ALLOW, + ], + ], -); +]; diff --git a/db/messages.php b/db/messages.php index 702fcf2a..a9f04b3c 100644 --- a/db/messages.php +++ b/db/messages.php @@ -24,18 +24,18 @@ defined('MOODLE_INTERNAL') || die(); -$messageproviders = array ( +$messageproviders = [ // Invitations to make a booking. - 'invitation' => array( - ), + 'invitation' => [ + ], // Notifications about bookings (to teachers or students). - 'bookingnotification' => array( - ), + 'bookingnotification' => [ + ], // Automated reminders about upcoming appointments. - 'reminder' => array( - ), + 'reminder' => [ + ], -); +]; diff --git a/db/services.php b/db/services.php index 6faa22da..0736f6e0 100644 --- a/db/services.php +++ b/db/services.php @@ -24,14 +24,14 @@ defined('MOODLE_INTERNAL') || die(); -$functions = array( +$functions = [ - 'mod_scheduler_studentid' => array( + 'mod_scheduler_studentid' => [ 'classname' => 'mod_scheduler\external', 'methodname' => 'studentid', 'description' => 'Retrieve the list of potential studentids.', 'type' => 'read', 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) - ), -); + 'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE], + ], +]; diff --git a/db/tasks.php b/db/tasks.php index 6a7709df..6b0f092f 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -24,21 +24,21 @@ defined('MOODLE_INTERNAL') || die(); -$tasks = array( - array( +$tasks = [ + [ 'classname' => 'mod_scheduler\task\send_reminders', 'minute' => 'R', 'hour' => '*', 'day' => '*', 'dayofweek' => '*', - 'month' => '*' - ), - array( + 'month' => '*', + ], + [ 'classname' => 'mod_scheduler\task\purge_unused_slots', 'minute' => '*/5', 'hour' => '*', 'day' => '*', 'dayofweek' => '*', - 'month' => '*' - ) -); + 'month' => '*', + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 8dbee09d..8ba33778 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -48,9 +48,9 @@ function scheduler_migrate_groupmode($sid) { } else { $g = -1; } - $DB->set_field('scheduler', 'bookingrouping', $g, array('id' => $sid)); - $DB->set_field('course_modules', 'groupmode', 0, array('id' => $cm->id)); - $DB->set_field('course_modules', 'groupingid', 0, array('id' => $cm->id)); + $DB->set_field('scheduler', 'bookingrouping', $g, ['id' => $sid]); + $DB->set_field('course_modules', 'groupmode', 0, ['id' => $cm->id]); + $DB->set_field('course_modules', 'groupingid', 0, ['id' => $cm->id]); } } @@ -106,7 +106,7 @@ function xmldb_scheduler_upgrade($oldversion=0) { // Conditionally migrate to html format in intro. if ($CFG->texteditors !== 'textarea') { - $rs = $DB->get_recordset('scheduler', array('introformat' => FORMAT_MOODLE), + $rs = $DB->get_recordset('scheduler', ['introformat' => FORMAT_MOODLE], '', 'id, intro, introformat'); foreach ($rs as $q) { $q->intro = text_to_html($q->intro, false, false, true); @@ -198,7 +198,7 @@ function xmldb_scheduler_upgrade($oldversion=0) { // Define index schedulerid-teacherid (not unique) to be added to scheduler_slots. $table = new xmldb_table('scheduler_slots'); - $index = new xmldb_index('schedulerid-teacherid', XMLDB_INDEX_NOTUNIQUE, array('schedulerid', 'teacherid')); + $index = new xmldb_index('schedulerid-teacherid', XMLDB_INDEX_NOTUNIQUE, ['schedulerid', 'teacherid']); // Conditionally launch add index schedulerid-teacherid. if (!$dbman->index_exists($table, $index)) { @@ -207,7 +207,7 @@ function xmldb_scheduler_upgrade($oldversion=0) { // Define index slotid (not unique) to be added to scheduler_appointment. $table = new xmldb_table('scheduler_appointment'); - $index = new xmldb_index('slotid', XMLDB_INDEX_NOTUNIQUE, array('slotid')); + $index = new xmldb_index('slotid', XMLDB_INDEX_NOTUNIQUE, ['slotid']); // Conditionally add index slotid. if (!$dbman->index_exists($table, $index)) { @@ -216,7 +216,7 @@ function xmldb_scheduler_upgrade($oldversion=0) { // Define index studentid (not unique) to be added to scheduler_appointment. $table = new xmldb_table('scheduler_appointment'); - $index = new xmldb_index('studentid', XMLDB_INDEX_NOTUNIQUE, array('studentid')); + $index = new xmldb_index('studentid', XMLDB_INDEX_NOTUNIQUE, ['studentid']); // Conditionally add index studentid. if (!$dbman->index_exists($table, $index)) { @@ -225,7 +225,7 @@ function xmldb_scheduler_upgrade($oldversion=0) { // Convert old calendar events. $sql = 'UPDATE {event} SET modulename = ? WHERE eventtype LIKE ? OR eventtype LIKE ?'; - $DB->execute($sql, array('scheduler', 'SSsup:%', 'SSstu:%')); + $DB->execute($sql, ['scheduler', 'SSsup:%', 'SSstu:%']); // Savepoint reached. upgrade_mod_savepoint(true, 2014071300, 'scheduler'); diff --git a/export.php b/export.php index c3dea461..3e1c7ccf 100644 --- a/export.php +++ b/export.php @@ -35,8 +35,8 @@ $currentgroupid = groups_get_activity_group($scheduler->cm, true); } -$actionurl = new moodle_url('/mod/scheduler/view.php', array('what' => 'export', 'id' => $scheduler->cmid)); -$returnurl = new moodle_url('/mod/scheduler/view.php', array('what' => 'view', 'id' => $scheduler->cmid)); +$actionurl = new moodle_url('/mod/scheduler/view.php', ['what' => 'export', 'id' => $scheduler->cmid]); +$returnurl = new moodle_url('/mod/scheduler/view.php', ['what' => 'view', 'id' => $scheduler->cmid]); $PAGE->set_url($actionurl); $mform = new scheduler_export_form($actionurl, $scheduler); @@ -47,7 +47,7 @@ $data = $mform->get_data(); if ($data) { $availablefields = scheduler_get_export_fields($scheduler); - $selectedfields = array(); + $selectedfields = []; foreach ($availablefields as $field) { $inputid = 'field-'.$field->get_id(); if (isset($data->{$inputid}) && $data->{$inputid} == 1) { @@ -70,7 +70,7 @@ echo $OUTPUT->header(); // Print top tabs. - $taburl = new moodle_url('/mod/scheduler/view.php', array('id' => $scheduler->cmid, 'what' => 'export')); + $taburl = new moodle_url('/mod/scheduler/view.php', ['id' => $scheduler->cmid, 'what' => 'export']); echo $output->teacherview_tabs($scheduler, $permissions, $taburl, 'export'); if ($groupmode) { diff --git a/exportform.php b/exportform.php index e092eec0..cee87e13 100644 --- a/exportform.php +++ b/exportform.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\scheduler; +use mod_scheduler\model\scheduler; require_once($CFG->libdir.'/formslib.php'); require_once($CFG->dirroot.'/mod/scheduler/exportlib.php'); @@ -65,7 +65,7 @@ protected function definition() { // General introduction. $mform->addElement('header', 'general', get_string('general', 'form')); - $radios = array(); + $radios = []; $radios[] = $mform->createElement('radio', 'content', '', get_string('onelineperslot', 'scheduler'), 'onelineperslot'); $radios[] = $mform->createElement('radio', 'content', '', @@ -78,13 +78,13 @@ protected function definition() { $mform->addHelpButton('contentgroup', 'contentformat', 'scheduler'); if (has_capability('mod/scheduler:canseeotherteachersbooking', $this->scheduler->get_context())) { - $selopt = array('me' => get_string('myself', 'scheduler'), - 'all' => get_string ('everyone', 'scheduler')); + $selopt = ['me' => get_string('myself', 'scheduler'), + 'all' => get_string ('everyone', 'scheduler'), ]; $mform->addElement('select', 'includewhom', get_string('includeslotsfor', 'scheduler'), $selopt); $mform->setDefault('includewhom', 'all'); - $selopt = array('all' => get_string('allononepage', 'scheduler'), - 'perteacher' => get_string('pageperteacher', 'scheduler', $this->scheduler->get_teacher_name()) ); + $selopt = ['all' => get_string('allononepage', 'scheduler'), + 'perteacher' => get_string('pageperteacher', 'scheduler', $this->scheduler->get_teacher_name()), ]; $mform->addElement('select', 'paging', get_string('pagination', 'scheduler'), $selopt); $mform->addHelpButton('paging', 'pagination', 'scheduler'); @@ -93,7 +93,7 @@ protected function definition() { $timeoptions = [ 0 => get_string('exporttimerangeall', 'scheduler'), 1 => get_string('exporttimerangefuture', 'scheduler'), - 2 => get_string('exporttimerangepast', 'scheduler') + 2 => get_string('exporttimerangepast', 'scheduler'), ]; $mform->addElement('select', 'timerange', get_string('exporttimerange', 'scheduler'), $timeoptions); $mform->setDefault('timerange', 0); @@ -120,7 +120,7 @@ protected function definition() { $mform->addElement('header', 'fileformathdr', get_string('fileformat', 'scheduler')); $mform->addHelpButton('fileformathdr', 'fileformat', 'scheduler'); - $radios = array(); + $radios = []; $radios[] = $mform->createElement('radio', 'outputformat', '', get_string('csvformat', 'scheduler'), 'csv'); $radios[] = $mform->createElement('radio', 'outputformat', '', get_string('excelformat', 'scheduler'), 'xls'); $radios[] = $mform->createElement('radio', 'outputformat', '', get_string('odsformat', 'scheduler'), 'ods'); @@ -129,24 +129,24 @@ protected function definition() { $mform->addGroup($radios, 'outputformatgroup', get_string('fileformat', 'scheduler'), null, false); $mform->setDefault('outputformat', 'csv'); - $selopt = array('comma' => get_string('sepcomma', 'scheduler'), + $selopt = ['comma' => get_string('sepcomma', 'scheduler'), 'colon' => get_string('sepcolon', 'scheduler'), 'semicolon' => get_string('sepsemicolon', 'scheduler'), - 'tab' => get_string('septab', 'scheduler')); + 'tab' => get_string('septab', 'scheduler'), ]; $mform->addElement('select', 'csvseparator', get_string('csvfieldseparator', 'scheduler'), $selopt); $mform->setDefault('csvseparator', 'comma'); $mform->disabledIf('csvseparator', 'outputformat', 'neq', 'csv'); - $selopt = array('P' => get_string('portrait', 'scheduler'), - 'L' => get_string('landscape', 'scheduler')); + $selopt = ['P' => get_string('portrait', 'scheduler'), + 'L' => get_string('landscape', 'scheduler'), ]; $mform->addElement('select', 'pdforientation', get_string('pdforientation', 'scheduler'), $selopt); $mform->disabledIf('pdforientation', 'outputformat', 'neq', 'pdf'); - $buttonarray = array(); + $buttonarray = []; $buttonarray[] = $mform->createElement('submit', 'preview', get_string('preview', 'scheduler')); $buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('createexport', 'scheduler')); $buttonarray[] = $mform->createElement('cancel'); - $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); $mform->closeHeaderBefore('buttonar'); } @@ -161,7 +161,7 @@ private function add_exportfield_group($groupid, $labelid) { $mform = $this->_form; $fields = scheduler_get_export_fields($this->scheduler); - $checkboxes = array(); + $checkboxes = []; foreach ($fields as $field) { if ($field->get_group() == $groupid && $field->is_available($this->scheduler)) { diff --git a/exportlib.php b/exportlib.php index 0a2b3341..a1f1f9a4 100644 --- a/exportlib.php +++ b/exportlib.php @@ -24,9 +24,9 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\scheduler; -use \mod_scheduler\model\slot; -use \mod_scheduler\model\appointment; +use mod_scheduler\model\scheduler; +use mod_scheduler\model\slot; +use mod_scheduler\model\appointment; require_once($CFG->dirroot.'/lib/excellib.class.php'); require_once($CFG->dirroot.'/lib/odslib.class.php'); @@ -98,7 +98,7 @@ public function get_header(scheduler $scheduler) { * @return array the header for this field */ public function get_headers(scheduler $scheduler) { - return array($this->get_header($scheduler)); + return [$this->get_header($scheduler)]; } /** @@ -160,7 +160,7 @@ abstract public function get_value(slot $slot, $appointment); * @return array an array of strings containing the column values */ public function get_values(slot $slot, $appointment) { - return array($this->get_value($slot, $appointment)); + return [$this->get_value($slot, $appointment)]; } } @@ -172,7 +172,7 @@ public function get_values(slot $slot, $appointment) { * @return array the fields as an array of scheduler_export_field objects. */ function scheduler_get_export_fields(scheduler $scheduler) { - $result = array(); + $result = []; $result[] = new slotdate_field(); $result[] = new scheduler_starttime_field(); $result[] = new scheduler_endtime_field(); @@ -1179,7 +1179,7 @@ public function get_value(slot $slot, $appointment) { $scheduler = $slot->get_scheduler(); $groups = groups_get_user_groups($scheduler->courseid, $appointment->studentid); $groupingid = $scheduler->get_cm()->groupingid; - $gn = array(); + $gn = []; foreach ($groups[$groupingid] as $groupid) { $gn[] = groups_get_group_name($groupid); } @@ -1254,7 +1254,7 @@ public function get_num_columns(scheduler $scheduler) { * @return array the header for this field */ public function get_headers(scheduler $scheduler) { - $result = array(); + $result = []; foreach ($this->coursegroups as $group) { $result[] = $group->name; } @@ -1285,7 +1285,7 @@ public function get_values(slot $slot, $appointment) { return ''; } $usergroups = groups_get_user_groups($slot->get_scheduler()->courseid, $appointment->studentid)[0]; - $result = array(); + $result = []; foreach ($this->coursegroups as $group) { $key = in_array($group->id, $usergroups) ? 'yes' : 'no'; $result[] = get_string($key); @@ -1700,7 +1700,7 @@ protected function compute_relative_widths($page) { foreach ($page->columnwidths as $width) { $sum += $width; } - $relwidths = array(); + $relwidths = []; for ($col = 0; $col < $cols; $col++) { if ($sum > 0 && isset($page->columnwidths[$col])) { $relwidths[$col] = (int) ($page->columnwidths[$col] / $sum * 100); @@ -1723,10 +1723,10 @@ public function start_page($title) { } else { $newpage = new stdClass; $newpage->title = $title; - $newpage->cells = array(); - $newpage->formats = array(); - $newpage->mergers = array(); - $newpage->columnwidths = array(); + $newpage->cells = []; + $newpage->formats = []; + $newpage->mergers = []; + $newpage->columnwidths = []; $this->pages[] = $newpage; $this->curpage = $newpage; } @@ -1913,7 +1913,7 @@ public function send($filename) { foreach ($this->pages as $page) { if ($page->title) { - $writer->add_data(array('*** '.$page->title.' ***')); + $writer->add_data(['*** '.$page->title.' ***']); } // Find extent of the table. @@ -1921,7 +1921,7 @@ public function send($filename) { $cols = $this->get_col_count($page); for ($row = 0; $row < $rows; $row++) { - $data = array(); + $data = []; $col = 0; while ($col < $cols) { if (isset($page->cells[$row][$col])) { @@ -1997,7 +1997,7 @@ public function send($filename) { $cols = $this->get_col_count($page); $relwidths = $this->compute_relative_widths($page); - $o = html_writer::start_tag('table', array('border' => 1, 'cellpadding' => 1)); + $o = html_writer::start_tag('table', ['border' => 1, 'cellpadding' => 1]); for ($row = 0; $row < $rows; $row++) { $o .= html_writer::start_tag('tr'); $col = 0; @@ -2009,7 +2009,7 @@ public function send($filename) { $span = $mergewidth; } } - $opts = array(); + $opts = []; if ($row == 0 && $relwidths[$col] > 0) { $opts['width'] = $relwidths[$col].'%'; } @@ -2210,7 +2210,7 @@ protected function write_row($row, slot $slot, $appointment, array $fields, $inc */ protected function write_row_summary($row, slot $slot, array $fields) { - $strs = array(); + $strs = []; $cols = 0; foreach ($fields as $field) { if ($field->get_group() == 'slot') { diff --git a/index.php b/index.php index 4b910fb1..305e1a43 100644 --- a/index.php +++ b/index.php @@ -28,17 +28,17 @@ require_once(dirname(__FILE__).'/lib.php'); $id = required_param('id', PARAM_INT); // Course id. -$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST); +$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST); -$PAGE->set_url('/mod/scheduler/index.php', array('id' => $id)); +$PAGE->set_url('/mod/scheduler/index.php', ['id' => $id]); $PAGE->set_pagelayout('incourse'); $coursecontext = context_course::instance($id); require_login($course->id); -$event = \mod_scheduler\event\course_module_instance_list_viewed::create(array( - 'context' => $coursecontext -)); +$event = \mod_scheduler\event\course_module_instance_list_viewed::create([ + 'context' => $coursecontext, +]); $event->add_record_snapshot('course', $course); $event->trigger(); @@ -72,26 +72,26 @@ $table = new html_table(); if ($course->format == 'weeks') { - $table->head = array ($strweek, $strname); - $table->align = array ('CENTER', 'LEFT'); + $table->head = [$strweek, $strname]; + $table->align = ['CENTER', 'LEFT']; } else if ($course->format == 'topics') { - $table->head = array ($strtopic, $strname); - $table->align = array ('CENTER', 'LEFT', 'LEFT', 'LEFT'); + $table->head = [$strtopic, $strname]; + $table->align = ['CENTER', 'LEFT', 'LEFT', 'LEFT']; } else { - $table->head = array ($strname); - $table->align = array ('LEFT', 'LEFT', 'LEFT'); + $table->head = [$strname]; + $table->align = ['LEFT', 'LEFT', 'LEFT']; } foreach ($schedulers as $scheduler) { - $url = new moodle_url('/mod/scheduler/view.php', array('id' => $scheduler->coursemodule)); + $url = new moodle_url('/mod/scheduler/view.php', ['id' => $scheduler->coursemodule]); // Show dimmed if the mod is hidden. - $attr = $scheduler->visible ? null : array('class' => 'dimmed'); + $attr = $scheduler->visible ? null : ['class' => 'dimmed']; $link = html_writer::link($url, $scheduler->name, $attr); if ($scheduler->visible || has_capability('moodle/course:viewhiddenactivities', $coursecontext)) { if ($course->format == 'weeks' || $course->format == 'topics') { - $table->data[] = array ($scheduler->section, $link); + $table->data[] = [$scheduler->section, $link]; } else { - $table->data[] = array ($link); + $table->data[] = [$link]; } } } diff --git a/lang/en/scheduler.php b/lang/en/scheduler.php index 3b2b19db..3fa13b7e 100644 --- a/lang/en/scheduler.php +++ b/lang/en/scheduler.php @@ -22,6 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +// Let codechecker ignore some sniffs for this file as it is perfectly well ordered, just not alphabetically. +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder + $string['pluginname'] = 'Scheduler'; $string['pluginadministration'] = 'Scheduler administration'; $string['modulename'] = 'Scheduler'; diff --git a/lib.php b/lib.php index 14119c92..2b9303c1 100644 --- a/lib.php +++ b/lib.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\scheduler; +use mod_scheduler\model\scheduler; // Library of functions and constants for module Scheduler. @@ -61,7 +61,7 @@ function scheduler_add_instance($data, $mform = null) { $data->id = $DB->insert_record('scheduler', $data); - $DB->set_field('course_modules', 'instance', $data->id, array('id' => $cmid)); + $DB->set_field('course_modules', 'instance', $data->id, ['id' => $cmid]); $context = context_module::instance($cmid); if ($mform) { @@ -78,13 +78,21 @@ function scheduler_add_instance($data, $mform = null) { return $data->id; } +/** + * Callback function for the student autocomplete. + * + * @param int $value user id + * @return bool|string + * @throws \core\exception\moodle_exception + * @throws dml_exception + */ function scheduler_student_autocomplete_callback($value) { global $OUTPUT; $fields = 'id ' . \core_user\fields::for_name()->get_sql()->selects; $user = \core_user::get_user($value, $fields); $useroptiondata = [ - 'fullname' => fullname($user) + 'fullname' => fullname($user), ]; return $OUTPUT->render_from_template('mod_scheduler/studentid', $useroptiondata); @@ -137,7 +145,7 @@ function scheduler_update_instance($data, $mform) { function scheduler_delete_instance($id) { global $DB; - if (! $DB->record_exists('scheduler', array('id' => $id))) { + if (! $DB->record_exists('scheduler', ['id' => $id])) { return false; } @@ -145,7 +153,7 @@ function scheduler_delete_instance($id) { $scheduler->delete(); // Clean up any possibly remaining event records. - $params = array('modulename' => 'scheduler', 'instance' => $id); + $params = ['modulename' => 'scheduler', 'instance' => $id]; $DB->delete_records('event', $params); return true; @@ -173,7 +181,7 @@ function scheduler_user_outline($course, $user, $mod, $scheduler) { $text = ''; if ($attended + $upcoming > 0) { - $a = array('attended' => $attended, 'upcoming' => $upcoming); + $a = ['attended' => $attended, 'upcoming' => $upcoming]; $text .= get_string('outlineappointments', 'scheduler', $a); } @@ -259,7 +267,7 @@ function scheduler_scale_used($cmid, $scaleid) { $return = false; // Note: scales are assigned using negative index in the grade field of the appointment (see mod/assignement/lib.php). - $rec = $DB->get_record('scheduler', array('id' => $cmid, 'scale' => -$scaleid)); + $rec = $DB->get_record('scheduler', ['id' => $cmid, 'scale' => -$scaleid]); if (!empty($rec) && !empty($scaleid)) { $return = true; @@ -279,7 +287,7 @@ function scheduler_scale_used($cmid, $scaleid) { function scheduler_scale_used_anywhere($scaleid) { global $DB; - if ($scaleid && $DB->record_exists('scheduler', array('scale' => -$scaleid))) { + if ($scaleid && $DB->record_exists('scheduler', ['scale' => -$scaleid])) { return true; } else { return false; @@ -304,7 +312,7 @@ function scheduler_reset_course_form_definition(&$mform) { $mform->addElement('header', 'schedulerheader', get_string('modulenameplural', 'scheduler')); - if ($DB->record_exists('scheduler', array('course' => $COURSE->id))) { + if ($DB->record_exists('scheduler', ['course' => $COURSE->id])) { $mform->addElement('checkbox', 'reset_scheduler_slots', get_string('resetslots', 'scheduler')); $mform->addElement('checkbox', 'reset_scheduler_appointments', get_string('resetappointments', 'scheduler')); @@ -318,7 +326,7 @@ function scheduler_reset_course_form_definition(&$mform) { * @param stdClass $course the course in which the reset takes place */ function scheduler_reset_course_form_defaults($course) { - return array('reset_scheduler_slots' => 1, 'reset_scheduler_appointments' => 1); + return ['reset_scheduler_slots' => 1, 'reset_scheduler_appointments' => 1]; } @@ -333,7 +341,7 @@ function scheduler_reset_course_form_defaults($course) { function scheduler_reset_userdata($data) { global $CFG, $DB; - $status = array(); + $status = []; $componentstr = get_string('modulenameplural', 'scheduler'); $success = true; @@ -347,16 +355,16 @@ function scheduler_reset_userdata($data) { if (!empty($data->reset_scheduler_slots) ) { $scheduler->delete_all_slots(); - $status[] = array('component' => $componentstr, 'item' => get_string('resetslots', 'scheduler'), 'error' => false); + $status[] = ['component' => $componentstr, 'item' => get_string('resetslots', 'scheduler'), 'error' => false]; } else if (!empty($data->reset_scheduler_appointments) ) { foreach ($scheduler->get_all_slots() as $slot) { $slot->delete_all_appointments(); } - $status[] = array( + $status[] = [ 'component' => $componentstr, 'item' => get_string('resetappointments', 'scheduler'), - 'error' => !$success - ); + 'error' => !$success, + ]; } } } @@ -449,15 +457,15 @@ function scheduler_grade_item_update($scheduler, $grades=null) { if (!isset($scheduler->courseid)) { $scheduler->courseid = $scheduler->course; } - $moduleid = $DB->get_field('modules', 'id', array('name' => 'scheduler')); - $cmid = $DB->get_field('course_modules', 'id', array('module' => $moduleid, 'instance' => $scheduler->id)); + $moduleid = $DB->get_field('modules', 'id', ['name' => 'scheduler']); + $cmid = $DB->get_field('course_modules', 'id', ['module' => $moduleid, 'instance' => $scheduler->id]); if ($scheduler->scale == 0) { // Delete any grade item. scheduler_grade_item_delete($scheduler); return 0; } else { - $params = array('itemname' => $scheduler->name, 'idnumber' => $cmid); + $params = ['itemname' => $scheduler->name, 'idnumber' => $cmid]; if ($scheduler->scale > 0) { $params['gradetype'] = GRADE_TYPE_VALUE; @@ -527,7 +535,7 @@ function scheduler_grade_item_delete($scheduler) { $scheduler->courseid = $scheduler->course; } - return grade_update('mod/scheduler', $scheduler->courseid, 'mod', 'scheduler', $scheduler->id, 0, null, array('deleted' => 1)); + return grade_update('mod/scheduler', $scheduler->courseid, 'mod', 'scheduler', $scheduler->id, 0, null, ['deleted' => 1]); } @@ -546,12 +554,12 @@ function scheduler_grade_item_delete($scheduler) { * @return array */ function scheduler_get_file_areas($course, $cm, $context) { - return array( + return [ 'bookinginstructions' => get_string('bookinginstructions', 'scheduler'), 'slotnote' => get_string('areaslotnote', 'scheduler'), 'appointmentnote' => get_string('areaappointmentnote', 'scheduler'), - 'teachernote' => get_string('areateachernote', 'scheduler') - ); + 'teachernote' => get_string('areateachernote', 'scheduler'), + ]; } /** @@ -573,8 +581,8 @@ function scheduler_get_file_info($browser, $areas, $course, $cm, $context, $file // Note: 'intro' area is handled in file_browser automatically. - if (!has_any_capability(array('mod/scheduler:appoint', 'mod/scheduler:attend', - 'mod/scheduler:viewotherteachersbooking', 'mod/scheduler:manageallappointments'), $context)) { + if (!has_any_capability(['mod/scheduler:appoint', 'mod/scheduler:attend', + 'mod/scheduler:viewotherteachersbooking', 'mod/scheduler:manageallappointments', ], $context)) { return null; } @@ -652,7 +660,7 @@ function scheduler_get_file_info($browser, $areas, $course, $cm, $context, $file * @param array $options additional options affecting the file serving * @return bool false if file not found, does not return if found - just send the file */ -function scheduler_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { +function scheduler_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=[]) { global $CFG, $DB, $USER; if ($context->contextlevel != CONTEXT_MODULE) { @@ -660,7 +668,7 @@ function scheduler_pluginfile($course, $cm, $context, $filearea, $args, $forcedo } require_course_login($course, true, $cm); - if (!has_any_capability(array('mod/scheduler:appoint', 'mod/scheduler:attend'), $context)) { + if (!has_any_capability(['mod/scheduler:appoint', 'mod/scheduler:attend'], $context)) { return false; } @@ -702,7 +710,7 @@ function scheduler_pluginfile($course, $cm, $context, $filearea, $args, $forcedo $permissions->ensure($permissions->teacher_can_see_slot($slot)); } else if ($filearea === 'bookinginstructions') { - $caps = array('moodle/course:manageactivities', 'mod/scheduler:appoint'); + $caps = ['moodle/course:manageactivities', 'mod/scheduler:appoint']; if (!has_any_capability($caps, $context)) { return false; } diff --git a/locallib.php b/locallib.php index 60ce8232..516b11cf 100644 --- a/locallib.php +++ b/locallib.php @@ -43,8 +43,8 @@ function scheduler_delete_calendar_events($slot) { $teachereventtype = "SSsup:{$slot->id}"; $studenteventtype = "SSstu:{$slot->id}"; - $teacherdeletionsuccess = $DB->delete_records('event', array('eventtype' => $teachereventtype)); - $studentdeletionsuccess = $DB->delete_records('event', array('eventtype' => $studenteventtype)); + $teacherdeletionsuccess = $DB->delete_records('event', ['eventtype' => $teachereventtype]); + $studentdeletionsuccess = $DB->delete_records('event', ['eventtype' => $studenteventtype]); return ($teacherdeletionsuccess && $studentdeletionsuccess); // This return may not be meaningful if the delete records functions do not return anything meaningful. @@ -109,7 +109,7 @@ function scheduler_print_user($user, $course, $messageselect=false, $return=fals // Get the hidden field list. if (has_capability('moodle/course:viewhiddenuserfields', $context)) { - $hiddenfields = array(); + $hiddenfields = []; } else { $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); } @@ -117,7 +117,7 @@ function scheduler_print_user($user, $course, $messageselect=false, $return=fals $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= '
'; - $output .= $OUTPUT->user_picture($user, array('size' => 100)); + $output .= $OUTPUT->user_picture($user, ['size' => 100]); $output .= ''; $output .= '
'.fullname($user, has_capability('moodle/site:viewfullnames', $context)).'
'; @@ -216,12 +216,12 @@ public function __construct($browser, $course, $cm, $context, $areas, $filearea) * @return array with keys contextid, filearea, itemid, filepath and filename */ public function get_params() { - return array('contextid' => $this->context->id, + return ['contextid' => $this->context->id, 'component' => 'mod_scheduler', 'filearea' => $this->filearea, 'itemid' => null, 'filepath' => null, - 'filename' => null); + 'filename' => null, ]; } /** @@ -269,9 +269,9 @@ public function get_children() { private function get_filtered_children($extensions = '*', $countonly = false, $returnemptyfolders = false) { global $DB; - $params = array('contextid' => $this->context->id, + $params = ['contextid' => $this->context->id, 'component' => 'mod_scheduler', - 'filearea' => $this->filearea); + 'filearea' => $this->filearea, ]; $sql = "SELECT DISTINCT f.itemid AS id FROM {files} f WHERE f.contextid = :contextid @@ -286,7 +286,7 @@ private function get_filtered_children($extensions = '*', $countonly = false, $r $params = array_merge($params, $params2); $rs = $DB->get_recordset_sql($sql, $params); - $children = array(); + $children = []; foreach ($rs as $record) { if ($child = $this->browser->get_file_info($this->context, 'mod_scheduler', $this->filearea, $record->id)) { if ($returnemptyfolders || $child->count_non_empty_children($extensions)) { diff --git a/mailtemplatelib.php b/mailtemplatelib.php index 85d6ad3b..ee7ec034 100644 --- a/mailtemplatelib.php +++ b/mailtemplatelib.php @@ -22,8 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use \mod_scheduler\model\scheduler; -use \mod_scheduler\model\slot; +use mod_scheduler\model\scheduler; +use mod_scheduler\model\slot; /** * Message functionality for scheduler module @@ -71,7 +71,7 @@ protected static function get_message_language($user, $course) { * */ public static function compile_mail_template($template, $format, $parameters, $module = 'scheduler', $lang = null) { - $params = array (); + $params = []; foreach ($parameters as $key => $value) { $params[strtolower($key)] = $value; } @@ -109,13 +109,13 @@ public static function send_message_from_template($modulename, $messagename, $is $lang = self::get_message_language($recipient, $course); - $defaultvars = array ( + $defaultvars = [ 'SITE' => $SITE->fullname, 'SITE_SHORT' => $SITE->shortname, 'SITE_URL' => $CFG->wwwroot, 'SENDER' => fullname ( $sender ), - 'RECIPIENT' => fullname ( $recipient ) - ); + 'RECIPIENT' => fullname ( $recipient ), + ]; if ($course) { $defaultvars['COURSE_SHORT'] = format_string($course->shortname); @@ -167,7 +167,7 @@ public static function get_scheduler_variables(scheduler $scheduler, $slot, $tz = core_date::get_user_timezone($recipient); - $vars = array(); + $vars = []; if ($scheduler) { $vars['MODULE'] = format_string($scheduler->name); diff --git a/message_form.php b/message_form.php index db55ea83..b0a33d6f 100644 --- a/message_form.php +++ b/message_form.php @@ -62,7 +62,7 @@ protected function definition() { $mform = $this->_form; // Select users to sent the message to. - $checkboxes = array(); + $checkboxes = []; $recipients = $this->_customdata['recipients']; foreach ($recipients as $recipient) { $inputid = 'recipient['.$recipient->id.']'; @@ -73,7 +73,7 @@ protected function definition() { $mform->addGroup($checkboxes, 'recipients', get_string('recipients', 'scheduler'), null, false); if (get_config('mod_scheduler', 'showemailplain')) { - $maillist = array(); + $maillist = []; foreach ($recipients as $recipient) { $maillist[] = trim($recipient->email); } @@ -84,7 +84,7 @@ protected function definition() { $mform->addElement('selectyesno', 'copytomyself', get_string('copytomyself', 'scheduler')); $mform->setDefault('copytomyself', true); - $mform->addElement('text', 'subject', get_string('messagesubject', 'scheduler'), array('size' => '60')); + $mform->addElement('text', 'subject', get_string('messagesubject', 'scheduler'), ['size' => '60']); $mform->setType('subject', PARAM_TEXT); $mform->addRule('subject', null, 'required'); if (isset($this->_customdata['subject'])) { @@ -92,16 +92,16 @@ protected function definition() { } $bodyedit = $mform->addElement('editor', 'body', get_string('messagebody', 'scheduler'), - array('rows' => 15, 'columns' => 60), array('collapsed' => true)); + ['rows' => 15, 'columns' => 60], ['collapsed' => true]); $mform->setType('body', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. if (isset($this->_customdata['body'])) { - $bodyedit->setValue(array('text' => $this->_customdata['body'])); + $bodyedit->setValue(['text' => $this->_customdata['body']]); } - $buttonarray = array(); + $buttonarray = []; $buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('sendmessage', 'scheduler')); $buttonarray[] = $mform->createElement('cancel'); - $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); } diff --git a/mod_form.php b/mod_form.php index 4dccef8c..2aa0898c 100644 --- a/mod_form.php +++ b/mod_form.php @@ -49,7 +49,7 @@ public function definition() { // General introduction. $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 { @@ -64,15 +64,15 @@ public function definition() { $mform->addElement('header', 'optionhdr', get_string('options', 'scheduler')); $mform->setExpanded('optionhdr'); - $mform->addElement('text', 'staffrolename', get_string('staffrolename', 'scheduler'), array('size' => '48')); + $mform->addElement('text', 'staffrolename', get_string('staffrolename', 'scheduler'), ['size' => '48']); $mform->setType('staffrolename', PARAM_TEXT); $mform->addRule('staffrolename', get_string('error'), 'maxlength', 255); $mform->addHelpButton('staffrolename', 'staffrolename', 'scheduler'); - $modegroup = array(); + $modegroup = []; $modegroup[] = $mform->createElement('static', 'modeintro', '', get_string('modeintro', 'scheduler')); - $maxbookoptions = array(); + $maxbookoptions = []; $maxbookoptions['0'] = get_string('unlimited', 'scheduler'); for ($i = 1; $i <= 10; $i++) { $maxbookoptions[(string)$i] = $i; @@ -91,10 +91,10 @@ public function definition() { $mform->addHelpButton('modegrp', 'appointmentmode', 'scheduler'); if (get_config('mod_scheduler', 'groupscheduling')) { - $selopt = array( + $selopt = [ -1 => get_string('no'), - 0 => get_string('yesallgroups', 'scheduler') - ); + 0 => get_string('yesallgroups', 'scheduler'), + ]; $groupings = groups_get_all_groupings($COURSE->id); foreach ($groupings as $grouping) { $selopt[$grouping->id] = get_string('yesingrouping', 'scheduler', $grouping->name); @@ -104,10 +104,10 @@ public function definition() { $mform->setDefault('bookingrouping', '-1'); } - $mform->addElement('duration', 'guardtime', get_string('guardtime', 'scheduler'), array('optional' => true)); + $mform->addElement('duration', 'guardtime', get_string('guardtime', 'scheduler'), ['optional' => true]); $mform->addHelpButton('guardtime', 'guardtime', 'scheduler'); - $mform->addElement('text', 'defaultslotduration', get_string('defaultslotduration', 'scheduler'), array('size' => '2')); + $mform->addElement('text', 'defaultslotduration', get_string('defaultslotduration', 'scheduler'), ['size' => '2']); $mform->setType('defaultslotduration', PARAM_INT); $mform->addHelpButton('defaultslotduration', 'defaultslotduration', 'scheduler'); $mform->setDefault('defaultslotduration', 15); @@ -139,10 +139,10 @@ public function definition() { $mform->addElement('selectyesno', 'usebookingform', get_string('usebookingform', 'scheduler')); $mform->addHelpButton('usebookingform', 'usebookingform', 'scheduler'); - $this->editoroptions = array('trusttext' => true, 'maxfiles' => -1, 'maxbytes' => 0, - 'context' => $this->context, 'collapsed' => true); + $this->editoroptions = ['trusttext' => true, 'maxfiles' => -1, 'maxbytes' => 0, + 'context' => $this->context, 'collapsed' => true, ]; $mform->addElement('editor', 'bookinginstructions_editor', get_string('bookinginstructions', 'scheduler'), - array('rows' => 3, 'columns' => 60), $this->editoroptions); + ['rows' => 3, 'columns' => 60], $this->editoroptions); $mform->setType('bookinginstructions', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. $mform->disabledIf('bookinginstructions_editor', 'usebookingform', 'eq', '0'); $mform->addHelpButton('bookinginstructions_editor', 'bookinginstructions', 'scheduler'); @@ -155,9 +155,9 @@ public function definition() { $mform->disabledIf('usestudentnotes', 'usebookingform', 'eq', '0'); $mform->addHelpButton('usestudentnotes', 'usestudentnotes', 'scheduler'); - $uploadgroup = array(); + $uploadgroup = []; - $filechoices = array(); + $filechoices = []; for ($i = 0; $i <= get_config('mod_scheduler', 'uploadmaxfiles'); $i++) { $filechoices[$i] = $i; } diff --git a/renderable.php b/renderable.php index 38c3bb7f..f7d8eea1 100644 --- a/renderable.php +++ b/renderable.php @@ -24,9 +24,9 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\scheduler; -use \mod_scheduler\model\slot; -use \mod_scheduler\model\appointment; +use mod_scheduler\model\scheduler; +use mod_scheduler\model\slot; +use mod_scheduler\model\appointment; /** * This class represents a table of slots associated with one student @@ -37,7 +37,7 @@ class scheduler_slot_table implements renderable { /** @var array list of slots in this table */ - public $slots = array(); + public $slots = []; /** @var scheduler the scheduler that the slots are in */ public $scheduler; @@ -143,7 +143,7 @@ public function __construct(scheduler $scheduler, $showgrades=true, $actionurl = class scheduler_student_list implements renderable { /** @var array list of students to be displayed */ - public $students = array(); + public $students = []; /** @var scheduler the scheduler in whose context the list is */ public $scheduler; @@ -232,7 +232,7 @@ class scheduler_slot_booker implements renderable { /** * @var array list of slots to be displayed */ - public $slots = array(); + public $slots = []; /** * @var scheduler scheduler in whose context the list is @@ -302,12 +302,12 @@ class scheduler_command_bar implements renderable { /** * @var array list of drop-down menus in the command bar */ - public $menus = array(); + public $menus = []; /** * @var array list of action_link objects used in the menu */ - public $linkactions = array(); + public $linkactions = []; /** * @var string title of the menu @@ -338,8 +338,8 @@ public function add_group($title, array $actions) { */ public function action_link(moodle_url $url, $titlekey, $iconkey, $confirmkey = null, $id = null) { $title = get_string($titlekey, 'scheduler'); - $pix = new pix_icon($iconkey, $title, 'moodle', array('class' => 'iconsmall', 'title' => '')); - $attributes = array(); + $pix = new pix_icon($iconkey, $title, 'moodle', ['class' => 'iconsmall', 'title' => '']); + $attributes = []; if ($id) { $attributes['id'] = $id; } @@ -363,8 +363,8 @@ public function action_link(moodle_url $url, $titlekey, $iconkey, $confirmkey = */ public function action_menu_link(moodle_url $url, $titlekey, $iconkey, $confirmkey = null, $id = null) { $title = get_string($titlekey, 'scheduler'); - $pix = new pix_icon($iconkey, $title, 'moodle', array('class' => 'iconsmall', 'title' => '')); - $attributes = array(); + $pix = new pix_icon($iconkey, $title, 'moodle', ['class' => 'iconsmall', 'title' => '']); + $attributes = []; if ($id) { $attributes['id'] = $id; } @@ -395,7 +395,7 @@ class scheduler_slot_manager implements renderable { /** * @var array list of slots */ - public $slots = array(); + public $slots = []; /** * @var scheduler scheduler in whose context the list is @@ -460,7 +460,7 @@ class scheduler_scheduling_list implements renderable { /** * @var array lines in the list */ - public $lines = array(); + public $lines = []; /** * @var scheduler the scheduler in whose context the list is @@ -566,7 +566,7 @@ class scheduler_conflict_list implements renderable { /** * @var array list of conflicts */ - public $conflicts = array(); + public $conflicts = []; /** * Add a conflict to the list. @@ -688,7 +688,7 @@ public static function make_from_appointment(slot $slot, appointment $appointmen $info->appointment = $appointment; $info->scheduler = $slot->get_scheduler(); $info->showslotinfo = true; - $info->showboookinginfo = true; + $info->showbookinginfo = true; $info->showstudentdata = $info->scheduler->uses_studentdata(); $info->showresult = true; $info->onstudentside = $onstudentside; @@ -711,7 +711,7 @@ public static function make_for_teacher(slot $slot, appointment $appointment) { $info->appointment = $appointment; $info->scheduler = $slot->get_scheduler(); $info->showslotinfo = true; - $info->showboookinginfo = false; + $info->showbookinginfo = false; $info->showstudentdata = $info->scheduler->uses_studentdata(); $info->showresult = false; $info->onstudentside = false; diff --git a/renderer.php b/renderer.php index e5e53f3e..58fffead 100644 --- a/renderer.php +++ b/renderer.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\scheduler; -use \mod_scheduler\permission\scheduler_permissions; +use mod_scheduler\model\scheduler; +use mod_scheduler\permission\scheduler_permissions; require_once($CFG->dirroot . '/mod/assign/locallib.php'); @@ -107,7 +107,7 @@ public static function slotdatetime($slotdate, $duration) { /** * @var array a cached version of scale levels */ - protected $scalecache = array(); + protected $scalecache = []; /** * Get a list of levels in a grading scale. @@ -119,8 +119,8 @@ public function get_scale_levels($scaleid) { global $DB; if (!array_key_exists($scaleid, $this->scalecache)) { - $this->scalecache[$scaleid] = array(); - if ($scale = $DB->get_record('scale', array('id' => $scaleid))) { + $this->scalecache[$scaleid] = []; + if ($scale = $DB->get_record('scale', ['id' => $scaleid])) { $levels = explode(',', $scale->scale); foreach ($levels as $levelid => $value) { $this->scalecache[$scaleid][$levelid + 1] = $value; @@ -189,7 +189,7 @@ public function format_grade($subject, $grade, $short = false, $decimals = 0) { */ public function grading_choices($scheduler) { if ($scheduler->scale > 0) { - $scalegrades = array(); + $scalegrades = []; for ($i = 0; $i <= $scheduler->scale; $i++) { $scalegrades[$i] = $i; } @@ -197,7 +197,7 @@ public function grading_choices($scheduler) { $scaleid = - ($scheduler->scale); $scalegrades = $this->get_scale_levels($scaleid); } - $scalegrades = array(-1 => get_string('nograde')) + $scalegrades; + $scalegrades = [-1 => get_string('nograde')] + $scalegrades; return $scalegrades; } @@ -262,7 +262,7 @@ public function format_appointment_notes(scheduler $scheduler, $data, $idfield = * @return string HTML code of the link */ public function user_profile_link(scheduler $scheduler, stdClass $user) { - $profileurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $scheduler->course)); + $profileurl = new moodle_url('/user/view.php', ['id' => $user->id, 'course' => $scheduler->course]); return html_writer::link($profileurl, fullname($user)); } @@ -276,11 +276,11 @@ public function user_profile_link(scheduler $scheduler, stdClass $user) { * @return string HTML code of the link */ public function appointment_link($scheduler, $user, $appointmentid) { - $paras = array( + $paras = [ 'what' => 'viewstudent', 'id' => $scheduler->cmid, - 'appointmentid' => $appointmentid - ); + 'appointmentid' => $appointmentid, + ]; $url = new moodle_url('/mod/scheduler/view.php', $paras); return html_writer::link($url, fullname($user)); } @@ -302,13 +302,13 @@ public function render_attachments($contextid, $filearea, $itemid) { // at the sametime (e.g. in the case of drag/drop upload) we revert to using the filename. $files = $fs->get_area_files($contextid, 'mod_scheduler', $filearea, $itemid, "filename", false); if ($files) { - $o .= html_writer::start_tag('ul', array('class' => 'scheduler_filelist')); + $o .= html_writer::start_tag('ul', ['class' => 'scheduler_filelist']); foreach ($files as $file) { $filename = $file->get_filename(); $pathname = $file->get_filepath(); $mimetype = $file->get_mimetype(); $iconimage = $this->pix_icon(file_file_icon($file), get_mimetype_description($file), - 'moodle', array('class' => 'icon')); + 'moodle', ['class' => 'icon']); $path = moodle_url::make_pluginfile_url($contextid, 'mod_scheduler', $filearea, $itemid, $pathname, $filename); $ulitem = html_writer::link($path, $iconimage) . html_writer::link($path, s($filename)); @@ -332,7 +332,7 @@ public function render_attachments($contextid, $filearea, $itemid) { * @return tabobject */ private function teacherview_tab(moodle_url $baseurl, $namekey, $what, $subpage = '', $nameargs = null) { - $taburl = new moodle_url($baseurl, array('what' => $what, 'subpage' => $subpage)); + $taburl = new moodle_url($baseurl, ['what' => $what, 'subpage' => $subpage]); $tabname = get_string($namekey, 'scheduler', $nameargs); $id = ($subpage != '') ? $subpage : $what; $tab = new tabobject($id, $taburl, $tabname); @@ -353,16 +353,16 @@ public function teacherview_tabs(scheduler $scheduler, scheduler_permissions $pe moodle_url $baseurl, $selected, $inactive = null) { $statstab = $this->teacherview_tab($baseurl, 'statistics', 'viewstatistics', 'overall'); - $statstab->subtree = array( + $statstab->subtree = [ $this->teacherview_tab($baseurl, 'overall', 'viewstatistics', 'overall'), $this->teacherview_tab($baseurl, 'studentbreakdown', 'viewstatistics', 'studentbreakdown'), $this->teacherview_tab($baseurl, 'staffbreakdown', 'viewstatistics', 'staffbreakdown', $scheduler->get_teacher_name()), $this->teacherview_tab($baseurl, 'lengthbreakdown', 'viewstatistics', 'lengthbreakdown'), - $this->teacherview_tab($baseurl, 'groupbreakdown', 'viewstatistics', 'groupbreakdown') - ); + $this->teacherview_tab($baseurl, 'groupbreakdown', 'viewstatistics', 'groupbreakdown'), + ]; - $level1 = array(); + $level1 = []; $level1[] = $this->teacherview_tab($baseurl, 'myappointments', 'view', 'myappointments'); if ($permissions->can_see_all_slots()) { $level1[] = $this->teacherview_tab($baseurl, 'allappointments', 'view', 'allappointments'); @@ -384,8 +384,8 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { $table = new html_table(); if ($slottable->showslot) { - $table->head = array(get_string('date', 'scheduler')); - $table->align = array('left'); + $table->head = [get_string('date', 'scheduler')]; + $table->align = ['left']; } if ($slottable->showstudent) { $table->head[] = get_string('name'); @@ -419,12 +419,12 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { $table->align[] = 'right'; } - $table->data = array(); + $table->data = []; foreach ($slottable->slots as $slot) { - $rowdata = array(); + $rowdata = []; - $studenturl = new moodle_url($slottable->actionurl, array('appointmentid' => $slot->appointmentid)); + $studenturl = new moodle_url($slottable->actionurl, ['appointmentid' => $slot->appointmentid]); $timedata = $this->userdate($slot->starttime); if ($slottable->showeditlink) { @@ -484,19 +484,19 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { $actions = ''; if ($slot->canedit) { $buttonurl = new moodle_url($slottable->actionurl, - array('what' => 'editbooking', 'appointmentid' => $slot->appointmentid)); + ['what' => 'editbooking', 'appointmentid' => $slot->appointmentid]); $button = new single_button($buttonurl, get_string('editbooking', 'scheduler')); $actions .= $this->render($button); } if ($slot->canview) { $buttonurl = new moodle_url($slottable->actionurl, - array('what' => 'viewbooking', 'appointmentid' => $slot->appointmentid)); + ['what' => 'viewbooking', 'appointmentid' => $slot->appointmentid]); $button = new single_button($buttonurl, get_string('viewbooking', 'scheduler')); $actions .= $this->render($button); } if ($slot->cancancel) { $buttonurl = new moodle_url($slottable->actionurl, - array('what' => 'cancelbooking', 'slotid' => $slot->slotid)); + ['what' => 'cancelbooking', 'slotid' => $slot->slotid]); $button = new single_button($buttonurl, get_string('cancelbooking', 'scheduler')); $actions .= $this->render($button); } @@ -525,16 +525,16 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis $imgclass = 'studentlist-togglebutton'; $alttext = get_string('showparticipants', 'scheduler'); $o .= $this->output->pix_icon('t/switch', $alttext, 'moodle', - array('id' => $toggleid, 'class' => $imgclass)); + ['id' => $toggleid, 'class' => $imgclass]); } - $divprops = array('id' => 'list'.$toggleid); + $divprops = ['id' => 'list'.$toggleid]; $o .= html_writer::start_div('studentlist', $divprops); if (count($studentlist->students) > 0) { $editable = $studentlist->actionurl && $studentlist->editable; if ($editable) { - $o .= html_writer::start_tag('form', array('action' => $studentlist->actionurl, - 'method' => 'post', 'class' => 'studentselectform')); + $o .= html_writer::start_tag('form', ['action' => $studentlist->actionurl, + 'method' => 'post', 'class' => 'studentselectform', ]); } foreach ($studentlist->students as $student) { @@ -543,10 +543,10 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis if ($studentlist->checkboxname) { if ($student->editattended) { $checkbox = html_writer::checkbox($studentlist->checkboxname, $student->entryid, $student->checked, '', - array('class' => 'studentselect')); + ['class' => 'studentselect']); } else { $img = $student->checked ? 'ticked' : 'unticked'; - $checkbox = $this->render(new pix_icon($img, '', 'scheduler', array('class' => 'statictickbox'))); + $checkbox = $this->render(new pix_icon($img, '', 'scheduler', ['class' => 'statictickbox'])); } } if ($studentlist->linkappointment) { @@ -555,7 +555,7 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis $name = fullname($student->user); } $studicons = ''; - $studprovided = array(); + $studprovided = []; if ($student->notesprovided) { $studprovided[] = get_string('message', 'scheduler'); } @@ -565,14 +565,14 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis if ($studprovided) { $providedstr = implode(', ', $studprovided); $alttext = get_string('studentprovided', 'scheduler', $providedstr); - $attachicon = new pix_icon('attachment', $alttext, 'scheduler', array('class' => 'studdataicon')); + $attachicon = new pix_icon('attachment', $alttext, 'scheduler', ['class' => 'studdataicon']); $studicons .= $this->render($attachicon); } if ($student->highlight) { $class .= ' highlight'; } - $picture = $this->user_picture($student->user, array('courseid' => $studentlist->scheduler->courseid)); + $picture = $this->user_picture($student->user, ['courseid' => $studentlist->scheduler->courseid]); $grade = ''; if ($studentlist->showgrades && $student->grade) { $grade = $this->format_grade($studentlist->scheduler, $student->grade, true); @@ -581,11 +581,11 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis } if ($editable) { - $o .= html_writer::empty_tag('input', array( + $o .= html_writer::empty_tag('input', [ 'type' => 'submit', 'class' => 'studentselectsubmit', - 'value' => $studentlist->buttontext - )); + 'value' => $studentlist->buttontext, + ]); $o .= html_writer::end_tag('form'); } } @@ -603,13 +603,13 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis public function render_scheduler_slot_booker(scheduler_slot_booker $booker) { $table = new html_table(); - $table->head = array( get_string('date', 'scheduler'), get_string('start', 'scheduler'), + $table->head = [ get_string('date', 'scheduler'), get_string('start', 'scheduler'), get_string('end', 'scheduler'), get_string('location', 'scheduler'), get_string('comments', 'scheduler'), s($booker->scheduler->get_teacher_name()), - get_string('groupsession', 'scheduler'), ''); - $table->align = array ('left', 'left', 'left', 'left', 'left', 'left', 'left', 'left'); + get_string('groupsession', 'scheduler'), '', ]; + $table->align = ['left', 'left', 'left', 'left', 'left', 'left', 'left', 'left']; $table->id = 'slotbookertable'; - $table->data = array(); + $table->data = []; $previousdate = ''; $previoustime = ''; @@ -618,7 +618,7 @@ public function render_scheduler_slot_booker(scheduler_slot_booker $booker) { foreach ($booker->slots as $slot) { - $rowdata = array(); + $rowdata = []; $startdate = $this->userdate($slot->starttime); $starttime = $this->usertime($slot->starttime); @@ -661,7 +661,7 @@ public function render_scheduler_slot_booker(scheduler_slot_booker $booker) { if ($slot->canbook) { $bookaction = $booker->scheduler->uses_bookingform() ? 'bookingform' : 'bookslot'; - $bookurl = new moodle_url($booker->actionurl, array('what' => $bookaction, 'slotid' => $slot->slotid)); + $bookurl = new moodle_url($booker->actionurl, ['what' => $bookaction, 'slotid' => $slot->slotid]); $button = new single_button($bookurl, get_string('bookslot', 'scheduler')); $rowdata[] = $this->render($button); } else { @@ -736,9 +736,9 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { $o = ''; $table = new html_table(); - $table->head = array('', get_string('date', 'scheduler'), get_string('start', 'scheduler'), - get_string('end', 'scheduler'), get_string('location', 'scheduler'), get_string('students', 'scheduler') ); - $table->align = array ('center', 'left', 'left', 'left', 'left', 'left'); + $table->head = ['', get_string('date', 'scheduler'), get_string('start', 'scheduler'), + get_string('end', 'scheduler'), get_string('location', 'scheduler'), get_string('students', 'scheduler'), ]; + $table->align = ['center', 'left', 'left', 'left', 'left', 'left']; if ($slotman->showteacher) { $table->head[] = s($slotman->scheduler->get_teacher_name()); $table->align[] = 'left'; @@ -747,7 +747,7 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { $table->align[] = 'center'; $table->id = 'slotmanager'; - $table->data = array(); + $table->data = []; $previousdate = ''; $previoustime = ''; @@ -755,9 +755,9 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { foreach ($slotman->slots as $slot) { - $rowdata = array(); + $rowdata = []; - $selectbox = html_writer::checkbox('selectedslot[]', $slot->slotid, false, '', array('class' => 'slotselect')); + $selectbox = html_writer::checkbox('selectedslot[]', $slot->slotid, false, '', ['class' => 'slotselect']); $rowdata[] = $slot->editable ? $selectbox : ''; $startdate = $this->userdate($slot->starttime); @@ -795,11 +795,11 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { $actions = ''; if ($slot->editable) { - $url = new moodle_url($slotman->actionurl, array('what' => 'deleteslot', 'slotid' => $slot->slotid)); + $url = new moodle_url($slotman->actionurl, ['what' => 'deleteslot', 'slotid' => $slot->slotid]); $confirmdelete = new confirm_action(get_string('confirmdelete-one', 'scheduler')); $actions .= $this->action_icon($url, new pix_icon('t/delete', get_string('delete')), $confirmdelete); - $url = new moodle_url($slotman->actionurl, array('what' => 'updateslot', 'slotid' => $slot->slotid)); + $url = new moodle_url($slotman->actionurl, ['what' => 'updateslot', 'slotid' => $slot->slotid]); $actions .= $this->action_icon($url, new pix_icon('t/edit', get_string('edit'))); } @@ -817,10 +817,10 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { $groupalt = 'isnonexclusive'; } else if ($slot->editable) { if ($slot->exclusivity == 1) { - $groupact = array('what' => 'allowgroup', 'slotid' => $slot->slotid); + $groupact = ['what' => 'allowgroup', 'slotid' => $slot->slotid]; $groupalt = 'allowgroup'; } else { - $groupact = array('what' => 'forbidgroup', 'slotid' => $slot->slotid); + $groupact = ['what' => 'forbidgroup', 'slotid' => $slot->slotid]; $groupalt = 'forbidgroup'; } } else { @@ -838,7 +838,7 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { } if ($slot->editable && $slot->isappointed) { - $url = new moodle_url($slotman->actionurl, array('what' => 'revokeall', 'slotid' => $slot->slotid)); + $url = new moodle_url($slotman->actionurl, ['what' => 'revokeall', 'slotid' => $slot->slotid]); $confirmrevoke = new confirm_action(get_string('confirmrevoke', 'scheduler')); $actions .= $this->action_icon($url, new pix_icon('s/no', get_string('revoke', 'scheduler')), $confirmrevoke); } @@ -870,8 +870,8 @@ public function render_scheduler_scheduling_list(scheduler_scheduling_list $list $mtable = new html_table(); $mtable->id = $list->id; - $mtable->head = array ('', get_string('name')); - $mtable->align = array ('center', 'left'); + $mtable->head = ['', get_string('name')]; + $mtable->align = ['center', 'left']; foreach ($list->extraheaders as $field) { $mtable->head[] = $field; $mtable->align[] = 'left'; @@ -879,9 +879,9 @@ public function render_scheduler_scheduling_list(scheduler_scheduling_list $list $mtable->head[] = get_string('action', 'scheduler'); $mtable->align[] = 'center'; - $mtable->data = array(); + $mtable->data = []; foreach ($list->lines as $line) { - $data = array($line->pix, $line->name); + $data = [$line->pix, $line->name]; foreach ($line->extrafields as $field) { $data[] = $field; } @@ -904,16 +904,16 @@ public function render_scheduler_scheduling_list(scheduler_scheduling_list $list * @return string */ public function render_scheduler_totalgrade_info(scheduler_totalgrade_info $gradeinfo) { - $items = array(); + $items = []; if ($gradeinfo->showtotalgrade) { - $items[] = array('gradingstrategy', $this->format_grading_strategy($gradeinfo->scheduler->gradingstrategy)); - $items[] = array('totalgrade', $this->format_grade($gradeinfo->scheduler, $gradeinfo->totalgrade, false, 2)); + $items[] = ['gradingstrategy', $this->format_grading_strategy($gradeinfo->scheduler->gradingstrategy)]; + $items[] = ['totalgrade', $this->format_grade($gradeinfo->scheduler, $gradeinfo->totalgrade, false, 2)]; } if (!is_null($gradeinfo->gbgrade)) { $gbgradestr = $gradeinfo->gbgrade->str_grade; - $attributes = array(); + $attributes = []; if ($gradeinfo->gbgrade->hidden) { $attributes[] = get_string('hidden', 'grades'); } @@ -926,11 +926,11 @@ public function render_scheduler_totalgrade_info(scheduler_totalgrade_info $grad if (count($attributes) > 0) { $gbgradestr .= ' ('.implode(', ', $attributes) .')'; } - $items[] = array('gradeingradebook', $gbgradestr); + $items[] = ['gradeingradebook', $gbgradestr]; } $o = html_writer::start_div('totalgrade'); - $o .= html_writer::start_tag('dl', array('class' => 'totalgrade')); + $o .= html_writer::start_tag('dl', ['class' => 'totalgrade']); foreach ($items as $item) { $o .= html_writer::tag('dt', get_string($item[0], 'scheduler')); $o .= html_writer::tag('dd', $item[1]); @@ -990,20 +990,20 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $cell1 = new html_table_cell(get_string('slotdatetimelabel', 'scheduler')); $data = self::slotdatetime($ai->slot->starttime, $ai->slot->duration); $cell2 = new html_table_cell(get_string('slotdatetimelong', 'scheduler', $data)); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; $row = new html_table_row(); $cell1 = new html_table_cell($ai->scheduler->get_teacher_name()); $cell2 = new html_table_cell(fullname($ai->slot->get_teacher())); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; if ($ai->slot->appointmentlocation) { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('location', 'scheduler')); $cell2 = new html_table_cell(format_string($ai->slot->appointmentlocation)); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } @@ -1013,7 +1013,7 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $notes = $this->format_notes($ai->slot->notes, $ai->slot->notesformat, $ai->scheduler->get_context(), 'slotnote', $ai->slot->id); $cell2 = new html_table_cell($notes); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } } @@ -1022,7 +1022,7 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $row = new html_table_row(); $cell1 = new html_table_cell(get_string('appointfor', 'scheduler')); $cell2 = new html_table_cell(format_string($ai->groupinfo)); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } @@ -1033,7 +1033,7 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $note = $this->format_notes($ai->scheduler->bookinginstructions, $ai->scheduler->bookinginstructionsformat, $ai->scheduler->get_context(), 'bookinginstructions', 0); $cell2 = new html_table_cell($note); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } } @@ -1049,7 +1049,7 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $cell1 = new html_table_cell(get_string($key, 'scheduler')); $note = format_text($ai->appointment->studentnote, $ai->appointment->studentnoteformat); $cell2 = new html_table_cell($note); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } if ($ai->scheduler->uses_studentfiles()) { @@ -1057,7 +1057,7 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $cell1 = new html_table_cell(get_string('studentfiles', 'scheduler')); $att = $this->render_attachments($ai->scheduler->context->id, 'studentfiles', $ai->appointment->id); $cell2 = new html_table_cell($att); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } } @@ -1069,7 +1069,7 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $note = $this->format_notes($ai->appointment->appointmentnote, $ai->appointment->appointmentnoteformat, $ai->scheduler->get_context(), 'appointmentnote', $ai->appointment->id); $cell2 = new html_table_cell($note); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } if ($ai->scheduler->uses_grades()) { @@ -1077,7 +1077,7 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $cell1 = new html_table_cell(get_string('grade', 'scheduler')); $gradetext = $this->format_grade($ai->scheduler, $ai->appointment->grade, false); $cell2 = new html_table_cell($gradetext); - $row->cells = array($cell1, $cell2); + $row->cells = [$cell1, $cell2]; $t->data[] = $row; } } diff --git a/slotforms.php b/slotforms.php index c03384cb..73819b94 100644 --- a/slotforms.php +++ b/slotforms.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\scheduler; -use \mod_scheduler\model\slot; +use mod_scheduler\model\scheduler; +use mod_scheduler\model\slot; require_once($CFG->libdir.'/formslib.php'); @@ -70,8 +70,8 @@ abstract class scheduler_slotform_base extends moodleform { public function __construct($action, scheduler $scheduler, $cm, $usergroups, $customdata=null) { $this->scheduler = $scheduler; $this->usergroups = $usergroups; - $this->noteoptions = array('trusttext' => true, 'maxfiles' => -1, 'maxbytes' => 0, - 'context' => $scheduler->get_context(), 'subdirs' => false); + $this->noteoptions = ['trusttext' => true, 'maxfiles' => -1, 'maxbytes' => 0, + 'context' => $scheduler->get_context(), 'subdirs' => false, ]; parent::__construct($action, $customdata); } @@ -86,9 +86,9 @@ protected function add_base_fields() { $mform = $this->_form; // Exclusivity. - $exclgroup = array(); + $exclgroup = []; - $exclgroup[] = $mform->createElement('text', 'exclusivity', '', array('size' => '10')); + $exclgroup[] = $mform->createElement('text', 'exclusivity', '', ['size' => '10']); $mform->setType('exclusivity', PARAM_INTEGER); $mform->setDefault('exclusivity', 1); @@ -100,7 +100,7 @@ protected function add_base_fields() { $mform->addHelpButton('exclusivitygroup', 'exclusivity', 'scheduler'); // Location of the appointment. - $mform->addElement('text', 'appointmentlocation', get_string('location', 'scheduler'), array('size' => '30')); + $mform->addElement('text', 'appointmentlocation', get_string('location', 'scheduler'), ['size' => '30']); $mform->setType('appointmentlocation', PARAM_TEXT); $mform->addRule('appointmentlocation', get_string('error'), 'maxlength', 255); $mform->setDefault('appointmentlocation', $this->scheduler->get_last_location($USER)); @@ -110,7 +110,7 @@ protected function add_base_fields() { if (has_capability('mod/scheduler:canscheduletootherteachers', $this->scheduler->get_context())) { $teachername = s($this->scheduler->get_teacher_name()); $teachers = $this->scheduler->get_available_teachers(); - $teachersmenu = array(); + $teachersmenu = []; if ($teachers) { foreach ($teachers as $teacher) { $teachersmenu[$teacher->id] = fullname($teacher); @@ -140,10 +140,10 @@ protected function add_base_fields() { */ protected function add_minutes_field($name, $label, $defaultval, $minuteslabel = 'minutes') { $mform = $this->_form; - $group = array(); - $group[] =& $mform->createElement('text', $name, '', array('size' => 5)); + $group = []; + $group[] =& $mform->createElement('text', $name, '', ['size' => 5]); $group[] =& $mform->createElement('static', $name.'mintext', '', get_string($minuteslabel, 'scheduler')); - $mform->addGroup($group, $name.'group', get_string($label, 'scheduler'), array(' '), false); + $mform->addGroup($group, $name.'group', get_string($label, 'scheduler'), [' '], false); $mform->setType($name, PARAM_INT); $mform->setDefault($name, $defaultval); } @@ -170,7 +170,7 @@ public function validation($data, $files) { // Check duration for valid range. if ($this->hasduration) { - $limits = array('min' => 1, 'max' => 24 * 60); + $limits = ['min' => 1, 'max' => 24 * 60]; if ($data['duration'] < $limits['min'] || $data['duration'] > $limits['max']) { $errors['durationgroup'] = get_string('durationrange', 'scheduler', $limits); } @@ -234,25 +234,25 @@ protected function definition() { // Send e-mail reminder? $mform->addElement('date_selector', 'emaildate', get_string('emailreminderondate', 'scheduler'), - array('optional' => true)); + ['optional' => true]); $mform->setDefault('remindersel', -1); // Slot comments. $mform->addElement('editor', 'notes_editor', get_string('comments', 'scheduler'), - array('rows' => 3, 'columns' => 60), $this->noteoptions); + ['rows' => 3, 'columns' => 60], $this->noteoptions); $mform->setType('notes', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. // Appointments. - $repeatarray = array(); - $grouparray = array(); + $repeatarray = []; + $grouparray = []; $repeatarray[] = $mform->createElement('header', 'appointhead', get_string('appointmentno', 'scheduler', '{no}')); // Choose student. $options = [ 'ajax' => 'mod_scheduler/studentid', 'valuehtmlcallback' => 'scheduler_student_autocomplete_callback', - 'scheduler' => $this->scheduler->id + 'scheduler' => $this->scheduler->id, ]; $grouparray[] = $mform->createElement('autocomplete', 'studentid', '', [], $options); $grouparray[] = $mform->createElement('hidden', 'appointid', 0); @@ -274,11 +274,11 @@ protected function definition() { if ($this->scheduler->uses_appointmentnotes()) { $repeatarray[] = $mform->createElement('editor', 'appointmentnote_editor', get_string('appointmentnote', 'scheduler'), - array('rows' => 3, 'columns' => 60), $this->noteoptions); + ['rows' => 3, 'columns' => 60], $this->noteoptions); } if ($this->scheduler->uses_teachernotes()) { $repeatarray[] = $mform->createElement('editor', 'teachernote_editor', get_string('teachernote', 'scheduler'), - array('rows' => 3, 'columns' => 60), $this->noteoptions); + ['rows' => 3, 'columns' => 60], $this->noteoptions); } // Tickbox to remove the student. @@ -287,16 +287,16 @@ protected function definition() { if (isset($this->_customdata['repeats'])) { $repeatno = $this->_customdata['repeats']; } else if ($this->slotid) { - $repeatno = $DB->count_records('scheduler_appointment', array('slotid' => $this->slotid)); + $repeatno = $DB->count_records('scheduler_appointment', ['slotid' => $this->slotid]); $repeatno += 1; } else { $repeatno = 1; } - $repeateloptions = array(); + $repeateloptions = []; $repeateloptions['appointid']['type'] = PARAM_INT; - $repeateloptions['studentid']['disabledif'] = array('appointid', 'neq', 0); - $nostudcheck = array('studentid', 'eq', 0); + $repeateloptions['studentid']['disabledif'] = ['appointid', 'neq', 0]; + $nostudcheck = ['studentid', 'eq', 0]; $repeateloptions['attended']['disabledif'] = $nostudcheck; $repeateloptions['appointmentnote_editor']['disabledif'] = $nostudcheck; $repeateloptions['teachernote_editor']['disabledif'] = $nostudcheck; @@ -389,7 +389,7 @@ public function prepare_formdata(slot $slot) { $data = file_prepare_standard_editor($data, "notes", $this->noteoptions, $context, 'mod_scheduler', 'slotnote', $slot->id); - $data->notes = array(); + $data->notes = []; $data->notes['text'] = $slot->notes; $data->notes['format'] = $slot->notesformat; @@ -407,17 +407,17 @@ public function prepare_formdata(slot $slot) { $currenttext = file_prepare_draft_area($draftid, $context->id, 'mod_scheduler', 'appointmentnote', $appointment->id, $this->noteoptions, $appointment->appointmentnote); - $data->appointmentnote_editor[$i] = array('text' => $currenttext, + $data->appointmentnote_editor[$i] = ['text' => $currenttext, 'format' => $appointment->appointmentnoteformat, - 'itemid' => $draftid); + 'itemid' => $draftid, ]; $draftid = file_get_submitted_draft_itemid('teachernote'); $currenttext = file_prepare_draft_area($draftid, $context->id, 'mod_scheduler', 'teachernote', $appointment->id, $this->noteoptions, $appointment->teachernote); - $data->teachernote_editor[$i] = array('text' => $currenttext, + $data->teachernote_editor[$i] = ['text' => $currenttext, 'format' => $appointment->teachernoteformat, - 'itemid' => $draftid); + 'itemid' => $draftid, ]; $data->grade[$i] = $appointment->grade; $i++; @@ -533,11 +533,11 @@ protected function definition() { $mform->setDefault('rangestart', time()); $mform->addElement('date_selector', 'rangeend', get_string('enddate', 'scheduler'), - array('optional' => true) ); + ['optional' => true] ); // Weekdays selection. - $checkboxes = array(); - $weekdays = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday'); + $checkboxes = []; + $weekdays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']; foreach ($weekdays as $day) { $checkboxes[] = $mform->createElement('advcheckbox', $day, '', get_string($day, 'scheduler')); $mform->setDefault($day, true); @@ -547,15 +547,15 @@ protected function definition() { $mform->addGroup($checkboxes, 'weekdays', get_string('addondays', 'scheduler'), null, false); // Start and end time. - $hours = array(); - $minutes = array(); + $hours = []; + $minutes = []; for ($i = 0; $i <= 23; $i++) { $hours[$i] = sprintf("%02d", $i); } for ($i = 0; $i < 60; $i += 5) { $minutes[$i] = sprintf("%02d", $i); } - $timegroup = array(); + $timegroup = []; if (right_to_left()) { $timegroup[] = $mform->createElement('static', 'timefrom', '', get_string('timefrom', 'scheduler')); $timegroup[] = $mform->createElement('select', 'startminute', get_string('minute', 'form'), $minutes); @@ -593,7 +593,7 @@ protected function definition() { $this->add_base_fields(); // Display slot from date - relative. - $hideuntilsel = array(); + $hideuntilsel = []; $hideuntilsel[0] = get_string('now', 'scheduler'); $hideuntilsel[DAYSECS] = get_string('onedaybefore', 'scheduler'); for ($i = 2; $i < 7; $i++) { @@ -607,7 +607,7 @@ protected function definition() { $mform->setDefault('hideuntilsel', 0); // E-mail reminder from. - $remindersel = array(); + $remindersel = []; $remindersel[-1] = get_string('never', 'scheduler'); $remindersel[0] = get_string('onthemorningofappointment', 'scheduler'); $remindersel[DAYSECS] = get_string('onedaybefore', 'scheduler'); diff --git a/studentview.controller.php b/studentview.controller.php index 1f0b5f06..0dac87e8 100644 --- a/studentview.controller.php +++ b/studentview.controller.php @@ -52,7 +52,7 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo } $requiredcapacity = 1; - $userstobook = array($userid); + $userstobook = [$userid]; if ($groupid > 0) { if (!$scheduler->is_group_scheduling_enabled()) { throw new moodle_exception('error'); @@ -76,7 +76,7 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo $errormessage = get_string('selectedtoomany', 'scheduler', $bookinglimit); } else { // Validate our user ids. - $existingstudents = array(); + $existingstudents = []; foreach ($slot->get_appointments() as $app) { $existingstudents[] = $app->studentid; } @@ -115,8 +115,8 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo // Notify the teacher. if ($scheduler->allownotifications) { - $student = $DB->get_record('user', array('id' => $appointment->studentid), '*', MUST_EXIST); - $teacher = $DB->get_record('user', array('id' => $slot->teacherid), '*', MUST_EXIST); + $student = $DB->get_record('user', ['id' => $appointment->studentid], '*', MUST_EXIST); + $teacher = $DB->get_record('user', ['id' => $slot->teacherid], '*', MUST_EXIST); scheduler_messenger::send_slot_notification($slot, 'bookingnotification', 'applied', $student, $teacher, $teacher, $student, $COURSE); } @@ -126,7 +126,7 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo } -$returnurlparas = array('id' => $cm->id); +$returnurlparas = ['id' => $cm->id]; if ($scheduler->is_group_scheduling_enabled()) { $returnurlparas['appointgroup'] = $appointgroup; } @@ -144,7 +144,7 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo $slotid = required_param('slotid', PARAM_INT); $slot = $scheduler->get_slot($slotid); - $actionurl = new moodle_url($returnurl, array('what' => 'bookingform', 'slotid' => $slotid)); + $actionurl = new moodle_url($returnurl, ['what' => 'bookingform', 'slotid' => $slotid]); $mform = new scheduler_booking_form($slot, $actionurl); @@ -240,7 +240,7 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo throw new moodle_exception('nopermissions'); } - $actionurl = new moodle_url($returnurl, array('what' => 'editbooking', 'appointmentid' => $appointmentid)); + $actionurl = new moodle_url($returnurl, ['what' => 'editbooking', 'appointmentid' => $appointmentid]); $mform = new scheduler_booking_form($slot, $actionurl, true); $mform->set_data($mform->prepare_booking_data($appointment)); @@ -282,7 +282,7 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo throw new moodle_exception('nopermissions'); } - $userstocancel = array($USER->id); + $userstocancel = [$USER->id]; if ($appointgroup) { $userstocancel = array_keys($scheduler->get_available_students($appointgroup)); } @@ -293,8 +293,8 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo // Notify the teacher. if ($scheduler->allownotifications) { - $student = $DB->get_record('user', array('id' => $USER->id)); - $teacher = $DB->get_record('user', array('id' => $slot->teacherid)); + $student = $DB->get_record('user', ['id' => $USER->id]); + $teacher = $DB->get_record('user', ['id' => $slot->teacherid]); scheduler_messenger::send_slot_notification($slot, 'bookingnotification', 'cancelled', $student, $teacher, $teacher, $student, $COURSE); } diff --git a/studentview.php b/studentview.php index 833748d6..0b9b28d6 100644 --- a/studentview.php +++ b/studentview.php @@ -30,10 +30,10 @@ $PAGE->set_docs_path('mod/scheduler/studentview'); -$urlparas = array( +$urlparas = [ 'id' => $scheduler->cmid, - 'sesskey' => sesskey() -); + 'sesskey' => sesskey(), +]; if ($appointgroup >= 0) { $urlparas['appointgroup'] = $appointgroup; } @@ -76,7 +76,7 @@ $grademsg = ''; if ($gradebookinfo->overridden) { $grademsg = html_writer::tag('p', - get_string('overriddennotice', 'grades'), array('class' => 'overriddennotice') + get_string('overriddennotice', 'grades'), ['class' => 'overriddennotice'] ); } $grademsg .= get_string('yourtotalgrade', 'scheduler', $gradebookinfo->str_grade); @@ -86,7 +86,7 @@ // Print group selection menu if given. if ($scheduler->is_group_scheduling_enabled()) { - $groupchoice = array(); + $groupchoice = []; if ($scheduler->is_individual_scheduling_enabled()) { $groupchoice[0] = get_string('myself', 'scheduler'); } @@ -94,7 +94,7 @@ $groupchoice[$group->id] = $group->name; } $select = $output->single_select($actionurl, 'appointgroup', $groupchoice, $appointgroup, - array(-1 => 'choosedots'), 'appointgroupform'); + [-1 => 'choosedots'], 'appointgroupform'); echo html_writer::div(get_string('appointforgroup', 'scheduler', $select), 'dropdownmenu'); } diff --git a/styles.css b/styles.css index 9dba784e..e5cfe623 100644 --- a/styles.css +++ b/styles.css @@ -112,7 +112,6 @@ body.path-mod-scheduler.jsenabled input.studentselectsubmit { } .path-mod-scheduler .maildisplay { - width: 90%; margin-left: auto; margin-right: auto; background: #eee; diff --git a/teacherview.controller.php b/teacherview.controller.php index 6cdb092e..37f02619 100644 --- a/teacherview.controller.php +++ b/teacherview.controller.php @@ -230,13 +230,13 @@ function scheduler_action_delete_slots(array $slots, $action, moodle_url $return $slotid = required_param('slotid', PARAM_INT); $slot = $scheduler->get_slot($slotid); $permissions->ensure($permissions->can_edit_slot($slot)); - scheduler_action_delete_slots(array($slot), $action, $viewurl); + scheduler_action_delete_slots([$slot], $action, $viewurl); break; /************************************ Deleting multiple slots ***********************************************/ case 'deleteslots': $slotids = required_param('items', PARAM_SEQUENCE); $slotids = explode(",", $slotids); - $slots = array(); + $slots = []; foreach ($slotids as $slotid) { if ($slotid > 0) { $slot = $scheduler->get_slot($slotid); @@ -250,7 +250,7 @@ function scheduler_action_delete_slots(array $slots, $action, moodle_url $return case 'saveseen': $slotid = required_param('slotid', PARAM_INT); $slot = $scheduler->get_slot($slotid); - $seen = optional_param_array('seen', array(), PARAM_INT); + $seen = optional_param_array('seen', [], PARAM_INT); if (is_array($seen)) { foreach ($slot->get_appointments() as $app) { @@ -268,7 +268,7 @@ function scheduler_action_delete_slots(array $slots, $action, moodle_url $return $slot = $scheduler->get_slot($slotid); $permissions->ensure($permissions->can_edit_slot($slot)); - $oldstudents = array(); + $oldstudents = []; foreach ($slot->get_appointments() as $app) { $oldstudents[] = $app->studentid; $slot->remove_appointment($app); @@ -278,8 +278,8 @@ function scheduler_action_delete_slots(array $slots, $action, moodle_url $return foreach ($oldstudents as $oldstudent) { include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php'); - $student = $DB->get_record('user', array('id' => $oldstudent)); - $teacher = $DB->get_record('user', array('id' => $slot->teacherid)); + $student = $DB->get_record('user', ['id' => $oldstudent]); + $teacher = $DB->get_record('user', ['id' => $slot->teacherid]); scheduler_messenger::send_slot_notification($slot, 'bookingnotification', 'teachercancelled', $teacher, $student, $teacher, $student, $COURSE); diff --git a/teacherview.php b/teacherview.php index a5dc7094..a820f195 100644 --- a/teacherview.php +++ b/teacherview.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -use \mod_scheduler\model\scheduler; +use mod_scheduler\model\scheduler; /** * Print a selection box of existing slots to be scheduler in @@ -40,7 +40,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $startdatemem = ''; $starttimemem = ''; - $availableslotsmenu = array(); + $availableslotsmenu = []; foreach ($availableslots as $slot) { $startdatecnv = $output->userdate($slot->starttime); $starttimecnv = $output->usertime($slot->starttime); @@ -52,7 +52,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $starttimemem = $starttimecnv; $url = new moodle_url('/mod/scheduler/view.php', - array('id' => $scheduler->cmid, 'slotid' => $slot->id, 'sesskey' => sesskey())); + ['id' => $scheduler->cmid, 'slotid' => $slot->id, 'sesskey' => sesskey()]); if ($groupid) { $url->param('what', 'schedulegroup'); $url->param('subaction', 'dochooseslot'); @@ -101,16 +101,16 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $groupsicurrentlysee = $groupsicansee; if ($currentgroup) { if ($userfilter && !groups_is_member($currentgroup, $userfilter)) { - $groupsicurrentlysee = array(); + $groupsicurrentlysee = []; } else { $cgobj = groups_get_group($currentgroup); - $groupsicurrentlysee = array($currentgroup => $cgobj); + $groupsicurrentlysee = [$currentgroup => $cgobj]; } } } // Find groups which the current teacher can schedule as a group ($groupsicanschedule). -$groupsicanschedule = array(); +$groupsicanschedule = []; if ($scheduler->is_group_scheduling_enabled()) { $groupsicanschedule = groups_get_all_groups($COURSE->id, $userfilter, $scheduler->bookingrouping); } @@ -123,16 +123,16 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid } -$taburl = new moodle_url('/mod/scheduler/view.php', array('id' => $scheduler->cmid, 'what' => 'view', 'subpage' => $subpage)); +$taburl = new moodle_url('/mod/scheduler/view.php', ['id' => $scheduler->cmid, 'what' => 'view', 'subpage' => $subpage]); -$baseurl = new moodle_url('/mod/scheduler/view.php', array( +$baseurl = new moodle_url('/mod/scheduler/view.php', [ 'id' => $scheduler->cmid, 'subpage' => $subpage, - 'offset' => $offset -)); + 'offset' => $offset, +]); // The URL that is used for jumping back to the view (e.g., after an action is performed). -$viewurl = new moodle_url($baseurl, array('what' => 'view')); +$viewurl = new moodle_url($baseurl, ['what' => 'view']); $PAGE->set_url($viewurl); @@ -145,7 +145,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid if ($action == 'addslot') { $permissions->ensure($permissions->can_edit_own_slots()); - $actionurl = new moodle_url($baseurl, array('what' => 'addslot')); + $actionurl = new moodle_url($baseurl, ['what' => 'addslot']); if (!$scheduler->has_available_teachers()) { throw new moodle_exception('needteachers', 'scheduler', $viewurl); @@ -179,16 +179,16 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid if ($slot->starttime % 300 !== 0 || $slot->duration % 5 !== 0) { - $timeoptions = array('step' => 1, 'optional' => false); + $timeoptions = ['step' => 1, 'optional' => false]; } else { - $timeoptions = array('step' => 5, 'optional' => false); + $timeoptions = ['step' => 5, 'optional' => false]; } - $actionurl = new moodle_url($baseurl, array('what' => 'updateslot', 'slotid' => $slotid)); + $actionurl = new moodle_url($baseurl, ['what' => 'updateslot', 'slotid' => $slotid]); - $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, array( + $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, [ 'slotid' => $slotid, - 'timeoptions' => $timeoptions) + 'timeoptions' => $timeoptions, ] ); $data = $mform->prepare_formdata($slot); $mform->set_data($data); @@ -215,7 +215,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $permissions->ensure($permissions->can_edit_own_slots()); - $actionurl = new moodle_url($baseurl, array('what' => 'addsession')); + $actionurl = new moodle_url($baseurl, ['what' => 'addsession']); if (!$scheduler->has_available_teachers()) { throw new moodle_exception('needteachers', 'scheduler', $viewurl); @@ -247,11 +247,11 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $slot = $scheduler->get_slot($slotid); $studentid = required_param('studentid', PARAM_INT); - $actionurl = new moodle_url($baseurl, array('what' => 'updateslot', 'slotid' => $slotid)); + $actionurl = new moodle_url($baseurl, ['what' => 'updateslot', 'slotid' => $slotid]); $repeats = $slot->get_appointment_count() + 1; $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, - array('slotid' => $slotid, 'repeats' => $repeats)); + ['slotid' => $slotid, 'repeats' => $repeats]); $data = $mform->prepare_formdata($slot); $data->studentid[] = $studentid; $mform->set_data($data); @@ -261,13 +261,13 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid } else if (empty($subaction)) { $studentid = required_param('studentid', PARAM_INT); - $student = $DB->get_record('user', array('id' => $studentid), '*', MUST_EXIST); + $student = $DB->get_record('user', ['id' => $studentid], '*', MUST_EXIST); - $actionurl = new moodle_url($baseurl, array('what' => 'addslot')); + $actionurl = new moodle_url($baseurl, ['what' => 'addslot']); $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee); - $data = array(); + $data = []; $data['studentid'][0] = $studentid; $mform->set_data($data); @@ -290,7 +290,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $permissions->ensure($permissions->can_edit_own_slots()); $groupid = required_param('groupid', PARAM_INT); - $group = $DB->get_record('groups', array('id' => $groupid), '*', MUST_EXIST); + $group = $DB->get_record('groups', ['id' => $groupid], '*', MUST_EXIST); $members = groups_get_members($groupid); echo $output->header(); @@ -301,11 +301,11 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $groupid = required_param('groupid', PARAM_INT); $slot = $scheduler->get_slot($slotid); - $actionurl = new moodle_url($baseurl, array('what' => 'updateslot', 'slotid' => $slotid)); + $actionurl = new moodle_url($baseurl, ['what' => 'updateslot', 'slotid' => $slotid]); $repeats = $slot->get_appointment_count() + count($members); $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, - array('slotid' => $slotid, 'repeats' => $repeats)); + ['slotid' => $slotid, 'repeats' => $repeats]); $data = $mform->prepare_formdata($slot); foreach ($members as $member) { $data->studentid[] = $member->id; @@ -317,9 +317,9 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid } else if (empty($subaction)) { - $actionurl = new moodle_url($baseurl, array('what' => 'addslot')); + $actionurl = new moodle_url($baseurl, ['what' => 'addslot']); - $data = array(); + $data = []; $i = 0; foreach ($members as $member) { $data['studentid'][$i] = $member->id; @@ -327,7 +327,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid } $data['exclusivity'] = $i; - $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, array('repeats' => $i)); + $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, ['repeats' => $i]); $mform->set_data($data); echo $output->heading(get_string('scheduleappointment', 'scheduler', $group->name)); @@ -354,10 +354,10 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $recipientids = required_param('recipients', PARAM_SEQUENCE); $actionurl = new moodle_url('/mod/scheduler/view.php', - array('what' => 'sendmessage', 'id' => $cm->id, 'subpage' => $subpage, - 'template' => $template, 'recipients' => $recipientids)); + ['what' => 'sendmessage', 'id' => $cm->id, 'subpage' => $subpage, + 'template' => $template, 'recipients' => $recipientids, ]); - $templatedata = array(); + $templatedata = []; if ($template != 'none') { $vars = scheduler_messenger::get_scheduler_variables($scheduler, null, $USER, null, $COURSE, null); $templatedata['subject'] = scheduler_messenger::compile_mail_template($template, 'subject', $vars); @@ -390,11 +390,11 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid // Print top tabs. -$actionurl = new moodle_url($viewurl, array('sesskey' => sesskey())); +$actionurl = new moodle_url($viewurl, ['sesskey' => sesskey()]); -$inactive = array(); -if ($DB->count_records('scheduler_slots', array('schedulerid' => $scheduler->id)) <= - $DB->count_records('scheduler_slots', array('schedulerid' => $scheduler->id, 'teacherid' => $USER->id)) ) { +$inactive = []; +if ($DB->count_records('scheduler_slots', ['schedulerid' => $scheduler->id]) <= + $DB->count_records('scheduler_slots', ['schedulerid' => $scheduler->id, 'teacherid' => $USER->id]) ) { // We are alone in this scheduler. $inactive[] = 'allappointments'; if ($subpage = 'allappointments') { @@ -411,7 +411,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid } else { $a = new stdClass(); $a->groupmode = get_string($groupmode == VISIBLEGROUPS ? 'groupsvisible' : 'groupsseparate'); - $groupnames = array(); + $groupnames = []; foreach ($groupsthatcanseeme as $id => $group) { $groupnames[] = $group->name; } @@ -458,35 +458,34 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $commandbar = new scheduler_command_bar(); $commandbar->title = get_string('actions', 'scheduler'); -$addbuttons = array(); -$addbuttons[] = $commandbar->action_menu_link(new moodle_url($actionurl, array('what' => 'addsession')), 'addsession', 't/add'); -$addbuttons[] = $commandbar->action_menu_link(new moodle_url($actionurl, array('what' => 'addslot')), 'addsingleslot', 't/add'); +$addbuttons = []; +$addbuttons[] = $commandbar->action_menu_link(new moodle_url($actionurl, ['what' => 'addsession']), 'addsession', 't/add'); +$addbuttons[] = $commandbar->action_menu_link(new moodle_url($actionurl, ['what' => 'addslot']), 'addsingleslot', 't/add'); $commandbar->add_group(get_string('addcommands', 'scheduler'), $addbuttons); // If slots already exist, also show delete buttons. if ($slots) { - $delbuttons = array(); + $delbuttons = []; - $delselectedurl = new moodle_url($actionurl, array('what' => 'deleteslots')); + $delselectedurl = new moodle_url($actionurl, ['what' => 'deleteslots']); $PAGE->requires->js_call_amd('mod_scheduler/delselected', 'init', [$delselectedurl->out(false)]); $delselected = $commandbar->action_menu_link($delselectedurl, 'deleteselection', 't/delete', 'confirmdelete-selected', 'delselected'); - $delselected->formid = 'delselected'; $delbuttons[] = $delselected; if ($permissions->can_edit_all_slots() && $subpage == 'allappointments') { $delbuttons[] = $commandbar->action_menu_link( - new moodle_url($actionurl, array('what' => 'deleteall')), + new moodle_url($actionurl, ['what' => 'deleteall']), 'deleteallslots', 't/delete', 'confirmdelete-all'); $delbuttons[] = $commandbar->action_menu_link( - new moodle_url($actionurl, array('what' => 'deleteallunused')), + new moodle_url($actionurl, ['what' => 'deleteallunused']), 'deleteallunusedslots', 't/delete', 'confirmdelete-unused'); } $delbuttons[] = $commandbar->action_menu_link( - new moodle_url($actionurl, array('what' => 'deleteunused')), + new moodle_url($actionurl, ['what' => 'deleteunused']), 'deleteunusedslots', 't/delete', 'confirmdelete-myunused'); $delbuttons[] = $commandbar->action_menu_link( - new moodle_url($actionurl, array('what' => 'deleteonlymine')), + new moodle_url($actionurl, ['what' => 'deleteonlymine']), 'deletemyslots', 't/delete', 'confirmdelete-mine'); $commandbar->add_group(get_string('deletecommands', 'scheduler'), $delbuttons); @@ -512,7 +511,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $studlist->linkappointment = true; $studlist->checkboxname = 'seen[]'; $studlist->buttontext = get_string('saveseen', 'scheduler'); - $studlist->actionurl = new moodle_url($actionurl, array('what' => 'saveseen', 'slotid' => $slot->id)); + $studlist->actionurl = new moodle_url($actionurl, ['what' => 'saveseen', 'slotid' => $slot->id]); foreach ($slot->get_appointments() as $app) { $studlist->add_student($app, false, $app->is_attended(), true, $scheduler->uses_studentdata(), $permissions->can_edit_attended($app)); @@ -534,8 +533,8 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $groupfilter = ($subpage == 'myappointments') ? $groupsthatcanseeme : $groupsicurrentlysee; $maxlistsize = get_config('mod_scheduler', 'maxstudentlistsize'); -$students = array(); -$reminderstudents = array(); +$students = []; +$reminderstudents = []; if ($groupfilter === '') { $students = $scheduler->get_students_for_scheduling('', $maxlistsize); if ($scheduler->allows_unlimited_bookings()) { @@ -568,9 +567,9 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid if (count($reminderstudents) > 0) { $studids = implode(',', array_keys($reminderstudents)); - $messageurl = new moodle_url($actionurl, array('what' => 'sendmessage', 'recipients' => $studids)); - $invitationurl = new moodle_url($messageurl, array('template' => 'invite')); - $reminderurl = new moodle_url($messageurl, array('template' => 'invitereminder')); + $messageurl = new moodle_url($actionurl, ['what' => 'sendmessage', 'recipients' => $studids]); + $invitationurl = new moodle_url($messageurl, ['template' => 'invite']); + $reminderurl = new moodle_url($messageurl, ['template' => 'invitereminder']); $maildisplay = ''; $maildisplay .= html_writer::link($invitationurl, get_string('sendinvitation', 'scheduler')); @@ -586,7 +585,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid } $userfields = scheduler_get_user_fields(null, $context); - $fieldtitles = array(); + $fieldtitles = []; foreach ($userfields as $f) { $fieldtitles[] = $f->title; } @@ -596,18 +595,18 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid foreach ($students as $student) { $picture = $output->user_picture($student); $name = $output->user_profile_link($scheduler, $student); - $actions = array(); + $actions = []; $actions[] = new action_menu_link_secondary( - new moodle_url($actionurl, array('what' => 'schedule', 'studentid' => $student->id)), + new moodle_url($actionurl, ['what' => 'schedule', 'studentid' => $student->id]), new pix_icon('e/insert_date', '', 'moodle'), get_string('scheduleinslot', 'scheduler') ); $actions[] = new action_menu_link_secondary( - new moodle_url($actionurl, array('what' => 'markasseennow', 'studentid' => $student->id)), + new moodle_url($actionurl, ['what' => 'markasseennow', 'studentid' => $student->id]), new pix_icon('t/approve', '', 'moodle'), get_string('markasseennow', 'scheduler') ); $userfields = scheduler_get_user_fields($student, $context); - $fieldvals = array(); + $fieldvals = []; foreach ($userfields as $f) { $fieldvals[] = $f->value; } @@ -632,7 +631,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid if (empty($groupsicanschedule)) { echo $output->notification(get_string('nogroups', 'scheduler')); } else { - $grouptable = new scheduler_scheduling_list($scheduler, array()); + $grouptable = new scheduler_scheduling_list($scheduler, []); $grouptable->id = 'groupstoschedule'; $groupcnt = 0; @@ -645,18 +644,18 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $picture = print_group_picture($group, $course->id, false, true, true); $name = $group->name; - $groupmembers = array(); + $groupmembers = []; foreach ($members as $member) { $groupmembers[] = fullname($member); } $name .= ' ['. implode(', ', $groupmembers) . ']'; - $actions = array(); + $actions = []; $actions[] = new action_menu_link_secondary( - new moodle_url($actionurl, array('what' => 'schedulegroup', 'groupid' => $group->id)), + new moodle_url($actionurl, ['what' => 'schedulegroup', 'groupid' => $group->id]), new pix_icon('e/insert_date', '', 'moodle'), get_string('scheduleinslot', 'scheduler') ); - $grouptable->add_line($picture, $name, array(), $actions); + $grouptable->add_line($picture, $name, [], $actions); $groupcnt++; } } diff --git a/templates/action_menu_trigger.mustache b/templates/action_menu_trigger.mustache index 5d467d8f..e7773383 100644 --- a/templates/action_menu_trigger.mustache +++ b/templates/action_menu_trigger.mustache @@ -86,10 +86,10 @@
'; - $output .= '
'.fullname($user, has_capability('moodle/site:viewfullnames', $context)).'
'; + $output .= '
' . fullname($user, has_capability('moodle/site:viewfullnames', $context)) . '
'; $output .= '
'; if (!empty($user->role) && ($user->role <> $course->teacher)) { - $output .= $string->role .': '. $user->role .'
'; + $output .= $string->role . ': ' . $user->role . '
'; } $extrafields = scheduler_get_user_fields($user, $context); @@ -133,33 +131,41 @@ function scheduler_print_user($user, $course, $messageselect=false, $return=fals if (!isset($hiddenfields['lastaccess'])) { if ($user->lastaccess) { - $output .= $string->lastaccess .': '. userdate($user->lastaccess); - $output .= '  ('. format_time(time() - $user->lastaccess, $datestring) .')'; + $output .= $string->lastaccess . ': ' . userdate($user->lastaccess); + $output .= '  (' . format_time(time() - $user->lastaccess, $datestring) . ')'; } else { - $output .= $string->lastaccess .': '. $string->never; + $output .= $string->lastaccess . ': ' . $string->never; } } + $output .= '
'; @@ -178,7 +184,8 @@ function scheduler_print_user($user, $course, $messageselect=false, $return=fals * @copyright 2011 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_file_info extends file_info { +class scheduler_file_info extends file_info +{ /** @var stdClass Course object */ protected $course; /** @var stdClass Course module object */ @@ -281,8 +288,9 @@ private function get_filtered_children($extensions = '*', $countonly = false, $r $sql .= ' AND filename <> :emptyfilename'; $params['emptyfilename'] = '.'; } - list($sql2, $params2) = $this->build_search_files_sql($extensions, 'f'); - $sql .= ' '.$sql2; + + [$sql2, $params2] = $this->build_search_files_sql($extensions, 'f'); + $sql .= ' ' . $sql2; $params = array_merge($params, $params2); $rs = $DB->get_recordset_sql($sql, $params); @@ -293,14 +301,17 @@ private function get_filtered_children($extensions = '*', $countonly = false, $r $children[] = $child; } } + if ($countonly !== false && count($children) >= $countonly) { break; } } + $rs->close(); if ($countonly !== false) { return count($children); } + return $children; } diff --git a/mailtemplatelib.php b/mailtemplatelib.php index ee7ec034..3a0353c8 100644 --- a/mailtemplatelib.php +++ b/mailtemplatelib.php @@ -32,7 +32,8 @@ * @copyright 2016 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_messenger { +class scheduler_messenger +{ /** * Returns the language to be used in a message to a user * @@ -43,12 +44,12 @@ class scheduler_messenger { * @return string */ protected static function get_message_language($user, $course) { - if ($course && ! empty ($course->id) && $course->id != SITEID && !empty($course->lang)) { + if ($course && ! empty($course->id) && $course->id != SITEID && !empty($course->lang)) { // Course language overrides user language. $return = $course->lang; } else if (!empty($user->lang)) { $return = $user->lang; - } else if (isset ($CFG->lang)) { + } else if (isset($CFG->lang)) { $return = $CFG->lang; } else { $return = 'en'; @@ -75,6 +76,7 @@ public static function compile_mail_template($template, $format, $parameters, $m foreach ($parameters as $key => $value) { $params[strtolower($key)] = $value; } + $mailstr = get_string_manager()->get_string("email_{$template}_{$format}", $module, $params, $lang); return $mailstr; } @@ -101,9 +103,16 @@ public static function compile_mail_template($template, $format, $parameters, $m * a hash containing pairs of parm => data to replace in template * @return bool|int Returns message id if message was sent OK, "false" if there was another sort of error. */ - public static function send_message_from_template($modulename, $messagename, $isnotification, - stdClass $sender, stdClass $recipient, $course, - $template, array $parameters) { + public static function send_message_from_template( + $modulename, + $messagename, + $isnotification, + stdClass $sender, + stdClass $recipient, + $course, + $template, + array $parameters + ) { global $CFG; global $SITE; @@ -113,8 +122,8 @@ public static function send_message_from_template($modulename, $messagename, $is 'SITE' => $SITE->fullname, 'SITE_SHORT' => $SITE->shortname, 'SITE_URL' => $CFG->wwwroot, - 'SENDER' => fullname ( $sender ), - 'RECIPIENT' => fullname ( $recipient ), + 'SENDER' => fullname($sender), + 'RECIPIENT' => fullname($recipient), ]; if ($course) { @@ -133,7 +142,7 @@ public static function send_message_from_template($modulename, $messagename, $is $message->subject = self::compile_mail_template($template, 'subject', $vars, $modulename, $lang); $message->fullmessage = self::compile_mail_template($template, 'plain', $vars, $modulename, $lang); $message->fullmessageformat = FORMAT_PLAIN; - $message->fullmessagehtml = self::compile_mail_template ( $template, 'html', $vars, $modulename, $lang ); + $message->fullmessagehtml = self::compile_mail_template($template, 'html', $vars, $modulename, $lang); $message->notification = '1'; $message->courseid = $course->id; $message->contexturl = $defaultvars['COURSE_URL']; @@ -156,9 +165,14 @@ public static function send_message_from_template($modulename, $messagename, $is * (used for determining the message language) * @return array A hash with mail template substitutions */ - public static function get_scheduler_variables(scheduler $scheduler, $slot, - $teacher, $student, $course, $recipient) { - + public static function get_scheduler_variables( + scheduler $scheduler, + $slot, + $teacher, + $student, + $course, + $recipient + ) { global $CFG; $lang = self::get_message_language($recipient, $course); @@ -172,28 +186,30 @@ public static function get_scheduler_variables(scheduler $scheduler, $slot, if ($scheduler) { $vars['MODULE'] = format_string($scheduler->name); $vars['STAFFROLE'] = $scheduler->get_teacher_name(); - $vars['SCHEDULER_URL'] = $CFG->wwwroot.'/mod/scheduler/view.php?id='.$scheduler->cmid; + $vars['SCHEDULER_URL'] = $CFG->wwwroot . '/mod/scheduler/view.php?id=' . $scheduler->cmid; } + if ($slot) { $vars['DATE'] = userdate($slot->starttime, get_string('strftimedate'), $tz); $vars['TIME'] = userdate($slot->starttime, get_string('strftimetime'), $tz); $vars['ENDTIME'] = userdate($slot->endtime, get_string('strftimetime'), $tz); $vars['LOCATION'] = format_string($slot->appointmentlocation); } + if ($teacher) { $vars['ATTENDANT'] = fullname($teacher); - $vars['ATTENDANT_URL'] = $CFG->wwwroot.'/user/view.php?id='.$teacher->id.'&course='.$scheduler->course; + $vars['ATTENDANT_URL'] = $CFG->wwwroot . '/user/view.php?id=' . $teacher->id . '&course=' . $scheduler->course; } + if ($student) { $vars['ATTENDEE'] = fullname($student); - $vars['ATTENDEE_URL'] = $CFG->wwwroot.'/user/view.php?id='.$student->id.'&course='.$scheduler->course; + $vars['ATTENDEE_URL'] = $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&course=' . $scheduler->course; } // Reset language settings. force_current_language($oldlang); return $vars; - } @@ -209,11 +225,17 @@ public static function get_scheduler_variables(scheduler $scheduler, $slot, * @param stdClass $student user record for student * @param stdClass $course course record */ - public static function send_slot_notification(slot $slot, $messagename, $template, - stdClass $sender, stdClass $recipient, - stdClass $teacher, stdClass $student, stdClass $course) { + public static function send_slot_notification( + slot $slot, + $messagename, + $template, + stdClass $sender, + stdClass $recipient, + stdClass $teacher, + stdClass $student, + stdClass $course + ) { $vars = self::get_scheduler_variables($slot->get_scheduler(), $slot, $teacher, $student, $course, $recipient); self::send_message_from_template('mod_scheduler', $messagename, 1, $sender, $recipient, $course, $template, $vars); } - } diff --git a/message_form.php b/message_form.php index b0a33d6f..250353df 100644 --- a/message_form.php +++ b/message_form.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/formslib.php'); +require_once($CFG->libdir . '/formslib.php'); /** * Message form for invitations (using Moodle formslib) @@ -35,8 +35,8 @@ * @copyright 2016 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_message_form extends moodleform { - +class scheduler_message_form extends moodleform +{ /** * @var scheduler scheduler in whose context the messages are sent */ @@ -49,7 +49,7 @@ class scheduler_message_form extends moodleform { * @param scheduler $scheduler scheduler in whose context the messages are sent * @param object $customdata */ - public function __construct($action, scheduler $scheduler, $customdata=null) { + public function __construct($action, scheduler $scheduler, $customdata = null) { $this->scheduler = $scheduler; parent::__construct($action, $customdata); } @@ -65,11 +65,12 @@ protected function definition() { $checkboxes = []; $recipients = $this->_customdata['recipients']; foreach ($recipients as $recipient) { - $inputid = 'recipient['.$recipient->id.']'; + $inputid = 'recipient[' . $recipient->id . ']'; $label = fullname($recipient); $checkboxes[] = $mform->createElement('checkbox', $inputid, '', $label); $mform->setDefault($inputid, true); } + $mform->addGroup($checkboxes, 'recipients', get_string('recipients', 'scheduler'), null, false); if (get_config('mod_scheduler', 'showemailplain')) { @@ -77,6 +78,7 @@ protected function definition() { foreach ($recipients as $recipient) { $maillist[] = trim($recipient->email); } + $maildisplay = html_writer::div(implode(', ', $maillist)); $mform->addElement('html', $maildisplay); } @@ -91,8 +93,13 @@ protected function definition() { $mform->setDefault('subject', $this->_customdata['subject']); } - $bodyedit = $mform->addElement('editor', 'body', get_string('messagebody', 'scheduler'), - ['rows' => 15, 'columns' => 60], ['collapsed' => true]); + $bodyedit = $mform->addElement( + 'editor', + 'body', + get_string('messagebody', 'scheduler'), + ['rows' => 15, 'columns' => 60], + ['collapsed' => true] + ); $mform->setType('body', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. if (isset($this->_customdata['body'])) { $bodyedit->setValue(['text' => $this->_customdata['body']]); @@ -102,7 +109,6 @@ protected function definition() { $buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('sendmessage', 'scheduler')); $buttonarray[] = $mform->createElement('cancel'); $mform->addGroup($buttonarray, 'buttonar', '', [' '], false); - } /** @@ -118,5 +124,4 @@ public function validation($data, $files) { return $errors; } - } diff --git a/mod_form.php b/mod_form.php index 2aa0898c..d2ac522d 100644 --- a/mod_form.php +++ b/mod_form.php @@ -33,8 +33,8 @@ * @copyright 2011 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_scheduler_mod_form extends moodleform_mod { - +class mod_scheduler_mod_form extends moodleform_mod +{ /** @var array */ protected $editoroptions; @@ -55,6 +55,7 @@ public function definition() { } else { $mform->setType('name', PARAM_CLEANHTML); } + $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); @@ -77,6 +78,7 @@ public function definition() { for ($i = 1; $i <= 10; $i++) { $maxbookoptions[(string)$i] = $i; } + $modegroup[] = $mform->createElement('select', 'maxbookings', '', $maxbookoptions); $mform->setDefault('maxbookings', 1); @@ -99,6 +101,7 @@ public function definition() { foreach ($groupings as $grouping) { $selopt[$grouping->id] = get_string('yesingrouping', 'scheduler', $grouping->name); } + $mform->addElement('select', 'bookingrouping', get_string('groupbookings', 'scheduler'), $selopt); $mform->addHelpButton('bookingrouping', 'groupbookings', 'scheduler'); $mform->setDefault('bookingrouping', '-1'); @@ -141,8 +144,13 @@ public function definition() { $this->editoroptions = ['trusttext' => true, 'maxfiles' => -1, 'maxbytes' => 0, 'context' => $this->context, 'collapsed' => true, ]; - $mform->addElement('editor', 'bookinginstructions_editor', get_string('bookinginstructions', 'scheduler'), - ['rows' => 3, 'columns' => 60], $this->editoroptions); + $mform->addElement( + 'editor', + 'bookinginstructions_editor', + get_string('bookinginstructions', 'scheduler'), + ['rows' => 3, 'columns' => 60], + $this->editoroptions + ); $mform->setType('bookinginstructions', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. $mform->disabledIf('bookinginstructions_editor', 'usebookingform', 'eq', '0'); $mform->addHelpButton('bookinginstructions_editor', 'bookinginstructions', 'scheduler'); @@ -161,6 +169,7 @@ public function definition() { for ($i = 0; $i <= get_config('mod_scheduler', 'uploadmaxfiles'); $i++) { $filechoices[$i] = $i; } + $uploadgroup[] = $mform->createElement('select', 'uploadmaxfiles', get_string('uploadmaxfiles', 'scheduler'), $filechoices); $mform->setDefault('uploadmaxfiles', 0); $mform->disabledIf('uploadmaxfiles', 'usebookingform', 'eq', '0'); @@ -202,11 +211,18 @@ public function definition() { public function data_preprocessing(&$defaultvalues) { parent::data_preprocessing($defaultvalues); if ($this->current->instance) { - $newvalues = file_prepare_standard_editor((object)$defaultvalues, 'bookinginstructions', - $this->editoroptions, $this->context, - 'mod_scheduler', 'bookinginstructions', 0); + $newvalues = file_prepare_standard_editor( + (object)$defaultvalues, + 'bookinginstructions', + $this->editoroptions, + $this->context, + 'mod_scheduler', + 'bookinginstructions', + 0 + ); $defaultvalues['bookinginstructions_editor'] = $newvalues->bookinginstructions_editor; } + if (array_key_exists('scale', $defaultvalues)) { $dgrade = $defaultvalues['scale']; $defaultvalues['grade'] = $dgrade; @@ -216,6 +232,7 @@ public function data_preprocessing(&$defaultvalues) { } else if ($dgrade < 0) { $type = 'scale'; } + $defaultvalues['grade[modgrade_type]'] = $type; } } @@ -231,14 +248,17 @@ public function save_mod_data(stdClass $data, context_module $context) { $editor = $data->bookinginstructions_editor; if ($editor && array_key_exists('text', $editor)) { - $data->bookinginstructions = file_save_draft_area_files($editor['itemid'], $context->id, - 'mod_scheduler', 'bookinginstructions', 0, - $this->editoroptions, $editor['text']); + $data->bookinginstructions = file_save_draft_area_files( + $editor['itemid'], + $context->id, + 'mod_scheduler', + 'bookinginstructions', + 0, + $this->editoroptions, + $editor['text'] + ); $data->bookinginstructionsformat = $editor['format']; $DB->update_record('scheduler', $data); } } - - - } diff --git a/renderable.php b/renderable.php index f7d8eea1..a6d2eb4e 100644 --- a/renderable.php +++ b/renderable.php @@ -28,14 +28,16 @@ use mod_scheduler\model\slot; use mod_scheduler\model\appointment; +// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses + /** * This class represents a table of slots associated with one student * * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_slot_table implements renderable { - +class scheduler_slot_table implements renderable +{ /** @var array list of slots in this table */ public $slots = []; @@ -82,13 +84,20 @@ class scheduler_slot_table implements renderable { * @param bool $canedit whether the user can edit the slot/appointment * @param bool $canview whether the user can view the appointment */ - public function add_slot(slot $slotmodel, appointment $appointmentmodel, - $otherstudents, $cancancel = false, $canedit = false, $canview = false) { + public function add_slot( + slot $slotmodel, + appointment $appointmentmodel, + $otherstudents, + $cancancel = false, + $canedit = false, + $canview = false + ) { $slot = new stdClass(); $slot->slotid = $slotmodel->id; if ($this->showstudent) { $slot->student = $appointmentmodel->student; } + $slot->starttime = $slotmodel->starttime; $slot->endtime = $slotmodel->endtime; $slot->attended = $appointmentmodel->attended; @@ -101,10 +110,12 @@ public function add_slot(slot $slotmodel, appointment $appointmentmodel, $slot->appointmentnote = $appointmentmodel->appointmentnote; $slot->appointmentnoteformat = $appointmentmodel->appointmentnoteformat; } + if ($this->scheduler->uses_teachernotes() && $this->showteachernotes) { $slot->teachernote = $appointmentmodel->teachernote; $slot->teachernoteformat = $appointmentmodel->teachernoteformat; } + $slot->otherstudents = $otherstudents; $slot->cancancel = $cancancel; $slot->canedit = $canedit; @@ -112,6 +123,7 @@ public function add_slot(slot $slotmodel, appointment $appointmentmodel, if ($this->showgrades) { $slot->grade = $appointmentmodel->grade; } + $this->showactions = $this->showactions || $cancancel; $this->hasotherstudents = $this->hasotherstudents || (bool) $otherstudents; @@ -125,12 +137,11 @@ public function add_slot(slot $slotmodel, appointment $appointmentmodel, * @param bool $showgrades whether to show grades * @param moodle_url|null $actionurl action URL for buttons */ - public function __construct(scheduler $scheduler, $showgrades=true, $actionurl = null) { + public function __construct(scheduler $scheduler, $showgrades = true, $actionurl = null) { $this->scheduler = $scheduler; $this->showgrades = $showgrades && $scheduler->uses_grades(); $this->actionurl = $actionurl; } - } @@ -140,8 +151,8 @@ public function __construct(scheduler $scheduler, $showgrades=true, $actionurl = * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_student_list implements renderable { - +class scheduler_student_list implements renderable +{ /** @var array list of students to be displayed */ public $students = []; @@ -182,8 +193,14 @@ class scheduler_student_list implements renderable { * @param bool $showstudprovided whether to show an icon for student-provided files * @param bool $editattended whether to make the attended tickbox editable */ - public function add_student(appointment $appointment, $highlight, $checked = false, - $showgrade = true, $showstudprovided = false, $editattended = false) { + public function add_student( + appointment $appointment, + $highlight, + $checked = false, + $showgrade = true, + $showstudprovided = false, + $editattended = false + ) { $student = new stdClass(); $student->user = $appointment->get_student(); if ($this->showgrades && $showgrade) { @@ -191,6 +208,7 @@ public function add_student(appointment $appointment, $highlight, $checked = fal } else { $student->grade = null; } + $student->highlight = $highlight; $student->checked = $checked; $student->editattended = $editattended; @@ -204,6 +222,7 @@ public function add_student(appointment $appointment, $highlight, $checked = fal $student->filesprovided = $appointment->count_studentfiles(); } } + $this->students[] = $student; } @@ -217,7 +236,6 @@ public function __construct(scheduler $scheduler, $showgrades = true) { $this->scheduler = $scheduler; $this->showgrades = $showgrades; } - } @@ -227,8 +245,8 @@ public function __construct(scheduler $scheduler, $showgrades = true) { * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_slot_booker implements renderable { - +class scheduler_slot_booker implements renderable +{ /** * @var array list of slots to be displayed */ @@ -288,7 +306,6 @@ public function __construct(scheduler $scheduler, $studentid, moodle_url $action $this->studentid = $studentid; $this->actionurl = $actionurl; } - } /** @@ -297,8 +314,8 @@ public function __construct(scheduler $scheduler, $studentid, moodle_url $action * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_command_bar implements renderable { - +class scheduler_command_bar implements renderable +{ /** * @var array list of drop-down menus in the command bar */ @@ -343,10 +360,12 @@ public function action_link(moodle_url $url, $titlekey, $iconkey, $confirmkey = if ($id) { $attributes['id'] = $id; } + $confirmaction = null; if ($confirmkey) { $confirmaction = new confirm_action(get_string($confirmkey, 'scheduler')); } + $act = new action_link($url, $title, $confirmaction, $attributes, $pix); return $act; } @@ -368,10 +387,12 @@ public function action_menu_link(moodle_url $url, $titlekey, $iconkey, $confirmk if ($id) { $attributes['id'] = $id; } + $act = new action_menu_link($url, $pix, $title, false, $attributes); if ($confirmkey) { $act->add_action(new confirm_action(get_string($confirmkey, 'scheduler'))); } + return $act; } @@ -381,7 +402,6 @@ public function action_menu_link(moodle_url $url, $titlekey, $iconkey, $confirmk public function __construct() { // Nothing to add right now. } - } /** @@ -390,8 +410,8 @@ public function __construct() { * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_slot_manager implements renderable { - +class scheduler_slot_manager implements renderable +{ /** * @var array list of slots */ @@ -445,7 +465,6 @@ public function __construct(scheduler $scheduler, moodle_url $actionurl) { $this->scheduler = $scheduler; $this->actionurl = $actionurl; } - } @@ -455,8 +474,8 @@ public function __construct(scheduler $scheduler, moodle_url $actionurl) { * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_scheduling_list implements renderable { - +class scheduler_scheduling_list implements renderable +{ /** * @var array lines in the list */ @@ -505,7 +524,6 @@ public function __construct(scheduler $scheduler, array $extraheaders) { $this->scheduler = $scheduler; $this->extraheaders = $extraheaders; } - } /** @@ -516,8 +534,8 @@ public function __construct(scheduler $scheduler, array $extraheaders) { * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_totalgrade_info implements renderable { - +class scheduler_totalgrade_info implements renderable +{ /** * @var stdClass|null gradebook grade for the student */ @@ -552,7 +570,6 @@ public function __construct(scheduler $scheduler, $gbgrade, $showtotalgrade = fa $this->showtotalgrade = $showtotalgrade; $this->totalgrade = $totalgrade; } - } /** @@ -561,8 +578,8 @@ public function __construct(scheduler $scheduler, $gbgrade, $showtotalgrade = fa * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_conflict_list implements renderable { - +class scheduler_conflict_list implements renderable +{ /** * @var array list of conflicts */ @@ -581,6 +598,7 @@ public function add_conflict(stdClass $conflict, $user = null) { } else { $c->userfullname = ''; } + $this->conflicts[] = $c; } @@ -594,7 +612,6 @@ public function add_conflicts(array $conflicts) { $this->add_conflict($c); } } - } /** @@ -603,8 +620,8 @@ public function add_conflicts(array $conflicts) { * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_appointment_info implements renderable { - +class scheduler_appointment_info implements renderable +{ /** * @var scheduler scheduler in whose context the appointment is */ @@ -659,8 +676,12 @@ class scheduler_appointment_info implements renderable { * @param string $groupinfo information about the group that the booking is for * @return scheduler_appointment_info */ - public static function make_from_slot(slot $slot, $showbookinginstr = true, $onstudentside = true, - $groupinfo = null) { + public static function make_from_slot( + slot $slot, + $showbookinginstr = true, + $onstudentside = true, + $groupinfo = null + ) { $info = new scheduler_appointment_info(); $info->slot = $slot; $info->scheduler = $slot->get_scheduler(); diff --git a/renderer.php b/renderer.php index 57dae16d..7a76920b 100644 --- a/renderer.php +++ b/renderer.php @@ -35,8 +35,8 @@ * @copyright 2016 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_scheduler_renderer extends plugin_renderer_base { - +class mod_scheduler_renderer extends plugin_renderer_base +{ /** * Constructor method, calls the parent constructor * @@ -75,9 +75,11 @@ public static function usertime($date) { if (empty($timeformat)) { $timeformat = get_config(null, 'calendar_site_timeformat'); // Get calendar config if above not exist. } + if (empty($timeformat)) { $timeformat = get_string('strftimetime'); // Get locale default format if both of the above do not exist. } + return userdate($date, $timeformat); } } @@ -127,6 +129,7 @@ public function get_scale_levels($scaleid) { } } } + return $this->scalecache[$scaleid]; } @@ -148,7 +151,7 @@ public function format_grade($subject, $grade, $short = false, $decimals = 0) { } $result = ''; - if ($scaleid == 0 || is_null($grade) ) { + if ($scaleid == 0 || is_null($grade)) { // Scheduler doesn't allow grading, or no grade entered. if (!$short) { $result = get_string('nograde'); @@ -171,10 +174,12 @@ public function format_grade($subject, $grade, $short = false, $decimals = 0) { } } } + if ($short && (strlen($result) > 0)) { - $result = '('.$result.')'; + $result = '(' . $result . ')'; } } + return $result; } @@ -197,6 +202,7 @@ public function grading_choices($scheduler) { $scaleid = - ($scheduler->scale); $scalegrades = $this->get_scale_levels($scaleid); } + $scalegrades = [-1 => get_string('nograde')] + $scalegrades; return $scalegrades; } @@ -243,13 +249,25 @@ public function format_appointment_notes(scheduler $scheduler, $data, $idfield = $note = ''; $id = $data->{$idfield}; if (isset($data->appointmentnote) && $scheduler->uses_appointmentnotes()) { - $note .= $this->format_notes($data->appointmentnote, $data->appointmentnoteformat, $scheduler->get_context(), - 'appointmentnote', $id); + $note .= $this->format_notes( + $data->appointmentnote, + $data->appointmentnoteformat, + $scheduler->get_context(), + 'appointmentnote', + $id + ); } + if (isset($data->teachernote) && $scheduler->uses_teachernotes()) { - $note .= $this->format_notes($data->teachernote, $data->teachernoteformat, $scheduler->get_context(), - 'teachernote', $id); + $note .= $this->format_notes( + $data->teachernote, + $data->teachernoteformat, + $scheduler->get_context(), + 'teachernote', + $id + ); } + return $note; } @@ -307,13 +325,18 @@ public function render_attachments($contextid, $filearea, $itemid) { $filename = $file->get_filename(); $pathname = $file->get_filepath(); $mimetype = $file->get_mimetype(); - $iconimage = $this->pix_icon(file_file_icon($file), get_mimetype_description($file), - 'moodle', ['class' => 'icon']); + $iconimage = $this->pix_icon( + file_file_icon($file), + get_mimetype_description($file), + 'moodle', + ['class' => 'icon'] + ); $path = moodle_url::make_pluginfile_url($contextid, 'mod_scheduler', $filearea, $itemid, $pathname, $filename); $ulitem = html_writer::link($path, $iconimage) . html_writer::link($path, s($filename)); $o .= html_writer::tag('ul', $ulitem); } + $o .= html_writer::end_tag('ul'); } @@ -349,15 +372,24 @@ private function teacherview_tab(moodle_url $baseurl, $namekey, $what, $subpage * @param array $inactive any inactive tabs * @return string rendered tab tree */ - public function teacherview_tabs(scheduler $scheduler, scheduler_permissions $permissions, - moodle_url $baseurl, $selected, $inactive = null) { - + public function teacherview_tabs( + scheduler $scheduler, + scheduler_permissions $permissions, + moodle_url $baseurl, + $selected, + $inactive = null + ) { $statstab = $this->teacherview_tab($baseurl, 'statistics', 'viewstatistics', 'overall'); $statstab->subtree = [ $this->teacherview_tab($baseurl, 'overall', 'viewstatistics', 'overall'), $this->teacherview_tab($baseurl, 'studentbreakdown', 'viewstatistics', 'studentbreakdown'), - $this->teacherview_tab($baseurl, 'staffbreakdown', 'viewstatistics', 'staffbreakdown', - $scheduler->get_teacher_name()), + $this->teacherview_tab( + $baseurl, + 'staffbreakdown', + 'viewstatistics', + 'staffbreakdown', + $scheduler->get_teacher_name() + ), $this->teacherview_tab($baseurl, 'lengthbreakdown', 'viewstatistics', 'lengthbreakdown'), $this->teacherview_tab($baseurl, 'groupbreakdown', 'viewstatistics', 'groupbreakdown'), ]; @@ -367,6 +399,7 @@ public function teacherview_tabs(scheduler $scheduler, scheduler_permissions $pe if ($permissions->can_see_all_slots()) { $level1[] = $this->teacherview_tab($baseurl, 'allappointments', 'view', 'allappointments'); } + $level1[] = $this->teacherview_tab($baseurl, 'datelist', 'datelist'); $level1[] = $statstab; $level1[] = $this->teacherview_tab($baseurl, 'export', 'export'); @@ -387,18 +420,22 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { $table->head = [get_string('date', 'scheduler')]; $table->align = ['left']; } + if ($slottable->showstudent) { $table->head[] = get_string('name'); $table->align[] = 'left'; } + if ($slottable->showattended) { $table->head[] = get_string('seen', 'scheduler'); $table->align[] = 'center'; } + if ($slottable->showslot) { $table->head[] = $slottable->scheduler->get_teacher_name(); $table->align[] = 'left'; } + if ($slottable->showslot && $slottable->showlocation) { $table->head[] = get_string('location', 'scheduler'); $table->align[] = 'left'; @@ -414,6 +451,7 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { $table->head[] = get_string('otherstudents', 'scheduler'); $table->align[] = 'left'; } + if ($slottable->showactions) { $table->head[] = ''; $table->align[] = 'right'; @@ -430,6 +468,7 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { if ($slottable->showeditlink) { $timedata = $this->action_link($studenturl, $timedata); } + $timedata = html_writer::div($timedata, 'datelabel'); $starttime = $this->usertime($slot->starttime); @@ -445,6 +484,7 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { if ($slottable->showeditlink) { $name = $this->action_link($studenturl, $name); } + $rowdata[] = $name; } @@ -465,9 +505,15 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { $notes = ''; if ($slottable->showslot && isset($slot->slotnote)) { - $notes .= $this->format_notes($slot->slotnote, $slot->slotnoteformat, - $slottable->scheduler->get_context(), 'slotnote', $slot->slotid); + $notes .= $this->format_notes( + $slot->slotnote, + $slot->slotnoteformat, + $slottable->scheduler->get_context(), + 'slotnote', + $slot->slotid + ); } + $notes .= $this->format_appointment_notes($slottable->scheduler, $slot, 'appointmentid'); $rowdata[] = $notes; @@ -478,30 +524,42 @@ public function render_scheduler_slot_table(scheduler_slot_table $slottable) { } else if ($slottable->showgrades) { $gradedata = $this->format_grade($slottable->scheduler, $slot->grade); } + $rowdata[] = $gradedata; } + if ($slottable->showactions) { $actions = ''; if ($slot->canedit) { - $buttonurl = new moodle_url($slottable->actionurl, - ['what' => 'editbooking', 'appointmentid' => $slot->appointmentid]); + $buttonurl = new moodle_url( + $slottable->actionurl, + ['what' => 'editbooking', 'appointmentid' => $slot->appointmentid] + ); $button = new single_button($buttonurl, get_string('editbooking', 'scheduler')); $actions .= $this->render($button); } + if ($slot->canview) { - $buttonurl = new moodle_url($slottable->actionurl, - ['what' => 'viewbooking', 'appointmentid' => $slot->appointmentid]); + $buttonurl = new moodle_url( + $slottable->actionurl, + ['what' => 'viewbooking', 'appointmentid' => $slot->appointmentid] + ); $button = new single_button($buttonurl, get_string('viewbooking', 'scheduler')); $actions .= $this->render($button); } + if ($slot->cancancel) { - $buttonurl = new moodle_url($slottable->actionurl, - ['what' => 'cancelbooking', 'slotid' => $slot->slotid]); + $buttonurl = new moodle_url( + $slottable->actionurl, + ['what' => 'cancelbooking', 'slotid' => $slot->slotid] + ); $button = new single_button($buttonurl, get_string('cancelbooking', 'scheduler')); $actions .= $this->render($button); } + $rowdata[] = $actions; } + $table->data[] = $rowdata; } @@ -521,14 +579,18 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis $toggleid = html_writer::random_id('toggle'); if ($studentlist->expandable && count($studentlist->students) > 0) { - $this->page->requires->js_call_amd('mod_scheduler/studentlist', 'init', [$toggleid, (boolean) $studentlist->expanded]); + $this->page->requires->js_call_amd('mod_scheduler/studentlist', 'init', [$toggleid, (bool) $studentlist->expanded]); $imgclass = 'studentlist-togglebutton'; $alttext = get_string('showparticipants', 'scheduler'); - $o .= $this->output->pix_icon('t/switch', $alttext, 'moodle', - ['id' => $toggleid, 'class' => $imgclass]); + $o .= $this->output->pix_icon( + 't/switch', + $alttext, + 'moodle', + ['id' => $toggleid, 'class' => $imgclass] + ); } - $divprops = ['id' => 'list'.$toggleid]; + $divprops = ['id' => 'list' . $toggleid]; $o .= html_writer::start_div('studentlist', $divprops); if (count($studentlist->students) > 0) { $editable = $studentlist->actionurl && $studentlist->editable; @@ -542,26 +604,35 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis $checkbox = ''; if ($studentlist->checkboxname) { if ($student->editattended) { - $checkbox = html_writer::checkbox($studentlist->checkboxname, $student->entryid, $student->checked, '', - ['class' => 'studentselect']); + $checkbox = html_writer::checkbox( + $studentlist->checkboxname, + $student->entryid, + $student->checked, + '', + ['class' => 'studentselect'] + ); } else { $img = $student->checked ? 'ticked' : 'unticked'; $checkbox = $this->render(new pix_icon($img, '', 'scheduler', ['class' => 'statictickbox'])); } } + if ($studentlist->linkappointment) { $name = $this->appointment_link($studentlist->scheduler, $student->user, $student->entryid); } else { $name = fullname($student->user); } + $studicons = ''; $studprovided = []; if ($student->notesprovided) { $studprovided[] = get_string('message', 'scheduler'); } + if ($student->filesprovided) { $studprovided[] = get_string('nfiles', 'scheduler', $student->filesprovided); } + if ($studprovided) { $providedstr = implode(', ', $studprovided); $alttext = get_string('studentprovided', 'scheduler', $providedstr); @@ -572,11 +643,13 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis if ($student->highlight) { $class .= ' highlight'; } + $picture = $this->user_picture($student->user, ['courseid' => $studentlist->scheduler->courseid]); $grade = ''; if ($studentlist->showgrades && $student->grade) { $grade = $this->format_grade($studentlist->scheduler, $student->grade, true); } + $o .= html_writer::div($checkbox . $picture . ' ' . $name . $studicons . ' ' . $grade, $class); } @@ -589,6 +662,7 @@ public function render_scheduler_student_list(scheduler_student_list $studentlis $o .= html_writer::end_tag('form'); } } + $o .= html_writer::end_div(); return $o; @@ -617,7 +691,6 @@ public function render_scheduler_slot_booker(scheduler_slot_booker $booker) { $canappoint = false; foreach ($booker->slots as $slot) { - $rowdata = []; $startdate = $this->userdate($slot->starttime); @@ -647,8 +720,13 @@ public function render_scheduler_slot_booker(scheduler_slot_booker $booker) { $rowdata[] = format_string($slot->location); - $rowdata[] = $this->format_notes($slot->notes, $slot->notesformat, $booker->scheduler->get_context(), - 'slotnote', $slot->slotid); + $rowdata[] = $this->format_notes( + $slot->notes, + $slot->notesformat, + $booker->scheduler->get_context(), + 'slotnote', + $slot->slotid + ); $rowdata[] = $this->user_profile_link($booker->scheduler, $slot->teacher); @@ -697,6 +775,7 @@ public function render_action_menu(action_menu $menu) { if ($menu->is_empty()) { return ''; } + $context = $menu->export_for_template($this); if ($CFG->version > 2025041400) { $context->primary->bs5 = "bs5"; @@ -715,13 +794,16 @@ public function render_scheduler_command_bar(scheduler_command_bar $commandbar) foreach ($commandbar->linkactions as $id => $action) { $this->add_action_handler($action, $id); } + $o .= html_writer::start_div('commandbar'); if ($commandbar->title) { $o .= html_writer::span($commandbar->title, 'title'); } + foreach ($commandbar->menus as $m) { $o .= $this->render($m); } + $o .= html_writer::end_div(); return $o; } @@ -734,7 +816,7 @@ public function render_scheduler_command_bar(scheduler_command_bar $commandbar) */ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { - $this->page->requires->js_call_amd('mod_scheduler/saveseen', 'init', [$slotman->scheduler->cmid] ); + $this->page->requires->js_call_amd('mod_scheduler/saveseen', 'init', [$slotman->scheduler->cmid]); $o = ''; @@ -746,6 +828,7 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { $table->head[] = s($slotman->scheduler->get_teacher_name()); $table->align[] = 'left'; } + $table->head[] = get_string('action', 'scheduler'); $table->align[] = 'center'; @@ -757,7 +840,6 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { $previousendtime = ''; foreach ($slotman->slots as $slot) { - $rowdata = []; $selectbox = html_writer::checkbox('selectedslot[]', $slot->slotid, false, '', ['class' => 'slotselect']); @@ -813,7 +895,9 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { } else { $groupicon = 't/groupv'; } - $groupalt = ''; $groupact = null; + + $groupalt = ''; + $groupact = null; if ($slot->isattended) { $groupalt = 'attended'; } else if ($slot->isappointed > 1) { @@ -833,6 +917,7 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { $groupalt = 'forbidgroup'; } } + if ($groupact) { $url = new moodle_url($slotman->actionurl, $groupact); $actions .= $this->action_icon($url, new pix_icon($groupicon, get_string($groupalt, 'scheduler'))); @@ -847,8 +932,9 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { } if ($slot->exclusivity > 1) { - $actions .= ' ('.$slot->exclusivity.')'; + $actions .= ' (' . $slot->exclusivity . ')'; } + $rowdata[] = $actions; $table->data[] = $rowdata; @@ -857,6 +943,7 @@ public function render_scheduler_slot_manager(scheduler_slot_manager $slotman) { $previousendtime = $endtime; $previousdate = $startdate; } + $o .= html_writer::table($table); return $o; @@ -879,6 +966,7 @@ public function render_scheduler_scheduling_list(scheduler_scheduling_list $list $mtable->head[] = $field; $mtable->align[] = 'left'; } + $mtable->head[] = get_string('action', 'scheduler'); $mtable->align[] = 'center'; @@ -888,15 +976,18 @@ public function render_scheduler_scheduling_list(scheduler_scheduling_list $list foreach ($line->extrafields as $field) { $data[] = $field; } + $actions = ''; if ($line->actions) { $menu = new action_menu($line->actions); $menu->actiontext = get_string('schedule', 'scheduler'); $actions = $this->render($menu); } + $data[] = $actions; $mtable->data[] = $data; } + return html_writer::table($mtable); } @@ -920,15 +1011,19 @@ public function render_scheduler_totalgrade_info(scheduler_totalgrade_info $grad if ($gradeinfo->gbgrade->hidden) { $attributes[] = get_string('hidden', 'grades'); } + if ($gradeinfo->gbgrade->locked) { $attributes[] = get_string('locked', 'grades'); } + if ($gradeinfo->gbgrade->overridden) { $attributes[] = get_string('overridden', 'grades'); } + if (count($attributes) > 0) { - $gbgradestr .= ' ('.implode(', ', $attributes) .')'; + $gbgradestr .= ' (' . implode(', ', $attributes) . ')'; } + $items[] = ['gradeingradebook', $gbgradestr]; } @@ -938,6 +1033,7 @@ public function render_scheduler_totalgrade_info(scheduler_totalgrade_info $grad $o .= html_writer::tag('dt', get_string($item[0], 'scheduler')); $o .= html_writer::tag('dd', $item[1]); } + $o .= html_writer::end_tag('dl'); $o .= html_writer::end_div('totalgrade'); return $o; @@ -965,6 +1061,7 @@ public function render_scheduler_conflict_list(scheduler_conflict_list $cl) { $a->schedulername = format_string($conflict->schedulername); $entry = get_string('conflictremote', 'scheduler', $a); } + $o .= html_writer::tag('li', $entry); } @@ -1013,8 +1110,13 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai if ($ai->slot->notes) { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('comments', 'scheduler')); - $notes = $this->format_notes($ai->slot->notes, $ai->slot->notesformat, $ai->scheduler->get_context(), - 'slotnote', $ai->slot->id); + $notes = $this->format_notes( + $ai->slot->notes, + $ai->slot->notesformat, + $ai->scheduler->get_context(), + 'slotnote', + $ai->slot->id + ); $cell2 = new html_table_cell($notes); $row->cells = [$cell1, $cell2]; $t->data[] = $row; @@ -1033,8 +1135,13 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai if ($ai->scheduler->has_bookinginstructions()) { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('bookinginstructions', 'scheduler')); - $note = $this->format_notes($ai->scheduler->bookinginstructions, $ai->scheduler->bookinginstructionsformat, - $ai->scheduler->get_context(), 'bookinginstructions', 0); + $note = $this->format_notes( + $ai->scheduler->bookinginstructions, + $ai->scheduler->bookinginstructionsformat, + $ai->scheduler->get_context(), + 'bookinginstructions', + 0 + ); $cell2 = new html_table_cell($note); $row->cells = [$cell1, $cell2]; $t->data[] = $row; @@ -1049,12 +1156,14 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai } else { $key = 'studentnote'; } + $cell1 = new html_table_cell(get_string($key, 'scheduler')); $note = format_text($ai->appointment->studentnote, $ai->appointment->studentnoteformat); $cell2 = new html_table_cell($note); $row->cells = [$cell1, $cell2]; $t->data[] = $row; } + if ($ai->scheduler->uses_studentfiles()) { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('studentfiles', 'scheduler')); @@ -1069,12 +1178,18 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai if ($ai->scheduler->uses_appointmentnotes() && $ai->appointment->appointmentnote) { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('appointmentnote', 'scheduler')); - $note = $this->format_notes($ai->appointment->appointmentnote, $ai->appointment->appointmentnoteformat, - $ai->scheduler->get_context(), 'appointmentnote', $ai->appointment->id); + $note = $this->format_notes( + $ai->appointment->appointmentnote, + $ai->appointment->appointmentnoteformat, + $ai->scheduler->get_context(), + 'appointmentnote', + $ai->appointment->id + ); $cell2 = new html_table_cell($note); $row->cells = [$cell1, $cell2]; $t->data[] = $row; } + if ($ai->scheduler->uses_grades()) { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('grade', 'scheduler')); @@ -1091,5 +1206,4 @@ public function render_scheduler_appointment_info(scheduler_appointment_info $ai $o .= $this->output->container_end(); return $o; } - } diff --git a/settings.php b/settings.php index b2fee38b..21bfd8fe 100644 --- a/settings.php +++ b/settings.php @@ -25,37 +25,49 @@ defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) { + require_once($CFG->dirroot . '/mod/scheduler/lib.php'); - require_once($CFG->dirroot.'/mod/scheduler/lib.php'); + $settings->add(new admin_setting_configcheckbox( + 'mod_scheduler/showemailplain', + get_string('showemailplain', 'scheduler'), + get_string('showemailplain_desc', 'scheduler'), + 0 + )); - $settings->add(new admin_setting_configcheckbox('mod_scheduler/showemailplain', - get_string('showemailplain', 'scheduler'), - get_string('showemailplain_desc', 'scheduler'), - 0)); + $settings->add(new admin_setting_configcheckbox( + 'mod_scheduler/groupscheduling', + get_string('groupscheduling', 'scheduler'), + get_string('groupscheduling_desc', 'scheduler'), + 1 + )); - $settings->add(new admin_setting_configcheckbox('mod_scheduler/groupscheduling', - get_string('groupscheduling', 'scheduler'), - get_string('groupscheduling_desc', 'scheduler'), - 1)); + $settings->add(new admin_setting_configcheckbox( + 'mod_scheduler/mixindivgroup', + get_string('mixindivgroup', 'scheduler'), + get_string('mixindivgroup_desc', 'scheduler'), + 1 + )); - $settings->add(new admin_setting_configcheckbox('mod_scheduler/mixindivgroup', - get_string('mixindivgroup', 'scheduler'), - get_string('mixindivgroup_desc', 'scheduler'), - 1)); + $settings->add(new admin_setting_configtext( + 'mod_scheduler/maxstudentlistsize', + get_string('maxstudentlistsize', 'scheduler'), + get_string('maxstudentlistsize_desc', 'scheduler'), + 200, + PARAM_INT + )); - $settings->add(new admin_setting_configtext('mod_scheduler/maxstudentlistsize', - get_string('maxstudentlistsize', 'scheduler'), - get_string('maxstudentlistsize_desc', 'scheduler'), - 200, PARAM_INT)); - - $settings->add(new admin_setting_configtext('mod_scheduler/uploadmaxfiles', - get_string('uploadmaxfilesglobal', 'scheduler'), - get_string('uploadmaxfilesglobal_desc', 'scheduler'), - 5, PARAM_INT)); - - $settings->add(new admin_setting_configcheckbox('mod_scheduler/revealteachernotes', - get_string('revealteachernotes', 'scheduler'), - get_string('revealteachernotes_desc', 'scheduler'), - 0)); + $settings->add(new admin_setting_configtext( + 'mod_scheduler/uploadmaxfiles', + get_string('uploadmaxfilesglobal', 'scheduler'), + get_string('uploadmaxfilesglobal_desc', 'scheduler'), + 5, + PARAM_INT + )); + $settings->add(new admin_setting_configcheckbox( + 'mod_scheduler/revealteachernotes', + get_string('revealteachernotes', 'scheduler'), + get_string('revealteachernotes_desc', 'scheduler'), + 0 + )); } diff --git a/slotforms.php b/slotforms.php index 73819b94..1f3a1377 100644 --- a/slotforms.php +++ b/slotforms.php @@ -27,7 +27,9 @@ use mod_scheduler\model\scheduler; use mod_scheduler\model\slot; -require_once($CFG->libdir.'/formslib.php'); +require_once($CFG->libdir . '/formslib.php'); + +// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses /** * Base class for slot-related forms @@ -36,8 +38,8 @@ * @copyright 2013 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -abstract class scheduler_slotform_base extends moodleform { - +abstract class scheduler_slotform_base extends moodleform +{ /** * @var scheduler the scheduler that this form refers to */ @@ -67,7 +69,13 @@ abstract class scheduler_slotform_base extends moodleform { * @param array $usergroups groups to filter for * @param array $customdata */ - public function __construct($action, scheduler $scheduler, $cm, $usergroups, $customdata=null) { + public function __construct( + $action, + scheduler $scheduler, + $cm, + $usergroups, + $customdata = null + ) { $this->scheduler = $scheduler; $this->usergroups = $usergroups; $this->noteoptions = ['trusttext' => true, 'maxfiles' => -1, 'maxbytes' => 0, @@ -115,19 +123,20 @@ protected function add_base_fields() { foreach ($teachers as $teacher) { $teachersmenu[$teacher->id] = fullname($teacher); } + $mform->addElement('select', 'teacherid', $teachername, $teachersmenu); $mform->addRule('teacherid', get_string('noteacherforslot', 'scheduler'), 'required'); $mform->setDefault('teacherid', $USER->id); } else { $mform->addElement('static', 'teacherid', $teachername, get_string('noteachershere', 'scheduler', $teachername)); } + $mform->addHelpButton('teacherid', 'bookwithteacher', 'scheduler'); } else { $mform->addElement('hidden', 'teacherid'); $mform->setDefault('teacherid', $USER->id); $mform->setType('teacherid', PARAM_INT); } - } /** @@ -142,8 +151,8 @@ protected function add_minutes_field($name, $label, $defaultval, $minuteslabel = $mform = $this->_form; $group = []; $group[] =& $mform->createElement('text', $name, '', ['size' => 5]); - $group[] =& $mform->createElement('static', $name.'mintext', '', get_string($minuteslabel, 'scheduler')); - $mform->addGroup($group, $name.'group', get_string($label, 'scheduler'), [' '], false); + $group[] =& $mform->createElement('static', $name . 'mintext', '', get_string($minuteslabel, 'scheduler')); + $mform->addGroup($group, $name . 'group', get_string($label, 'scheduler'), [' '], false); $mform->setType($name, PARAM_INT); $mform->setDefault($name, $defaultval); } @@ -178,7 +187,6 @@ public function validation($data, $files) { return $errors; } - } /** @@ -188,8 +196,8 @@ public function validation($data, $files) { * @copyright 2013 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class scheduler_editslot_form extends scheduler_slotform_base { - +class scheduler_editslot_form extends scheduler_slotform_base +{ /** * @var int id of the slot being edited */ @@ -207,6 +215,7 @@ protected function definition() { if (isset($this->_customdata['slotid'])) { $this->slotid = $this->_customdata['slotid']; } + $timeoptions = null; if (isset($this->_customdata['timeoptions'])) { $timeoptions = $this->_customdata['timeoptions']; @@ -233,13 +242,22 @@ protected function definition() { $mform->setDefault('hideuntil', time()); // Send e-mail reminder? - $mform->addElement('date_selector', 'emaildate', get_string('emailreminderondate', 'scheduler'), - ['optional' => true]); + $mform->addElement( + 'date_selector', + 'emaildate', + get_string('emailreminderondate', 'scheduler'), + ['optional' => true] + ); $mform->setDefault('remindersel', -1); // Slot comments. - $mform->addElement('editor', 'notes_editor', get_string('comments', 'scheduler'), - ['rows' => 3, 'columns' => 60], $this->noteoptions); + $mform->addElement( + 'editor', + 'notes_editor', + get_string('comments', 'scheduler'), + ['rows' => 3, 'columns' => 60], + $this->noteoptions + ); $mform->setType('notes', PARAM_RAW); // Must be PARAM_RAW for rich text editor content. // Appointments. @@ -273,12 +291,23 @@ protected function definition() { // Appointment notes, visible to teacher and/or student. if ($this->scheduler->uses_appointmentnotes()) { - $repeatarray[] = $mform->createElement('editor', 'appointmentnote_editor', get_string('appointmentnote', 'scheduler'), - ['rows' => 3, 'columns' => 60], $this->noteoptions); + $repeatarray[] = $mform->createElement( + 'editor', + 'appointmentnote_editor', + get_string('appointmentnote', 'scheduler'), + ['rows' => 3, 'columns' => 60], + $this->noteoptions + ); } + if ($this->scheduler->uses_teachernotes()) { - $repeatarray[] = $mform->createElement('editor', 'teachernote_editor', get_string('teachernote', 'scheduler'), - ['rows' => 3, 'columns' => 60], $this->noteoptions); + $repeatarray[] = $mform->createElement( + 'editor', + 'teachernote_editor', + get_string('teachernote', 'scheduler'), + ['rows' => 3, 'columns' => 60], + $this->noteoptions + ); } // Tickbox to remove the student. @@ -304,11 +333,17 @@ protected function definition() { $repeateloptions['deletestudent']['disabledif'] = $nostudcheck; $repeateloptions['appointhead']['expanded'] = true; - $this->repeat_elements($repeatarray, $repeatno, $repeateloptions, - 'appointment_repeats', 'appointment_add', 1, get_string('addappointment', 'scheduler')); + $this->repeat_elements( + $repeatarray, + $repeatno, + $repeateloptions, + 'appointment_repeats', + 'appointment_add', + 1, + get_string('addappointment', 'scheduler') + ); $this->add_action_buttons(); - } /** @@ -331,6 +366,7 @@ public function validation($data, $files) { $numappointments++; } } + if ($data['exclusivityenable'] && $data['exclusivity'] <= 0) { $errors['exclusivitygroup'] = get_string('exclusivitypositive', 'scheduler'); } else if ($data['exclusivityenable'] && $numappointments > $data['exclusivity']) { @@ -345,10 +381,12 @@ public function validation($data, $files) { // Check whether students have been selected several times. for ($i = 0; $i < $data['appointment_repeats']; $i++) { for ($j = 0; $j < $i; $j++) { - if ($data['deletestudent'][$j] == 0 && $data['studentid'][$i] > 0 - && $data['studentid'][$i] == $data['studentid'][$j]) { - $errors['studgroup['.$i.']'] = get_string('studentmultiselect', 'scheduler'); - $errors['studgroup['.$j.']'] = get_string('studentmultiselect', 'scheduler'); + if ( + $data['deletestudent'][$j] == 0 && $data['studentid'][$i] > 0 + && $data['studentid'][$i] == $data['studentid'][$j] + ) { + $errors['studgroup[' . $i . ']'] = get_string('studentmultiselect', 'scheduler'); + $errors['studgroup[' . $j . ']'] = get_string('studentmultiselect', 'scheduler'); } } } @@ -356,11 +394,15 @@ public function validation($data, $files) { if (!isset($data['ignoreconflicts'])) { /* Avoid overlapping slots by warning the user */ $conflicts = $this->scheduler->get_conflicts( - $data['starttime'], $data['starttime'] + $data['duration'] * 60, - $data['teacherid'], 0, SCHEDULER_ALL, $this->slotid); + $data['starttime'], + $data['starttime'] + $data['duration'] * 60, + $data['teacherid'], + 0, + SCHEDULER_ALL, + $this->slotid + ); if (count($conflicts) > 0) { - $cl = new scheduler_conflict_list(); $cl->add_conflicts($conflicts); @@ -371,6 +413,7 @@ public function validation($data, $files) { $errors['starttime'] = $msg; } } + return $errors; } @@ -387,8 +430,15 @@ public function prepare_formdata(slot $slot) { $data = $slot->get_data(); $data->exclusivityenable = ($data->exclusivity > 0); - $data = file_prepare_standard_editor($data, "notes", $this->noteoptions, $context, - 'mod_scheduler', 'slotnote', $slot->id); + $data = file_prepare_standard_editor( + $data, + "notes", + $this->noteoptions, + $context, + 'mod_scheduler', + 'slotnote', + $slot->id + ); $data->notes = []; $data->notes['text'] = $slot->notes; $data->notes['format'] = $slot->notesformat; @@ -404,17 +454,29 @@ public function prepare_formdata(slot $slot) { $data->attended[$i] = $appointment->attended; $draftid = file_get_submitted_draft_itemid('appointmentnote'); - $currenttext = file_prepare_draft_area($draftid, $context->id, - 'mod_scheduler', 'appointmentnote', $appointment->id, - $this->noteoptions, $appointment->appointmentnote); + $currenttext = file_prepare_draft_area( + $draftid, + $context->id, + 'mod_scheduler', + 'appointmentnote', + $appointment->id, + $this->noteoptions, + $appointment->appointmentnote + ); $data->appointmentnote_editor[$i] = ['text' => $currenttext, 'format' => $appointment->appointmentnoteformat, 'itemid' => $draftid, ]; $draftid = file_get_submitted_draft_itemid('teachernote'); - $currenttext = file_prepare_draft_area($draftid, $context->id, - 'mod_scheduler', 'teachernote', $appointment->id, - $this->noteoptions, $appointment->teachernote); + $currenttext = file_prepare_draft_area( + $draftid, + $context->id, + 'mod_scheduler', + 'teachernote', + $appointment->id, + $this->noteoptions, + $appointment->teachernote + ); $data->teachernote_editor[$i] = ['text' => $currenttext, 'format' => $appointment->teachernoteformat, 'itemid' => $draftid, ]; @@ -457,8 +519,15 @@ public function save_slot($slotid, $data) { } $editor = $data->notes_editor; - $slot->notes = file_save_draft_area_files($editor['itemid'], $context->id, 'mod_scheduler', 'slotnote', $slotid, - $this->noteoptions, $editor['text']); + $slot->notes = file_save_draft_area_files( + $editor['itemid'], + $context->id, + 'mod_scheduler', + 'slotnote', + $slotid, + $this->noteoptions, + $editor['text'] + ); $slot->notesformat = $editor['format']; $currentapps = $slot->get_appointments(); @@ -478,6 +547,7 @@ public function save_slot($slotid, $data) { $app->timecreated = time(); $app->save(); } + $app->attended = isset($data->attended[$i]); if (isset($data->grade)) { @@ -487,16 +557,29 @@ public function save_slot($slotid, $data) { if ($this->scheduler->uses_appointmentnotes()) { $editor = $data->appointmentnote_editor[$i]; - $app->appointmentnote = file_save_draft_area_files($editor['itemid'], $context->id, - 'mod_scheduler', 'appointmentnote', $app->id, - $this->noteoptions, $editor['text']); + $app->appointmentnote = file_save_draft_area_files( + $editor['itemid'], + $context->id, + 'mod_scheduler', + 'appointmentnote', + $app->id, + $this->noteoptions, + $editor['text'] + ); $app->appointmentnoteformat = $editor['format']; } + if ($this->scheduler->uses_teachernotes()) { $editor = $data->teachernote_editor[$i]; - $app->teachernote = file_save_draft_area_files($editor['itemid'], $context->id, - 'mod_scheduler', 'teachernote', $app->id, - $this->noteoptions, $editor['text']); + $app->teachernote = file_save_draft_area_files( + $editor['itemid'], + $context->id, + 'mod_scheduler', + 'teachernote', + $app->id, + $this->noteoptions, + $editor['text'] + ); $app->teachernoteformat = $editor['format']; } } @@ -518,7 +601,6 @@ public function save_slot($slotid, $data) { * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class scheduler_addsession_form extends scheduler_slotform_base { - /** * Form definition */ @@ -532,8 +614,12 @@ protected function definition() { $mform->addElement('date_selector', 'rangestart', get_string('date', 'scheduler')); $mform->setDefault('rangestart', time()); - $mform->addElement('date_selector', 'rangeend', get_string('enddate', 'scheduler'), - ['optional' => true] ); + $mform->addElement( + 'date_selector', + 'rangeend', + get_string('enddate', 'scheduler'), + ['optional' => true] + ); // Weekdays selection. $checkboxes = []; @@ -542,6 +628,7 @@ protected function definition() { $checkboxes[] = $mform->createElement('advcheckbox', $day, '', get_string($day, 'scheduler')); $mform->setDefault($day, true); } + $checkboxes[] = $mform->createElement('advcheckbox', 'saturday', '', get_string('saturday', 'scheduler')); $checkboxes[] = $mform->createElement('advcheckbox', 'sunday', '', get_string('sunday', 'scheduler')); $mform->addGroup($checkboxes, 'weekdays', get_string('addondays', 'scheduler'), null, false); @@ -552,9 +639,11 @@ protected function definition() { for ($i = 0; $i <= 23; $i++) { $hours[$i] = sprintf("%02d", $i); } + for ($i = 0; $i < 60; $i += 5) { $minutes[$i] = sprintf("%02d", $i); } + $timegroup = []; if (right_to_left()) { $timegroup[] = $mform->createElement('static', 'timefrom', '', get_string('timefrom', 'scheduler')); @@ -571,6 +660,7 @@ protected function definition() { $timegroup[] = $mform->createElement('select', 'endhour', get_string('hour', 'form'), $hours); $timegroup[] = $mform->createElement('select', 'endminute', get_string('minute', 'form'), $minutes); } + $mform->addGroup($timegroup, 'timerange', get_string('timerange', 'scheduler'), null, false); // Divide into slots? @@ -599,10 +689,12 @@ protected function definition() { for ($i = 2; $i < 7; $i++) { $hideuntilsel[DAYSECS * $i] = get_string('xdaysbefore', 'scheduler', $i); } + $hideuntilsel[WEEKSECS] = get_string('oneweekbefore', 'scheduler'); for ($i = 2; $i < 7; $i++) { $hideuntilsel[WEEKSECS * $i] = get_string('xweeksbefore', 'scheduler', $i); } + $mform->addElement('select', 'hideuntilrel', get_string('displayfrom', 'scheduler'), $hideuntilsel); $mform->setDefault('hideuntilsel', 0); @@ -614,6 +706,7 @@ protected function definition() { for ($i = 2; $i < 7; $i++) { $remindersel[DAYSECS * $i] = get_string('xdaysbefore', 'scheduler', $i); } + $remindersel[WEEKSECS] = get_string('oneweekbefore', 'scheduler'); for ($i = 2; $i < 7; $i++) { $remindersel[WEEKSECS * $i] = get_string('xweeksbefore', 'scheduler', $i); @@ -623,7 +716,6 @@ protected function definition() { $mform->setDefault('remindersel', -1); $this->add_action_buttons(); - } /** diff --git a/studentview.controller.php b/studentview.controller.php index 0dac87e8..2cab25e7 100644 --- a/studentview.controller.php +++ b/studentview.controller.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php'); +require_once($CFG->dirroot . '/mod/scheduler/mailtemplatelib.php'); /** * scheduler_book_slot @@ -57,6 +57,7 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo if (!$scheduler->is_group_scheduling_enabled()) { throw new moodle_exception('error'); } + $groupmembers = $scheduler->get_available_students($groupid); $requiredcapacity = count($groupmembers); $userstobook = array_keys($groupmembers); @@ -80,6 +81,7 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo foreach ($slot->get_appointments() as $app) { $existingstudents[] = $app->studentid; } + $userstobook = array_diff($userstobook, $existingstudents); $remaining = $slot->count_remaining_appointments(); @@ -117,26 +119,35 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo if ($scheduler->allownotifications) { $student = $DB->get_record('user', ['id' => $appointment->studentid], '*', MUST_EXIST); $teacher = $DB->get_record('user', ['id' => $slot->teacherid], '*', MUST_EXIST); - scheduler_messenger::send_slot_notification($slot, 'bookingnotification', 'applied', - $student, $teacher, $teacher, $student, $COURSE); + scheduler_messenger::send_slot_notification( + $slot, + 'bookingnotification', + 'applied', + $student, + $teacher, + $teacher, + $student, + $COURSE + ); } } + $slot->save(); redirect($returnurl); - } $returnurlparas = ['id' => $cm->id]; if ($scheduler->is_group_scheduling_enabled()) { $returnurlparas['appointgroup'] = $appointgroup; } + $returnurl = new moodle_url('/mod/scheduler/view.php', $returnurlparas); /******************************************** Show the booking form *******************************************/ if ($action == 'bookingform') { - require_once($CFG->dirroot.'/mod/scheduler/bookingform.php'); + require_once($CFG->dirroot . '/mod/scheduler/bookingform.php'); require_sesskey(); require_capability('mod/scheduler:appoint', $context); @@ -171,13 +182,11 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo echo $output->footer(); exit(); } - } /************************************************ Book a slot ************************************************/ if ($action == 'bookslot') { - require_sesskey(); require_capability('mod/scheduler:appoint', $context); @@ -195,13 +204,13 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo /******************************************** Show details of booking *******************************************/ if ($action == 'viewbooking') { - require_once($CFG->dirroot.'/mod/scheduler/bookingform.php'); + require_once($CFG->dirroot . '/mod/scheduler/bookingform.php'); require_sesskey(); require_capability('mod/scheduler:appoint', $context); $appointmentid = required_param('appointmentid', PARAM_INT); - list($slot, $appointment) = $scheduler->get_slot_appointment($appointmentid); + [$slot, $appointment] = $scheduler->get_slot_appointment($appointmentid); if ($appointment->studentid != $USER->id) { throw new moodle_exception('nopermissions'); @@ -215,13 +224,12 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo echo $output->continue_button($returnurl); echo $output->footer(); exit(); - } /******************************************** Edit a booking *******************************************/ if ($action == 'editbooking') { - require_once($CFG->dirroot.'/mod/scheduler/bookingform.php'); + require_once($CFG->dirroot . '/mod/scheduler/bookingform.php'); require_sesskey(); require_capability('mod/scheduler:appoint', $context); @@ -231,11 +239,12 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo } $appointmentid = required_param('appointmentid', PARAM_INT); - list($slot, $appointment) = $scheduler->get_slot_appointment($appointmentid); + [$slot, $appointment] = $scheduler->get_slot_appointment($appointmentid); if ($appointment->studentid != $USER->id) { throw new moodle_exception('nopermissions'); } + if (!$slot->is_in_bookable_period()) { throw new moodle_exception('nopermissions'); } @@ -260,14 +269,12 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo echo $output->footer(); exit(); } - } /******************************** Cancel a booking (for the current student or a group) ******************************/ if ($action == 'cancelbooking') { - require_sesskey(); require_capability('mod/scheduler:appoint', $context); @@ -295,12 +302,21 @@ function scheduler_book_slot($scheduler, $slotid, $userid, $groupid, $mform, $fo if ($scheduler->allownotifications) { $student = $DB->get_record('user', ['id' => $USER->id]); $teacher = $DB->get_record('user', ['id' => $slot->teacherid]); - scheduler_messenger::send_slot_notification($slot, 'bookingnotification', 'cancelled', - $student, $teacher, $teacher, $student, $COURSE); + scheduler_messenger::send_slot_notification( + $slot, + 'bookingnotification', + 'cancelled', + $student, + $teacher, + $teacher, + $student, + $COURSE + ); } + \mod_scheduler\event\booking_removed::create_from_slot($slot)->trigger(); } } - redirect($returnurl); + redirect($returnurl); } diff --git a/studentview.php b/studentview.php index 0b9b28d6..8721c44f 100644 --- a/studentview.php +++ b/studentview.php @@ -37,6 +37,7 @@ if ($appointgroup >= 0) { $urlparas['appointgroup'] = $appointgroup; } + $actionurl = new moodle_url('/mod/scheduler/view.php', $urlparas); @@ -59,7 +60,7 @@ } -require_once($CFG->dirroot.'/mod/scheduler/studentview.controller.php'); +require_once($CFG->dirroot . '/mod/scheduler/studentview.controller.php'); echo $output->header(); @@ -72,13 +73,16 @@ $showowngrades = !$gradebookinfo->hidden; - if ($gradebookinfo && !$gradebookinfo->hidden && ($totalgrade || $gradebookinfo->overridden) ) { + if ($gradebookinfo && !$gradebookinfo->hidden && ($totalgrade || $gradebookinfo->overridden)) { $grademsg = ''; if ($gradebookinfo->overridden) { - $grademsg = html_writer::tag('p', - get_string('overriddennotice', 'grades'), ['class' => 'overriddennotice'] - ); + $grademsg = html_writer::tag( + 'p', + get_string('overriddennotice', 'grades'), + ['class' => 'overriddennotice'] + ); } + $grademsg .= get_string('yourtotalgrade', 'scheduler', $gradebookinfo->str_grade); echo html_writer::div($grademsg, 'totalgrade'); } @@ -90,11 +94,19 @@ if ($scheduler->is_individual_scheduling_enabled()) { $groupchoice[0] = get_string('myself', 'scheduler'); } + foreach ($mygroupsforscheduling as $group) { $groupchoice[$group->id] = $group->name; } - $select = $output->single_select($actionurl, 'appointgroup', $groupchoice, $appointgroup, - [-1 => 'choosedots'], 'appointgroupform'); + + $select = $output->single_select( + $actionurl, + 'appointgroup', + $groupchoice, + $appointgroup, + [-1 => 'choosedots'], + 'appointgroupform' + ); echo html_writer::div(get_string('appointforgroup', 'scheduler', $select), 'dropdownmenu'); } @@ -117,6 +129,7 @@ } else { $others = null; } + $hasdetails = $scheduler->uses_studentdata(); $slottable->add_slot($pastslot, $appointment, $others, false, false, $hasdetails); } @@ -152,6 +165,7 @@ if ($scheduler->is_group_scheduling_enabled()) { $cancancel = $cancancel && ($appointgroup >= 0); } + $slottable->add_slot($slot, $appointment, $others, $cancancel, $canedit, $canview); } @@ -164,13 +178,10 @@ if (!$canseefull && $bookablecnt == 0) { echo html_writer::div(get_string('canbooknofurtherappointments', 'scheduler'), 'studentbookingmessage'); - } else if (count($bookableslots) == 0) { - // No slots are available at this time. $noslots = get_string('noslotsavailable', 'scheduler'); echo html_writer::div($noslots, 'studentbookingmessage'); - } else { // The student can book (or see) further appointments, and slots are available. // Show the booking form. @@ -194,6 +205,7 @@ foreach ($slot->get_appointments() as $otherapp) { $others->add_student($otherapp, $otherapp->studentid == $USER->id); } + $others->expandable = true; $others->expanded = false; } else { @@ -208,7 +220,7 @@ $groupinfo = get_string('no'); } else { if ($remaining > 0) { - $groupinfo = get_string('limited', 'scheduler', $remaining.'/'.$slot->exclusivity); + $groupinfo = get_string('limited', 'scheduler', $remaining . '/' . $slot->exclusivity); } else { // Group info should not be visible to students. $groupinfo = get_string('complete', 'scheduler'); $canbookthisslot = false; @@ -232,6 +244,7 @@ } else { $msgkey = 'canbookunlimitedappointments'; } + $bookingmsg2 = get_string($msgkey, 'scheduler', $a); echo $output->heading(get_string('availableslots', 'scheduler'), 3); @@ -239,14 +252,15 @@ echo html_writer::div($bookingmsg1, 'studentbookingmessage'); echo html_writer::div($bookingmsg2, 'studentbookingmessage'); } + if ($total > $pagesize) { echo $output->paging_bar($total, $offset, $pagesize, $actionurl, 'offset'); } + echo $output->render($booker); if ($total > $pagesize) { echo $output->paging_bar($total, $offset, $pagesize, $actionurl, 'offset'); } - } echo $output->footer(); diff --git a/teacherview.controller.php b/teacherview.controller.php index 37f02619..affe6016 100644 --- a/teacherview.controller.php +++ b/teacherview.controller.php @@ -56,47 +56,68 @@ function scheduler_action_doaddsession($scheduler, $formdata, moodle_url $return } else { $slot->duration = max(1, $data->endhour * 60 + $data->endminute - $data->starthour * 60 - $data->startminute); } + $slot->notes = ''; $slot->notesformat = FORMAT_HTML; $slot->timemodified = time(); - for ($d = 0; $d <= $fordays; $d ++) { + for ($d = 0; $d <= $fordays; $d++) { $starttime = $startfrom + ($d * DAYSECS); $eventdate = usergetdate($starttime); $dayofweek = $eventdate['wday']; - if ((($dayofweek == 1) && ($data->monday == 1)) || - (($dayofweek == 2) && ($data->tuesday == 1)) || - (($dayofweek == 3) && ($data->wednesday == 1)) || - (($dayofweek == 4) && ($data->thursday == 1)) || - (($dayofweek == 5) && ($data->friday == 1)) || - (($dayofweek == 6) && ($data->saturday == 1)) || - (($dayofweek == 0) && ($data->sunday == 1))) { - $slot->starttime = make_timestamp($eventdate['year'], $eventdate['mon'], $eventdate['mday'], - $data->starthour, $data->startminute); + if ( + (($dayofweek == 1) && ($data->monday == 1)) || + (($dayofweek == 2) && ($data->tuesday == 1)) || + (($dayofweek == 3) && ($data->wednesday == 1)) || + (($dayofweek == 4) && ($data->thursday == 1)) || + (($dayofweek == 5) && ($data->friday == 1)) || + (($dayofweek == 6) && ($data->saturday == 1)) || + (($dayofweek == 0) && ($data->sunday == 1)) + ) { + $slot->starttime = make_timestamp( + $eventdate['year'], + $eventdate['mon'], + $eventdate['mday'], + $data->starthour, + $data->startminute + ); $data->timestart = $slot->starttime; - $data->timeend = make_timestamp($eventdate['year'], $eventdate['mon'], $eventdate['mday'], - $data->endhour, $data->endminute); + $data->timeend = make_timestamp( + $eventdate['year'], + $eventdate['mon'], + $eventdate['mday'], + $data->endhour, + $data->endminute + ); // This corrects around midnight bug. if ($data->timestart > $data->timeend) { $data->timeend += DAYSECS; } + if ($data->hideuntilrel == 0) { $slot->hideuntil = time(); } else { $slot->hideuntil = make_timestamp($eventdate['year'], $eventdate['mon'], $eventdate['mday'], 6, 0) - $data->hideuntilrel; } + if ($data->emaildaterel == -1) { $slot->emaildate = 0; } else { $slot->emaildate = make_timestamp($eventdate['year'], $eventdate['mon'], $eventdate['mday'], 0, 0) - $data->emaildaterel; } + while ($slot->starttime <= $data->timeend - $slot->duration * 60) { - $conflicts = $scheduler->get_conflicts($data->timestart, $data->timestart + $slot->duration * 60, - $data->teacherid, 0, SCHEDULER_ALL); - $resolvable = (boolean) $data->forcewhenoverlap; + $conflicts = $scheduler->get_conflicts( + $data->timestart, + $data->timestart + $slot->duration * 60, + $data->teacherid, + 0, + SCHEDULER_ALL + ); + $resolvable = (bool) $data->forcewhenoverlap; foreach ($conflicts as $conflict) { $resolvable = $resolvable && $conflict->isself == 1 // Do not delete slots outside the current scheduler. @@ -117,18 +138,22 @@ function scheduler_action_doaddsession($scheduler, $formdata, moodle_url $return \mod_scheduler\event\slot_deleted::create_from_slot($cslot, 'addsession-conflict')->trigger(); $cslot->delete(); } + $conflictmsg .= get_string('deletedconflictingslots', 'scheduler', userdate($data->timestart)); $conflictmsg .= $output->doc_link('mod/scheduler/conflict', '', true); $conflictmsg .= $output->render($cl); } + \core\notification::warning($conflictmsg); } + if (!$conflicts || $resolvable) { $slotid = $DB->insert_record('scheduler_slots', $slot, true, true); $slotobj = $scheduler->get_slot($slotid); \mod_scheduler\event\slot_added::create_from_slot($slotobj)->trigger(); $countslots++; } + $slot->starttime += ($slot->duration + $data->break) * 60; $data->timestart += ($slot->duration + $data->break) * 60; } @@ -159,6 +184,7 @@ function scheduler_action_dosendmessage($scheduler, $formdata, $returnurl) { if ($data->copytomyself) { $recipients[$USER->id] = 1; } + $rawmessage = $data->body['text']; $format = $data->body['format']; $textmessage = format_text_email($rawmessage, $format); @@ -181,6 +207,7 @@ function scheduler_action_dosendmessage($scheduler, $formdata, $returnurl) { if ($htmlmessage) { $message->fullmessagehtml = $htmlmessage; } + $message->notification = '1'; message_send($message); @@ -214,6 +241,7 @@ function scheduler_action_delete_slots(array $slots, $action, moodle_url $return } else { $message = get_string('slotsdeleted', 'scheduler', $cnt); } + $messagetype = ($cnt > 0) ? \core\output\notification::NOTIFY_SUCCESS : \core\output\notification::NOTIFY_INFO; \core\notification::add($message, $messagetype); redirect($returnurl); @@ -244,6 +272,7 @@ function scheduler_action_delete_slots(array $slots, $action, moodle_url $return $slots[] = $slot; } } + scheduler_action_delete_slots($slots, $action, $viewurl); break; /************************************ Students were seen ***************************************************/ @@ -259,6 +288,7 @@ function scheduler_action_delete_slots(array $slots, $action, moodle_url $return $app->timemodified = time(); } } + $slot->save(); redirect($viewurl); break; @@ -273,16 +303,25 @@ function scheduler_action_delete_slots(array $slots, $action, moodle_url $return $oldstudents[] = $app->studentid; $slot->remove_appointment($app); } + // Notify the student. if ($scheduler->allownotifications) { foreach ($oldstudents as $oldstudent) { - include_once($CFG->dirroot.'/mod/scheduler/mailtemplatelib.php'); + include_once($CFG->dirroot . '/mod/scheduler/mailtemplatelib.php'); $student = $DB->get_record('user', ['id' => $oldstudent]); $teacher = $DB->get_record('user', ['id' => $slot->teacherid]); - scheduler_messenger::send_slot_notification($slot, 'bookingnotification', 'teachercancelled', - $teacher, $student, $teacher, $student, $COURSE); + scheduler_messenger::send_slot_notification( + $slot, + 'bookingnotification', + 'teachercancelled', + $teacher, + $student, + $teacher, + $student, + $COURSE + ); } } diff --git a/teacherview.php b/teacherview.php index a820f195..556fdaf3 100644 --- a/teacherview.php +++ b/teacherview.php @@ -51,8 +51,10 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $startdatemem = $startdatecnv; $starttimemem = $starttimecnv; - $url = new moodle_url('/mod/scheduler/view.php', - ['id' => $scheduler->cmid, 'slotid' => $slot->id, 'sesskey' => sesskey()]); + $url = new moodle_url( + '/mod/scheduler/view.php', + ['id' => $scheduler->cmid, 'slotid' => $slot->id, 'sesskey' => sesskey()] + ); if ($groupid) { $url->param('what', 'schedulegroup'); $url->param('subaction', 'dochooseslot'); @@ -62,6 +64,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $url->param('subaction', 'dochooseslot'); $url->param('studentid', $studentid); } + $availableslotsmenu[$url->out()] = "$startdatestr $starttimestr"; } @@ -92,12 +95,14 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid if (has_capability('moodle/site:accessallgroups', $context)) { $userfilter = 0; } + $groupsicansee = ''; $groupsicurrentlysee = ''; if ($groupmode) { if ($userfilter) { $groupsicansee = groups_get_all_groups($COURSE->id, $userfilter, $cm->groupingid); } + $groupsicurrentlysee = $groupsicansee; if ($currentgroup) { if ($userfilter && !groups_is_member($currentgroup, $userfilter)) { @@ -137,8 +142,8 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $PAGE->set_url($viewurl); if ($action != 'view') { - require_once($CFG->dirroot.'/mod/scheduler/slotforms.php'); - require_once($CFG->dirroot.'/mod/scheduler/teacherview.controller.php'); + require_once($CFG->dirroot . '/mod/scheduler/slotforms.php'); + require_once($CFG->dirroot . '/mod/scheduler/teacherview.controller.php'); } /************************************ View : New single slot form ****************************************/ @@ -158,10 +163,12 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid } else if ($formdata = $mform->get_data()) { $slot = $mform->save_slot(0, $formdata); \mod_scheduler\event\slot_added::create_from_slot($slot)->trigger(); - redirect($viewurl, - get_string('oneslotadded', 'scheduler'), - 0, - \core\output\notification::NOTIFY_SUCCESS); + redirect( + $viewurl, + get_string('oneslotadded', 'scheduler'), + 0, + \core\output\notification::NOTIFY_SUCCESS + ); } else { echo $output->header(); echo $output->heading(get_string('addsingleslot', 'scheduler')); @@ -170,9 +177,9 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid die; } } + /************************************ View : Update single slot form ****************************************/ if ($action == 'updateslot') { - $slotid = required_param('slotid', PARAM_INT); $slot = $scheduler->get_slot($slotid); $permissions->ensure($permissions->can_edit_slot($slot)); @@ -188,8 +195,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, [ 'slotid' => $slotid, - 'timeoptions' => $timeoptions, ] - ); + 'timeoptions' => $timeoptions, ]); $data = $mform->prepare_formdata($slot); $mform->set_data($data); @@ -197,10 +203,12 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid redirect($viewurl); } else if ($formdata = $mform->get_data()) { $mform->save_slot($slotid, $formdata); - redirect($viewurl, - get_string('slotupdated', 'scheduler'), - 0, - \core\output\notification::NOTIFY_SUCCESS); + redirect( + $viewurl, + get_string('slotupdated', 'scheduler'), + 0, + \core\output\notification::NOTIFY_SUCCESS + ); } else { echo $output->header(); echo $output->heading(get_string('updatesingleslot', 'scheduler')); @@ -208,11 +216,10 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid echo $output->footer($course); die; } - } + /************************************ Add session multiple slots form ****************************************/ if ($action == 'addsession') { - $permissions->ensure($permissions->can_edit_own_slots()); $actionurl = new moodle_url($baseurl, ['what' => 'addsession']); @@ -250,15 +257,19 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $actionurl = new moodle_url($baseurl, ['what' => 'updateslot', 'slotid' => $slotid]); $repeats = $slot->get_appointment_count() + 1; - $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, - ['slotid' => $slotid, 'repeats' => $repeats]); + $mform = new scheduler_editslot_form( + $actionurl, + $scheduler, + $cm, + $groupsicansee, + ['slotid' => $slotid, 'repeats' => $repeats] + ); $data = $mform->prepare_formdata($slot); $data->studentid[] = $studentid; $mform->set_data($data); echo $output->heading(get_string('updatesingleslot', 'scheduler'), 2); $mform->display(); - } else if (empty($subaction)) { $studentid = required_param('studentid', PARAM_INT); $student = $DB->get_record('user', ['id' => $studentid], '*', MUST_EXIST); @@ -284,9 +295,9 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid echo $output->footer(); die(); } + /************************************ Schedule a whole group in form ***********************************************/ if ($action == 'schedulegroup') { - $permissions->ensure($permissions->can_edit_own_slots()); $groupid = required_param('groupid', PARAM_INT); @@ -296,7 +307,6 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid echo $output->header(); if ($subaction == 'dochooseslot') { - $slotid = required_param('slotid', PARAM_INT); $groupid = required_param('groupid', PARAM_INT); $slot = $scheduler->get_slot($slotid); @@ -304,19 +314,23 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $actionurl = new moodle_url($baseurl, ['what' => 'updateslot', 'slotid' => $slotid]); $repeats = $slot->get_appointment_count() + count($members); - $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, - ['slotid' => $slotid, 'repeats' => $repeats]); + $mform = new scheduler_editslot_form( + $actionurl, + $scheduler, + $cm, + $groupsicansee, + ['slotid' => $slotid, 'repeats' => $repeats] + ); $data = $mform->prepare_formdata($slot); foreach ($members as $member) { $data->studentid[] = $member->id; } + $mform->set_data($data); echo $output->heading(get_string('updatesingleslot', 'scheduler'), 3); $mform->display(); - } else if (empty($subaction)) { - $actionurl = new moodle_url($baseurl, ['what' => 'addslot']); $data = []; @@ -325,6 +339,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $data['studentid'][$i] = $member->id; $i++; } + $data['exclusivity'] = $i; $mform = new scheduler_editslot_form($actionurl, $scheduler, $cm, $groupsicansee, ['repeats' => $i]); @@ -338,8 +353,8 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid echo $output->heading(get_string('scheduleinnew', 'scheduler'), 3); $mform->display(); echo $output->box_end(); - } + echo $output->footer(); die(); } @@ -348,14 +363,18 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid if ($action == 'sendmessage') { $permissions->ensure($permissions->can_edit_own_slots()); - require_once($CFG->dirroot.'/mod/scheduler/message_form.php'); + require_once($CFG->dirroot . '/mod/scheduler/message_form.php'); $template = optional_param('template', 'none', PARAM_ALPHA); $recipientids = required_param('recipients', PARAM_SEQUENCE); - $actionurl = new moodle_url('/mod/scheduler/view.php', - ['what' => 'sendmessage', 'id' => $cm->id, 'subpage' => $subpage, - 'template' => $template, 'recipients' => $recipientids, ]); + $actionurl = new moodle_url( + '/mod/scheduler/view.php', + ['what' => 'sendmessage', 'id' => $cm->id, 'subpage' => $subpage, + 'template' => $template, + 'recipients' => $recipientids, + ] + ); $templatedata = []; if ($template != 'none') { @@ -363,6 +382,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $templatedata['subject'] = scheduler_messenger::compile_mail_template($template, 'subject', $vars); $templatedata['body'] = scheduler_messenger::compile_mail_template($template, 'html', $vars); } + $templatedata['recipients'] = $DB->get_records_list('user', 'id', explode(',', $recipientids), 'lastname,firstname'); $mform = new scheduler_message_form($actionurl, $scheduler, $templatedata); @@ -393,8 +413,10 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $actionurl = new moodle_url($viewurl, ['sesskey' => sesskey()]); $inactive = []; -if ($DB->count_records('scheduler_slots', ['schedulerid' => $scheduler->id]) <= - $DB->count_records('scheduler_slots', ['schedulerid' => $scheduler->id, 'teacherid' => $USER->id]) ) { +if ( + $DB->count_records('scheduler_slots', ['schedulerid' => $scheduler->id]) <= + $DB->count_records('scheduler_slots', ['schedulerid' => $scheduler->id, 'teacherid' => $USER->id]) +) { // We are alone in this scheduler. $inactive[] = 'allappointments'; if ($subpage = 'allappointments') { @@ -415,6 +437,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid foreach ($groupsthatcanseeme as $id => $group) { $groupnames[] = $group->name; } + $a->grouplist = implode(', ', $groupnames); $messagekey = $groupsthatcanseeme ? 'groupmodeyourgroups' : 'groupmodeyourgroupsempty'; $message = get_string($messagekey, 'scheduler', $a); @@ -431,6 +454,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $slotgroup = 0; $subpage = 'myappointments'; } + $sqlcount = $scheduler->count_slots_for_teacher($teacherid, $slotgroup); $pagesize = 25; @@ -442,6 +466,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $offset = 0; } } + if ($offset * $pagesize >= $sqlcount && $sqlcount > 0) { $offset = floor(($sqlcount - 1) / $pagesize); } @@ -469,24 +494,42 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $delselectedurl = new moodle_url($actionurl, ['what' => 'deleteslots']); $PAGE->requires->js_call_amd('mod_scheduler/delselected', 'init', [$delselectedurl->out(false)]); - $delselected = $commandbar->action_menu_link($delselectedurl, 'deleteselection', 't/delete', - 'confirmdelete-selected', 'delselected'); + $delselected = $commandbar->action_menu_link( + $delselectedurl, + 'deleteselection', + 't/delete', + 'confirmdelete-selected', + 'delselected' + ); $delbuttons[] = $delselected; if ($permissions->can_edit_all_slots() && $subpage == 'allappointments') { $delbuttons[] = $commandbar->action_menu_link( - new moodle_url($actionurl, ['what' => 'deleteall']), - 'deleteallslots', 't/delete', 'confirmdelete-all'); + new moodle_url($actionurl, ['what' => 'deleteall']), + 'deleteallslots', + 't/delete', + 'confirmdelete-all' + ); $delbuttons[] = $commandbar->action_menu_link( - new moodle_url($actionurl, ['what' => 'deleteallunused']), - 'deleteallunusedslots', 't/delete', 'confirmdelete-unused'); + new moodle_url($actionurl, ['what' => 'deleteallunused']), + 'deleteallunusedslots', + 't/delete', + 'confirmdelete-unused' + ); } + $delbuttons[] = $commandbar->action_menu_link( - new moodle_url($actionurl, ['what' => 'deleteunused']), - 'deleteunusedslots', 't/delete', 'confirmdelete-myunused'); + new moodle_url($actionurl, ['what' => 'deleteunused']), + 'deleteunusedslots', + 't/delete', + 'confirmdelete-myunused' + ); $delbuttons[] = $commandbar->action_menu_link( - new moodle_url($actionurl, ['what' => 'deleteonlymine']), - 'deletemyslots', 't/delete', 'confirmdelete-mine'); + new moodle_url($actionurl, ['what' => 'deleteonlymine']), + 'deletemyslots', + 't/delete', + 'confirmdelete-mine' + ); $commandbar->add_group(get_string('deletecommands', 'scheduler'), $delbuttons); } @@ -496,12 +539,10 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid // Some slots already exist - prepare the table of slots. if ($slots) { - $slotman = new scheduler_slot_manager($scheduler, $actionurl); $slotman->showteacher = ($subpage == 'allappointments'); foreach ($slots as $slot) { - $editable = $permissions->can_edit_slot($slot); $studlist = new scheduler_student_list($slotman->scheduler); @@ -513,8 +554,14 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $studlist->buttontext = get_string('saveseen', 'scheduler'); $studlist->actionurl = new moodle_url($actionurl, ['what' => 'saveseen', 'slotid' => $slot->id]); foreach ($slot->get_appointments() as $app) { - $studlist->add_student($app, false, $app->is_attended(), true, $scheduler->uses_studentdata(), - $permissions->can_edit_attended($app)); + $studlist->add_student( + $app, + false, + $app->is_attended(), + true, + $scheduler->uses_studentdata(), + $permissions->can_edit_attended($app) + ); } $slotman->add_slot($slot, $studlist, $editable); @@ -528,7 +575,6 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid // Instruction for teacher to click Seen box after appointment. echo html_writer::div(get_string('markseen', 'scheduler')); - } $groupfilter = ($subpage == 'myappointments') ? $groupsthatcanseeme : $groupsicurrentlysee; @@ -554,16 +600,15 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid if ($students === 0) { $nostudentstr = get_string('noexistingstudents', 'scheduler'); if ($COURSE->id == SITEID) { - $nostudentstr .= '
'.get_string('howtoaddstudents', 'scheduler'); + $nostudentstr .= '
' . get_string('howtoaddstudents', 'scheduler'); } + echo $output->notification($nostudentstr, 'notifyproblem'); } else if (is_integer($students)) { // There are too many students who still have to make appointments, don't display a list. $toomanystr = get_string('missingstudentsmany', 'scheduler', $students); echo $output->notification($toomanystr, 'notifymessage'); - } else if (count($students) > 0) { - if (count($reminderstudents) > 0) { $studids = implode(',', array_keys($reminderstudents)); @@ -589,6 +634,7 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid foreach ($userfields as $f) { $fieldtitles[] = $f->title; } + $studtable = new scheduler_scheduling_list($scheduler, $fieldtitles); $studtable->id = 'studentstoschedule'; @@ -597,23 +643,26 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $name = $output->user_profile_link($scheduler, $student); $actions = []; $actions[] = new action_menu_link_secondary( - new moodle_url($actionurl, ['what' => 'schedule', 'studentid' => $student->id]), - new pix_icon('e/insert_date', '', 'moodle'), - get_string('scheduleinslot', 'scheduler') ); + new moodle_url($actionurl, ['what' => 'schedule', 'studentid' => $student->id]), + new pix_icon('e/insert_date', '', 'moodle'), + get_string('scheduleinslot', 'scheduler') + ); $actions[] = new action_menu_link_secondary( - new moodle_url($actionurl, ['what' => 'markasseennow', 'studentid' => $student->id]), - new pix_icon('t/approve', '', 'moodle'), - get_string('markasseennow', 'scheduler') ); + new moodle_url($actionurl, ['what' => 'markasseennow', 'studentid' => $student->id]), + new pix_icon('t/approve', '', 'moodle'), + get_string('markasseennow', 'scheduler') + ); $userfields = scheduler_get_user_fields($student, $context); $fieldvals = []; foreach ($userfields as $f) { $fieldvals[] = $f->value; } + $studtable->add_line($picture, $name, $fieldvals, $actions); } - $divclass = 'schedulelist '.($scheduler->is_group_scheduling_enabled() ? 'halfsize' : 'fullsize'); + $divclass = 'schedulelist ' . ($scheduler->is_group_scheduling_enabled() ? 'halfsize' : 'fullsize'); echo html_writer::start_div($divclass); echo $output->heading(get_string('schedulestudents', 'scheduler'), 3); @@ -622,7 +671,6 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid echo html_writer::end_div(); if ($scheduler->is_group_scheduling_enabled()) { - // Print list of groups that can be scheduled. echo html_writer::start_div('schedulelist halfsize'); @@ -640,25 +688,28 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid if (empty($members)) { continue; } - if (!$scheduler->has_slots_booked_for_group($group->id, false, $scheduler->schedulermode == 'onetime')) { + if (!$scheduler->has_slots_booked_for_group($group->id, false, $scheduler->schedulermode == 'onetime')) { $picture = print_group_picture($group, $course->id, false, true, true); $name = $group->name; $groupmembers = []; foreach ($members as $member) { $groupmembers[] = fullname($member); } - $name .= ' ['. implode(', ', $groupmembers) . ']'; + + $name .= ' [' . implode(', ', $groupmembers) . ']'; $actions = []; $actions[] = new action_menu_link_secondary( - new moodle_url($actionurl, ['what' => 'schedulegroup', 'groupid' => $group->id]), - new pix_icon('e/insert_date', '', 'moodle'), - get_string('scheduleinslot', 'scheduler') ); + new moodle_url($actionurl, ['what' => 'schedulegroup', 'groupid' => $group->id]), + new pix_icon('e/insert_date', '', 'moodle'), + get_string('scheduleinslot', 'scheduler') + ); $grouptable->add_line($picture, $name, [], $actions); $groupcnt++; } } + // Print table of groups that still need to make appointments. if ($groupcnt > 0) { echo $output->render($grouptable); @@ -666,10 +717,11 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid echo $output->notification(get_string('nogroups', 'scheduler')); } } + echo html_writer::end_div(); } - } else { echo $output->notification(get_string('noexistingstudents', 'scheduler')); } + echo $output->footer(); diff --git a/templates/action_menu_trigger.mustache b/templates/action_menu_trigger.mustache index 877b84a2..e870891a 100644 --- a/templates/action_menu_trigger.mustache +++ b/templates/action_menu_trigger.mustache @@ -87,7 +87,7 @@ execute('behat_forms::i_set_the_following_fields_to_these_values', new TableNode($rows)); $this->execute('behat_general::i_click_on', ['Save changes', 'button']); @@ -93,8 +99,11 @@ public function i_add_a_slot_days_ahead_at_in_scheduler_and_i_fill_the_form_with * @param TableNode $fielddata */ public function i_add_slots_days_ahead_in_scheduler_and_i_fill_the_form_with( - $slotcount, $daysahead, $activityname, TableNode $fielddata) { - + $slotcount, + $daysahead, + $activityname, + TableNode $fielddata + ) { $startdate = time() + $daysahead * DAYSECS; $this->execute('behat_navigation::i_am_on_page_instance', [$this->escape($activityname), 'Activity']); @@ -118,7 +127,6 @@ public function i_add_slots_days_ahead_in_scheduler_and_i_fill_the_form_with( $this->execute('behat_forms::i_set_the_following_fields_to_these_values', new TableNode($rows)); $this->execute('behat_general::i_click_on', ['Save changes', 'button']); - } /** @@ -129,18 +137,24 @@ public function i_add_slots_days_ahead_in_scheduler_and_i_fill_the_form_with( * @Given /^I add the upcoming events block globally$/ */ public function i_add_the_upcoming_events_block_globally() { + global $CFG; + if ($CFG->version > 2026042000) { + // Moodle 5.2 onwards has "Home" not enabled by default. + set_config('enablemyhome', 1); + set_config('defaulthomepage', 1); + } $this->execute('behat_data_generators::the_following_entities_exist', ['users', new TableNode([ ['username', 'firstname', 'lastname', 'email'], ['globalmanager1', 'GlobalManager', '1', 'globalmanager1@example.com'], - ]), ] ); + ]), ]); $this->execute('behat_data_generators::the_following_entities_exist', ['system role assigns', new TableNode([ ['user', 'role'], ['globalmanager1', 'manager'], - ]), ] ); + ]), ]); $this->execute('behat_auth::i_log_in_as', 'globalmanager1'); $this->execute('behat_general::i_am_on_site_homepage'); @@ -151,10 +165,9 @@ public function i_add_the_upcoming_events_block_globally() { $this->execute('behat_general::click_link', 'Configure Upcoming events block'); $this->execute('behat_forms::i_set_the_following_fields_to_these_values', new TableNode([ ['Page contexts', 'Display throughout the entire site'], - ]) ); + ])); $this->execute('behat_general::i_click_on', ['Save changes', 'button']); $this->execute('behat_auth::i_log_out'); - } /** @@ -171,7 +184,7 @@ public function i_click_on_item_in_the_nth_autocomplete_list($item, $listnumber) $this->execute('behat_general::i_click_on', [$downarrowtarget, 'xpath_element']); $xpathtarget = "(//descendant::ul[@class='form-autocomplete-suggestions'][$listnumber]//" - ."*[contains(concat('|', string(.), '|'),'|$item|')])"; + . "*[contains(concat('|', string(.), '|'),'|$item|')])"; $this->execute('behat_general::i_click_on', [$xpathtarget, 'xpath_element']); } } diff --git a/tests/behat/grades.feature b/tests/behat/grades.feature index 06fa1954..d52f6e2f 100644 --- a/tests/behat/grades.feature +++ b/tests/behat/grades.feature @@ -166,7 +166,7 @@ Feature: Teachers can grade student appointments with totals automatically compu And I expand all fieldsets And I set the field "Grading strategy" to "Take the highest grade" And I press "Save and display" - And I click on "Edit" "icon" in the "3:00 AM" "table_row" + And I click on "//table[@id='slotmanager']//tr[1]//td[contains(@class,'lastcol')]//a[@aria-label='Edit']" "xpath_element" And I set the following fields to these values: | grade[0] | 5 | And I click on "Save" "button" @@ -175,7 +175,7 @@ Feature: Teachers can grade student appointments with totals automatically compu And I should see "5.00" in the "div.totalgrade" "css_element" When I am on the "scheduler1" Activity page logged in as "teacher1" - And I click on "Edit" "icon" in the "4:00 AM" "table_row" + And I click on "//table[@id='slotmanager']//tr[2]//td[contains(@class,'lastcol')]//a[@aria-label='Edit']" "xpath_element" And I set the following fields to these values: | grade[0] | 7 | And I click on "Save" "button" @@ -185,7 +185,7 @@ Feature: Teachers can grade student appointments with totals automatically compu And I should see "7.00" in the "div.totalgrade" "css_element" When I am on the "scheduler1" Activity page logged in as "teacher1" - And I click on "Edit" "icon" in the "4:00 AM" "table_row" + And I click on "//table[@id='slotmanager']//tr[2]//td[contains(@class,'lastcol')]//a[@aria-label='Edit']" "xpath_element" And I set the following fields to these values: | grade[0] | 2 | And I click on "Save" "button" @@ -195,7 +195,7 @@ Feature: Teachers can grade student appointments with totals automatically compu And I should see "5.00" in the "div.totalgrade" "css_element" When I am on the "scheduler1" Activity page logged in as "teacher1" - And I click on "Edit" "icon" in the "3:00 AM" "table_row" + And I click on "//table[@id='slotmanager']//tr[1]//td[contains(@class,'lastcol')]//a[@aria-label='Edit']" "xpath_element" And I set the following fields to these values: | grade[0] | No grade | And I click on "Save" "button" diff --git a/tests/generator/behat_mod_scheduler_generator.php b/tests/generator/behat_mod_scheduler_generator.php index 19ec172e..5d906f69 100644 --- a/tests/generator/behat_mod_scheduler_generator.php +++ b/tests/generator/behat_mod_scheduler_generator.php @@ -22,8 +22,8 @@ * @copyright 2022 Henning Bostelmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class behat_mod_scheduler_generator extends behat_generator_base { - +class behat_mod_scheduler_generator extends behat_generator_base +{ /** * Get a list of the entities that Behat can create using the generator step. * @@ -73,5 +73,4 @@ protected function get_student_id(string $idnumber): int { return 0; } } - } diff --git a/tests/generator/lib.php b/tests/generator/lib.php index de51a153..785b1fb6 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -29,8 +29,8 @@ * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_scheduler_generator extends testing_module_generator { - +class mod_scheduler_generator extends testing_module_generator +{ /** * set default * @@ -64,8 +64,9 @@ public function create_instance($record = null, ?array $options = null) { if (empty($record->course)) { throw new coding_exception('module generator requires $record->course'); } - self::set_default($record, 'name', get_string('pluginname', 'scheduler').' '.$i); - self::set_default($record, 'intro', 'Test scheduler '.$i); + + self::set_default($record, 'name', get_string('pluginname', 'scheduler') . ' ' . $i); + self::set_default($record, 'intro', 'Test scheduler ' . $i); self::set_default($record, 'introformat', FORMAT_MOODLE); self::set_default($record, 'schedulermode', 'onetime'); self::set_default($record, 'guardtime', 0); @@ -147,5 +148,4 @@ public function create_slot(array $data): void { $slot->save(); } - } diff --git a/tests/model_test.php b/tests/model_test.php index d18428b4..7ea48831 100644 --- a/tests/model_test.php +++ b/tests/model_test.php @@ -39,8 +39,8 @@ * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -final class model_test extends \advanced_testcase { - +final class model_test extends \advanced_testcase +{ /** * @var int Course_modules id used for testing */ @@ -75,6 +75,7 @@ protected function setUp(): void { $options['slottimes'][$c] = time() + ($c + 1) * DAYSECS; $options['slotstudents'][$c] = [$this->getDataGenerator()->create_user()->id]; } + $options['slottimes'][4] = time() + 10 * DAYSECS; $options['slottimes'][5] = time() + 11 * DAYSECS; $options['slotstudents'][5] = [ @@ -103,8 +104,7 @@ public function test_scheduler(): void { $instance = scheduler::load_by_coursemodule_id($this->moduleid); - $this->assertEquals( $dbdata->name, $instance->get_name()); - + $this->assertEquals($dbdata->name, $instance->get_name()); } /** @@ -150,7 +150,5 @@ public function test_appointment(): void { $this->assertEquals(fullname($user), fullname($appobj->get_student())); $this->assertTrue($appobj->is_attended()); $this->assertEquals(-7, $appobj->grade); - } - } diff --git a/tests/permissions_test.php b/tests/permissions_test.php index ed61fe03..b599ad23 100644 --- a/tests/permissions_test.php +++ b/tests/permissions_test.php @@ -40,8 +40,8 @@ * @copyright 2019 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -final class permissions_test extends \advanced_testcase { - +final class permissions_test extends \advanced_testcase +{ /** * @var int Course_modules id used for testing */ @@ -167,7 +167,7 @@ public function test_teacher_can_see_slot(): void { // Nonediting teacher sees only his own slot. $p = new scheduler_permissions($this->context, $this->nonedteacher); $this->assertFalse($p->teacher_can_see_slot($this->slots[0])); - $this->assertTrue ($p->teacher_can_see_slot($this->slots[1])); + $this->assertTrue($p->teacher_can_see_slot($this->slots[1])); $this->assertFalse($p->teacher_can_see_slot($this->slots[2])); // Adminstrator sees all slots. @@ -181,7 +181,6 @@ public function test_teacher_can_see_slot(): void { $this->assertFalse($p->teacher_can_see_slot($this->slots[0])); $this->assertFalse($p->teacher_can_see_slot($this->slots[1])); $this->assertFalse($p->teacher_can_see_slot($this->slots[2])); - } /** @@ -200,7 +199,7 @@ public function test_can_edit_slot(): void { // Nonediting teacher can only edit his own slot. $p = new scheduler_permissions($this->context, $this->nonedteacher); $this->assertFalse($p->can_edit_slot($this->slots[0])); - $this->assertTrue ($p->can_edit_slot($this->slots[1])); + $this->assertTrue($p->can_edit_slot($this->slots[1])); $this->assertFalse($p->can_edit_slot($this->slots[2])); // Adminstrator cannot edit any slots. @@ -214,7 +213,6 @@ public function test_can_edit_slot(): void { $this->assertFalse($p->can_edit_slot($this->slots[0])); $this->assertFalse($p->can_edit_slot($this->slots[1])); $this->assertFalse($p->can_edit_slot($this->slots[2])); - } /** @@ -235,7 +233,6 @@ public function test_can_edit_own_slots(): void { $this->assertFalse($p->can_edit_own_slots()); $p = new scheduler_permissions($this->context, $this->students[1]); $this->assertFalse($p->can_edit_own_slots()); - } /** @@ -256,7 +253,6 @@ public function test_can_edit_all_slots(): void { $this->assertFalse($p->can_edit_all_slots()); $p = new scheduler_permissions($this->context, $this->students[1]); $this->assertFalse($p->can_edit_all_slots()); - } /** @@ -281,7 +277,6 @@ public function test_can_see_all_slots(): void { // Students cannot see all slots. $p = new scheduler_permissions($this->context, $this->students[1]); $this->assertFalse($p->can_see_all_slots()); - } /** @@ -300,7 +295,7 @@ public function test_can_see_appointment(): void { // Nonediting teacher can only see his own appointment. $p = new scheduler_permissions($this->context, $this->nonedteacher); $this->assertFalse($p->can_see_appointment($this->appts[0])); - $this->assertTrue ($p->can_see_appointment($this->appts[1])); + $this->assertTrue($p->can_see_appointment($this->appts[1])); $this->assertFalse($p->can_see_appointment($this->appts[2])); // Administrator can see all appointments. @@ -319,8 +314,5 @@ public function test_can_see_appointment(): void { $this->assertEquals($expected, $actual, $msg); } } - } - - } diff --git a/tests/privacy_test.php b/tests/privacy_test.php index 0c222ba0..03f097ac 100644 --- a/tests/privacy_test.php +++ b/tests/privacy_test.php @@ -36,7 +36,7 @@ use core_privacy\local\request\approved_userlist; use core_privacy\local\request\writer; -require_once($CFG->dirroot.'/mod/scheduler/locallib.php'); +require_once($CFG->dirroot . '/mod/scheduler/locallib.php'); /** * Data provider testcase class. @@ -45,8 +45,8 @@ * @copyright 2018 Henning Bostelmann * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -final class privacy_test extends provider_testcase { - +final class privacy_test extends provider_testcase +{ /** * @var int course_module id used for testing */ @@ -114,6 +114,7 @@ protected function setUp(): void { $this->allstudents[] = $stud; $options['slotstudents'][$c] = [$stud]; } + $options['slottimes'][4] = time() + 10 * DAYSECS; $options['slottimes'][5] = time() + 11 * DAYSECS; $options['slotstudents'][5] = [ @@ -243,7 +244,6 @@ public function test_delete_data_for_user(): void { $this->assert_appointment_status($this->schedulerid, $this->student1->id, false); $this->assert_appointment_status($this->schedulerid, $this->student2->id, true); - } /** diff --git a/tests/scheduler_test.php b/tests/scheduler_test.php index 99e5067e..8cf646e3 100644 --- a/tests/scheduler_test.php +++ b/tests/scheduler_test.php @@ -40,8 +40,8 @@ * @copyright 2011 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -final class scheduler_test extends \advanced_testcase { - +final class scheduler_test extends \advanced_testcase +{ /** * @var int Course_module id used for testing */ @@ -83,6 +83,7 @@ protected function setUp(): void { $options['slottimes'][$c] = time() + ($c + 1) * DAYSECS; $options['slotstudents'][$c] = [$this->getDataGenerator()->create_user()->id]; } + $options['slottimes'][4] = time() + 10 * DAYSECS; $options['slottimes'][5] = time() + 11 * DAYSECS; $options['slotstudents'][5] = [ @@ -111,6 +112,7 @@ private function create_student($courseid = 0) { if ($courseid == 0) { $courseid = $this->courseid; } + $userid = $this->getDataGenerator()->create_user()->id; $this->getDataGenerator()->enrol_user($userid, $courseid); return $userid; @@ -144,7 +146,6 @@ public function test_scheduler(): void { $instance = scheduler::load_by_coursemodule_id($this->moduleid); $this->assertEquals($dbdata->name, $instance->get_name()); - } /** @@ -182,6 +183,7 @@ public function test_load_slots(): void { } else { $expectedapp = 1; } + $this->assertEquals($expectedapp, $slot->get_appointment_count()); $apps = $slot->get_appointments(); @@ -190,9 +192,9 @@ public function test_load_slots(): void { foreach ($apps as $app) { $this->assertTrue($app instanceof appointment); } + $cnt++; } - } /** @@ -213,7 +215,6 @@ public function test_add_slot(): void { $this->assertEquals(7, count($allslots)); $scheduler->save(); - } /** @@ -251,7 +252,6 @@ public function test_delete_scheduler(): void { $this->assert_record_count('scheduler', 'id', $delid, 0); $this->assert_record_count('scheduler_slots', 'schedulerid', $delid, 0); - } /** @@ -267,8 +267,9 @@ private function assert_slot_times($expected, $actual, $options, $message) { foreach ($expected as $e) { $slottimes[] = $options['slottimes'][$e]; } + foreach ($actual as $a) { - $this->assertTrue( in_array($a->starttime, $slottimes), "Slot at {$a->starttime} - $message"); + $this->assertTrue(in_array($a->starttime, $slottimes), "Slot at {$a->starttime} - $message"); } } @@ -283,9 +284,15 @@ private function assert_slot_times($expected, $actual, $options, $message) { * @param unknown $expavailable which slots are expected to be "available" (including already booked ones) * @param unknown $expbookable which slots are expected to be "bookable" */ - private function check_timed_slots($schedulerid, $studentid, $slotoptions, - $expattended, $expupcoming, $expavailable, $expbookable) { - + private function check_timed_slots( + $schedulerid, + $studentid, + $slotoptions, + $expattended, + $expupcoming, + $expavailable, + $expbookable + ) { $sched = scheduler::load_by_id($schedulerid); $attended = $sched->get_attended_slots_for_student($studentid); @@ -299,7 +306,6 @@ private function check_timed_slots($schedulerid, $studentid, $slotoptions, $bookable = $sched->get_slots_available_to_student($studentid, true); $this->assert_slot_times($expbookable, $bookable, $slotoptions, 'Booked slots'); - } /** @@ -358,39 +364,54 @@ public function test_load_slot_timing(): void { $schedrec->guardtime = 0; $DB->update_record('scheduler', $schedrec); - $this->check_timed_slots($schedid, $currentstud, $options, - [7, 8], - [0, 1, 2, 3, 4, 5, 6], - [10, 11, 12, 13, 14], - [10, 11, 12, 13, 14, 9] ); + $this->check_timed_slots( + $schedid, + $currentstud, + $options, + [7, 8], + [0, 1, 2, 3, 4, 5, 6], + [10, 11, 12, 13, 14], + [10, 11, 12, 13, 14, 9] + ); $schedrec->guardtime = DAYSECS; $DB->update_record('scheduler', $schedrec); - $this->check_timed_slots($schedid, $currentstud, $options, - [7, 8], - [0, 1, 2, 3, 4, 5, 6], - [11, 12, 13, 14], - [11, 12, 13, 14, 9] ); + $this->check_timed_slots( + $schedid, + $currentstud, + $options, + [7, 8], + [0, 1, 2, 3, 4, 5, 6], + [11, 12, 13, 14], + [11, 12, 13, 14, 9] + ); $schedrec->guardtime = 4 * DAYSECS; $DB->update_record('scheduler', $schedrec); - $this->check_timed_slots($schedid, $currentstud, $options, - [7, 8], - [0, 1, 2, 3, 4, 5, 6], - [14], - [14, 9] ); + $this->check_timed_slots( + $schedid, + $currentstud, + $options, + [7, 8], + [0, 1, 2, 3, 4, 5, 6], + [14], + [14, 9] + ); $schedrec->guardtime = 20 * DAYSECS; $DB->update_record('scheduler', $schedrec); - $this->check_timed_slots($schedid, $currentstud, $options, - [7, 8], - [0, 1, 2, 3, 4, 5, 6], - [], - [] ); - + $this->check_timed_slots( + $schedid, + $currentstud, + $options, + [7, 8], + [0, 1, 2, 3, 4, 5, 6], + [], + [] + ); } /** @@ -403,22 +424,33 @@ public function test_load_slot_timing(): void { * * @covers \mod_scheduler\model\scheduler::load_by_id */ - private function assert_bookable_appointments($expectedwithchangeables, $expectedwithoutchangeables, - $schedid, $studentid) { + private function assert_bookable_appointments( + $expectedwithchangeables, + $expectedwithoutchangeables, + $schedid, + $studentid + ) { $scheduler = scheduler::load_by_id($schedid); $actualwithchangeables = $scheduler->count_bookable_appointments($studentid, true); - $this->assertEquals($expectedwithchangeables, $actualwithchangeables, - 'Checking number of bookable appointments (including changeable bookings)'); + $this->assertEquals( + $expectedwithchangeables, + $actualwithchangeables, + 'Checking number of bookable appointments (including changeable bookings)' + ); $actualwithoutchangeables = $scheduler->count_bookable_appointments($studentid, false); - $this->assertEquals($expectedwithoutchangeables, $actualwithoutchangeables, - 'Checking number of bookable appointments (excluding changeable bookings)'); + $this->assertEquals( + $expectedwithoutchangeables, + $actualwithoutchangeables, + 'Checking number of bookable appointments (excluding changeable bookings)' + ); $studs = $scheduler->get_students_for_scheduling(); if ($expectedwithoutchangeables != 0) { $this->assertTrue(is_array($studs), 'Checking that get_students_for_scheduling returns an array'); } + $actualnum = count($studs); $expectednum = ($expectedwithoutchangeables > 0) ? 3 : 2; $this->assertEquals($expectednum, $actualnum, 'Checking number of students available for scheduling'); @@ -440,9 +472,14 @@ private function assert_bookable_appointments($expectedwithchangeables, $expecte * @param array $bookedslots slots to book the student in * @param array $attendedslots slots which the student has attended */ - private function create_data_for_bookable_appointments($schedulermode, $maxbookings, $guardtime, $studentid, - array $bookedslots, array $attendedslots) { - + private function create_data_for_bookable_appointments( + $schedulermode, + $maxbookings, + $guardtime, + $studentid, + array $bookedslots, + array $attendedslots + ) { global $DB; $course = $this->getDataGenerator()->create_course(); @@ -527,7 +564,5 @@ public function test_bookable_appointments(): void { // One booking allowed at a time. One booked inside GT. $sid = $this->create_data_for_bookable_appointments('onetime', 1, 5 * DAYSECS, $studid, [2], []); $this->assert_bookable_appointments(0, 0, $sid, $studid); - } - } diff --git a/tests/slot_test.php b/tests/slot_test.php index b9c39295..36e73796 100644 --- a/tests/slot_test.php +++ b/tests/slot_test.php @@ -39,8 +39,8 @@ * @copyright 2014 Henning Bostelmann and others (see README.txt) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -final class slot_test extends \advanced_testcase { - +final class slot_test extends \advanced_testcase +{ /** * @var int Course_modules id used for testing */ @@ -162,7 +162,6 @@ public function test_create(): void { $newcnt = $DB->count_records('scheduler_appointment', ['slotid' => $newid]); $this->assertEquals(2, $newcnt, "Counting number of appointments after addition"); - } @@ -193,7 +192,6 @@ public function test_delete(): void { foreach ($this->students as $student) { $this->assert_event_absent($student, $start, ""); } - } /** @@ -218,7 +216,6 @@ public function test_add_appointment(): void { $newcnt = $DB->count_records('scheduler_appointment', ['slotid' => $slot->get_id()]); $this->assertEquals(4, $newcnt, "Counting number of appointments after addition"); - } /** @@ -272,6 +269,7 @@ public function test_calendar_events(): void { $this->assert_event_absent($student, $oldstart); $this->assert_event_exists($student, $newstart, "Meeting with your Teacher"); } + $this->assert_event_absent($this->teacherid, $oldstart); $this->assert_event_exists($this->teacherid, $newstart, "Meeting with your Students"); @@ -292,8 +290,8 @@ public function test_calendar_events(): void { foreach ($this->students as $student) { $this->assert_event_absent($student, $newstart); } - $this->assert_event_absent($this->teacherid, $newstart); + $this->assert_event_absent($this->teacherid, $newstart); } /** diff --git a/view.php b/view.php index 6171ddf5..e2d6b0fa 100644 --- a/view.php +++ b/view.php @@ -25,9 +25,9 @@ use mod_scheduler\model\scheduler; require_once(dirname(__FILE__) . '/../../config.php'); -require_once($CFG->dirroot.'/mod/scheduler/lib.php'); -require_once($CFG->dirroot.'/mod/scheduler/locallib.php'); -require_once($CFG->dirroot.'/mod/scheduler/renderable.php'); +require_once($CFG->dirroot . '/mod/scheduler/lib.php'); +require_once($CFG->dirroot . '/mod/scheduler/locallib.php'); +require_once($CFG->dirroot . '/mod/scheduler/renderable.php'); // Read common request parameters. $id = optional_param('id', '', PARAM_INT); // Course Module ID - if it's not specified, must specify 'a', see below. @@ -43,6 +43,7 @@ $scheduler = scheduler::load_by_id($a); $cm = $scheduler->get_cm(); } + $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); @@ -60,6 +61,7 @@ } else { $defaultsubpage = 'allappointments'; } + $subpage = optional_param('subpage', $defaultsubpage, PARAM_ALPHA); @@ -77,21 +79,19 @@ if ($isteacher) { // Teacher side. if ($action == 'viewstatistics') { - include($CFG->dirroot.'/mod/scheduler/viewstatistics.php'); + include($CFG->dirroot . '/mod/scheduler/viewstatistics.php'); } else if ($action == 'viewstudent') { - include($CFG->dirroot.'/mod/scheduler/viewstudent.php'); + include($CFG->dirroot . '/mod/scheduler/viewstudent.php'); } else if ($action == 'export') { - include($CFG->dirroot.'/mod/scheduler/export.php'); + include($CFG->dirroot . '/mod/scheduler/export.php'); } else if ($action == 'datelist') { - include($CFG->dirroot.'/mod/scheduler/datelist.php'); + include($CFG->dirroot . '/mod/scheduler/datelist.php'); } else { - include($CFG->dirroot.'/mod/scheduler/teacherview.php'); + include($CFG->dirroot . '/mod/scheduler/teacherview.php'); } - } else if ($isstudent) { // Student side. - include($CFG->dirroot.'/mod/scheduler/studentview.php'); - + include($CFG->dirroot . '/mod/scheduler/studentview.php'); } else { // For guests. echo $OUTPUT->header(); diff --git a/viewstatistics.php b/viewstatistics.php index 58e408f3..6fb8165f 100644 --- a/viewstatistics.php +++ b/viewstatistics.php @@ -120,18 +120,18 @@ function byname($a, $b) { $allattendees = ($attendees) ? count($attendees) : 0; - $str = '

'.get_string('attendable', 'scheduler').'

'; - $str .= ''.get_string('attendablelbl', 'scheduler').': ' . $allattendees . '
'; - $str .= '

'.get_string('attended', 'scheduler').'

'; - $str .= ''.get_string('attendedlbl', 'scheduler').': ' . $attended . '

'; - $str .= '

'.get_string('unattended', 'scheduler').'

'; - $str .= ''.get_string('registeredlbl', 'scheduler').': ' . $registered . '
'; - $str .= ''.get_string('unregisteredlbl', 'scheduler').': ' . + $str = '

' . get_string('attendable', 'scheduler') . '

'; + $str .= '' . get_string('attendablelbl', 'scheduler') . ': ' . $allattendees . '
'; + $str .= '

' . get_string('attended', 'scheduler') . '

'; + $str .= '' . get_string('attendedlbl', 'scheduler') . ': ' . $attended . '

'; + $str .= '

' . get_string('unattended', 'scheduler') . '

'; + $str .= '' . get_string('registeredlbl', 'scheduler') . ': ' . $registered . '
'; + $str .= '' . get_string('unregisteredlbl', 'scheduler') . ': ' . ($allattendees - $registered - $attended) . '
'; - $str .= '

'.get_string('availableslots', 'scheduler').'

'; - $str .= ''.get_string('availableslotsowned', 'scheduler').': ' . $freeowned . '
'; - $str .= ''.get_string('availableslotsnotowned', 'scheduler').': ' . $freenotowned . '
'; - $str .= ''.get_string('availableslotsall', 'scheduler').': ' . ($freeowned + $freenotowned) . '
'; + $str .= '

' . get_string('availableslots', 'scheduler') . '

'; + $str .= '' . get_string('availableslotsowned', 'scheduler') . ': ' . $freeowned . '
'; + $str .= '' . get_string('availableslotsnotowned', 'scheduler') . ': ' . $freenotowned . '
'; + $str .= '' . get_string('availableslotsall', 'scheduler') . ': ' . ($freeowned + $freenotowned) . '
'; echo $OUTPUT->box($str); @@ -165,8 +165,10 @@ function byname($a, $b) { $table->data[] = [fullname($attendees[$arecord->studentid]), $arecord->totaltime]; } } + uasort($table->data, 'byname'); } + echo html_writer::table($table); } else { echo $OUTPUT->box(get_string('nostudents', 'scheduler'), 'center', '70%'); @@ -187,6 +189,7 @@ function byname($a, $b) { $sql .= " AND EXISTS (SELECT 1 FROM {groups_members} gm WHERE gm.userid = a.studentid AND gm.groupid = :gid)"; $params['gid'] = $currentgroupid; } + $sql .= " GROUP BY s.teacherid"; if ($statrecords = $DB->get_records_sql($sql, $params)) { $table = new html_table(); @@ -197,6 +200,7 @@ function byname($a, $b) { $ateacher = $DB->get_record('user', ['id' => $arecord->teacherid]); $table->data[] = [fullname($ateacher), $arecord->totaltime]; } + uasort($table->data, 'byname'); echo html_writer::table($table); } @@ -222,6 +226,7 @@ function byname($a, $b) { $sql .= " AND EXISTS (SELECT 1 FROM {groups_members} gm WHERE gm.userid = a.studentid AND gm.groupid = :gid)"; $params['gid'] = $currentgroupid; } + $sql .= " GROUP BY s.starttime ORDER BY groupsize DESC"; if ($groupslots = $DB->get_records_sql($sql, $params)) { $table = new html_table(); @@ -232,14 +237,16 @@ function byname($a, $b) { $durationcount = []; foreach ($groupslots as $slot) { if (array_key_exists($slot->duration, $durationcount)) { - $durationcount[$slot->duration] ++; + $durationcount[$slot->duration]++; } else { $durationcount[$slot->duration] = 1; } } + foreach ($durationcount as $key => $duration) { $table->data[] = [$key, $duration]; } + echo html_writer::table($table); } break; @@ -264,6 +271,7 @@ function byname($a, $b) { $sql .= " AND EXISTS (SELECT 1 FROM {groups_members} gm WHERE gm.userid = s.teacherid AND gm.groupid = :gid)"; $params['gid'] = $currentgroupid; } + $sql .= " GROUP BY s.starttime ORDER BY groupsize DESC"; if ($groupslots = $DB->get_records_sql($sql, $params)) { @@ -279,17 +287,21 @@ function byname($a, $b) { $grouprows[$agroup->groupsize]->occurrences = 0; $grouprows[$agroup->groupsize]->duration = 0; } + $grouprows[$agroup->groupsize]->occurrences++; $grouprows[$agroup->groupsize]->duration += $agroup->duration; } + foreach (array_keys($grouprows) as $agroupsize) { $table->data[] = [$agroupsize, $grouprows[$agroupsize]->occurrences, $grouprows[$agroupsize]->duration]; } + echo html_writer::table($table); } } + echo '
'; -echo $OUTPUT->continue_button("$CFG->wwwroot/mod/scheduler/view.php?id=".$cm->id); +echo $OUTPUT->continue_button("$CFG->wwwroot/mod/scheduler/view.php?id=" . $cm->id); // Finish the page. echo $OUTPUT->footer($course); exit; diff --git a/viewstudent.php b/viewstudent.php index e1a2480e..90f98eeb 100644 --- a/viewstudent.php +++ b/viewstudent.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot.'/mod/scheduler/locallib.php'); +require_once($CFG->dirroot . '/mod/scheduler/locallib.php'); $appointmentid = required_param('appointmentid', PARAM_INT); -list($slot, $appointment) = $scheduler->get_slot_appointment($appointmentid); +[$slot, $appointment] = $scheduler->get_slot_appointment($appointmentid); $studentid = $appointment->studentid; $permissions->ensure($permissions->can_see_appointment($appointment)); @@ -45,17 +45,18 @@ if ($slot->get_appointment_count() > 1) { $pages[] = 'otherstudents'; } + if (count($appts) > 1) { $pages[] = 'otherappointments'; } -if (!in_array($subpage, $pages) ) { +if (!in_array($subpage, $pages)) { $subpage = 'thisappointment'; } // Process edit form before page output starts. if ($subpage == 'thisappointment') { - require_once($CFG->dirroot.'/mod/scheduler/appointmentforms.php'); + require_once($CFG->dirroot . '/mod/scheduler/appointmentforms.php'); $actionurl = new moodle_url($taburl, ['page' => 'thisappointment']); $returnurl = new moodle_url($taburl, ['page' => 'thisappointment']); @@ -85,9 +86,10 @@ if (count($pages) > 1) { foreach ($pages as $tabpage) { - $tabname = get_string('tab-'.$tabpage, 'scheduler'); + $tabname = get_string('tab-' . $tabpage, 'scheduler'); $row[] = new tabobject($tabpage, new moodle_url($taburl, ['subpage' => $tabpage]), $tabname); } + $tabrows[] = $row; print_tabs($tabrows, $subpage); } @@ -95,7 +97,6 @@ $totalgradeinfo = new scheduler_totalgrade_info($scheduler, $scheduler->get_gradebook_info($appointment->studentid)); if ($subpage == 'thisappointment') { - $ai = scheduler_appointment_info::make_for_teacher($slot, $appointment); echo $output->render($ai); @@ -104,7 +105,6 @@ if ($scheduler->uses_grades()) { echo $output->render($totalgradeinfo); } - } else if ($subpage == 'otherappointments') { // Print table of other appointments of the same student. @@ -126,7 +126,6 @@ $totalgradeinfo->totalgrade = $scheduler->get_user_grade($appointment->studentid); echo $output->render($totalgradeinfo); } - } else if ($subpage == 'otherstudents') { // Print table of other students in the same slot.