{{#str}}topcollopened, format_topcoll{{/str}}
{{#tif}}{{{tif}}}{{/tif}} + {{#tifpleft}}{{#tif}}{{{tif}}}{{/tif}}{{/tifpleft}}{{#str}}topcollopened, format_topcoll{{/str}}
{{^tifpleft}}{{#tif}}{{{tif}}}{{/tif}}{{/tifpleft}} -{{#str}}topcollclosed, format_topcoll{{/str}}
{{#tif}}{{{tif}}}{{/tif}} + {{#tifpleft}}{{#tif}}{{{tif}}}{{/tif}}{{/tifpleft}}{{#str}}topcollclosed, format_topcoll{{/str}}
{{^tifpleft}}{{#tif}}{{{tif}}}{{/tif}}{{/tifpleft}}' . print_r($totalsbyid, 1) . '
'; .... - if (!empty($totalsbyid)) { - if (isset($totalsbyid[$modid])) { - return intval($totalsbyid[$modid]->total); - } + $modtotalsbyid[$modinstance] = $DB->get_records_sql($sql, $params); } - return 0; + + return intval($modtotalsbyid[$modinstance]); } /** From 8e3ed76615abc9bd91864e0a407667231b2d82ee Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Mon, 14 Aug 2023 12:11:11 +0100 Subject: [PATCH 23/31] V402.1.1 --- Changes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Changes.md b/Changes.md index effb795..cea0cf0 100644 --- a/Changes.md +++ b/Changes.md @@ -1,8 +1,8 @@ Version Information =================== -Version 402.1.1 - TBR --------------------------- +Version 402.1.1 - 14/08/2023 +---------------------------- 1. Fix 'section_activity_summary' method. 2. Single section navigation fixes. 3. Improve single section navigation appearance. From 6a0a892561555b6ae8d7d2c35e47d4656a607176 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Sat, 23 Sep 2023 15:51:52 +0100 Subject: [PATCH 24/31] V402.1.2 --- Changes.md | 3 +++ version.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Changes.md b/Changes.md index cea0cf0..d967942 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,9 @@ Version Information =================== +Version 402.1.2 - TBR +---------------------------- + Version 402.1.1 - 14/08/2023 ---------------------------- 1. Fix 'section_activity_summary' method. diff --git a/version.php b/version.php index 1c4588b..ec65b21 100644 --- a/version.php +++ b/version.php @@ -33,9 +33,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023042401; +$plugin->version = 2023042402; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2023042400.00; // 4.2 (Build: 20230424). $plugin->supported = array(402, 402); $plugin->component = 'format_topcoll'; -$plugin->release = '402.1.1'; +$plugin->release = '402.1.2'; From 54a438061a6eb5b374dc708fda186533bbb3a8ea Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Sat, 23 Sep 2023 16:55:54 +0100 Subject: [PATCH 25/31] CodeChecker!!!! --- .../restore_format_topcoll_plugin.class.php | 21 +- classes/activity.php | 129 +-- classes/activity_meta.php | 1 - classes/admin_setting_information.php | 29 +- classes/admin_setting_markdown.php | 7 +- classes/observer.php | 5 +- classes/output/courseformat/content/cm.php | 49 +- .../courseformat/content/section/cmitem.php | 1 - .../courseformat/content/section/cmlist.php | 1 - .../content/section/controlmenu.php | 11 +- .../format_renderer_migration_toolbox.php | 1 - classes/output/renderer.php | 192 ++-- classes/privacy/provider.php | 9 +- classes/togglelib.php | 10 +- classes/toolbox.php | 11 +- db/access.php | 54 +- db/caches.php | 28 +- db/events.php | 44 +- db/upgrade.php | 19 +- format.php | 6 +- js/tc_colourpopup.php | 21 +- lang/en_us/format_topcoll.php | 1 - lib.php | 823 ++++++++++-------- settings.php | 235 ++--- tests/courseformatlib_test.php | 17 +- tests/courseformatrenderer_test.php | 255 +++--- tests/courseformattoolbox_test.php | 4 +- tests/privacy_provider_test.php | 19 +- tests/togglelib_test.php | 15 +- version.php | 2 +- 30 files changed, 1096 insertions(+), 924 deletions(-) diff --git a/backup/moodle2/restore_format_topcoll_plugin.class.php b/backup/moodle2/restore_format_topcoll_plugin.class.php index f392160..6974b54 100644 --- a/backup/moodle2/restore_format_topcoll_plugin.class.php +++ b/backup/moodle2/restore_format_topcoll_plugin.class.php @@ -38,7 +38,6 @@ * needed to restore one topcoll course format. */ class restore_format_topcoll_plugin extends restore_format_plugin { - /** @var int */ protected $originalnumsections = 0; @@ -53,11 +52,12 @@ protected function define_course_plugin_structure() { global $DB; $maxsection = $DB->get_field_sql( 'SELECT max(section) FROM {course_sections} WHERE course = ?', - [$this->step->get_task()->get_courseid()]); + [$this->step->get_task()->get_courseid()] + ); $this->originalnumsections = (int)$maxsection; } - $paths = array(); + $paths = []; // Add own format stuff. $elename = 'topcoll'; // This defines the postfix of 'process_*' below. @@ -79,14 +79,14 @@ public function process_topcoll($data) { $data = (object) $data; /* We only process this information if the course we are restoring to has 'topcoll' format (target format can change depending of restore options). */ - $format = $DB->get_field('course', 'format', array('id' => $this->task->get_courseid())); + $format = $DB->get_field('course', 'format', ['id' => $this->task->get_courseid()]); if ($format != 'topcoll') { return; } $data->courseid = $this->task->get_courseid(); - if (!($course = $DB->get_record('course', array('id' => $data->courseid)))) { + if (!($course = $DB->get_record('course', ['id' => $data->courseid]))) { print_error('invalidcourseid', 'error'); } // From /course/view.php. $courseformat = course_get_format($course); @@ -103,7 +103,8 @@ public function process_topcoll($data) { $data->layoutcolumns, $data->tgfgcolour, $data->tgbgcolour, - $data->tgbghvrcolour); + $data->tgbghvrcolour + ); // No need to annotate anything here. } @@ -124,7 +125,7 @@ public function after_restore_course() { /* We only process this information if the course we are restoring to has 'topcoll' format (target format can change depending of restore options). */ - $format = $DB->get_field('course', 'format', array('id' => $courseid)); + $format = $DB->get_field('course', 'format', ['id' => $courseid]); if ($format !== 'topcoll') { return; } @@ -154,8 +155,10 @@ public function after_restore_course() { if ($this->step->get_task()->get_setting_value($key . '_included')) { $sectionnum = (int)$section->title; if ($sectionnum > $settings['numsections'] && $sectionnum > $this->originalnumsections) { - $DB->execute("UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?", - [$this->step->get_task()->get_courseid(), $sectionnum]); + $DB->execute( + "UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?", + [$this->step->get_task()->get_courseid(), $sectionnum] + ); } } } diff --git a/classes/activity.php b/classes/activity.php index 46b572f..b7f619e 100644 --- a/classes/activity.php +++ b/classes/activity.php @@ -48,9 +48,9 @@ defined('MOODLE_INTERNAL') || die(); -use \cm_info; +use cm_info; -require_once($CFG->dirroot.'/mod/assign/locallib.php'); +require_once($CFG->dirroot . '/mod/assign/locallib.php'); /** * Activity functions. @@ -64,7 +64,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class activity { - /** * * Main method that calls relevant activity-related method based on the mod name. @@ -96,40 +95,42 @@ public static function module_meta(cm_info $mod) { * @return activity_meta */ protected static function std_meta( - cm_info $mod, - $submitstrkey, - $isgradeable = false - ) { + cm_info $mod, + $submitstrkey, + $isgradeable = false + ) { $courseid = $mod->course; $meta = null; // If role has specific "teacher" capabilities. - if ((has_capability('mod/assign:grade', $mod->context)) || - (has_capability('mod/forum:grade', $mod->context))) { + if ( + (has_capability('mod/assign:grade', $mod->context)) || + (has_capability('mod/forum:grade', $mod->context)) + ) { $meta = new activity_meta(); $meta->isteacher = true; $meta->submitstrkey = $submitstrkey; if ($mod->modname === 'assign') { - list( + [ 'participants' => $meta->numparticipants, 'submissions' => $meta->numsubmissions, 'ungraded' => $meta->numrequiregrading, - ) = self::assign_nums($courseid, $mod); + ] = self::assign_nums($courseid, $mod); } else { - $methodnsubmissions = $mod->modname.'_num_submissions'; - $methodnumungraded = $mod->modname.'_num_submissions_ungraded'; + $methodnsubmissions = $mod->modname . '_num_submissions'; + $methodnumungraded = $mod->modname . '_num_submissions_ungraded'; // Do this before the rest so that the caches are populated for use. $meta->numparticipants = self::course_participant_count($courseid, $mod); if (!empty($meta->numparticipants)) { // Only need to bother if there are participants! if (method_exists('format_topcoll\\activity', $methodnsubmissions)) { - $meta->numsubmissions = call_user_func('format_topcoll\\activity::'. + $meta->numsubmissions = call_user_func('format_topcoll\\activity::' . $methodnsubmissions, $courseid, $mod); } if (method_exists('format_topcoll\\activity', $methodnumungraded)) { - $meta->numrequiregrading = call_user_func('format_topcoll\\activity::'. + $meta->numrequiregrading = call_user_func('format_topcoll\\activity::' . $methodnumungraded, $courseid, $mod); } if ($mod->modname === 'forum') { @@ -151,14 +152,14 @@ protected static function std_meta( } else { global $USER; - $gradeitem = \grade_item::fetch(array( + $gradeitem = \grade_item::fetch([ 'itemtype' => 'mod', 'itemmodule' => $mod->modname, 'iteminstance' => $mod->instance, - 'outcomeid' => null - )); + 'outcomeid' => null, + ]); - $grade = new \grade_grade(array('itemid' => $gradeitem->id, 'userid' => $USER->id)); + $grade = new \grade_grade(['itemid' => $gradeitem->id, 'userid' => $USER->id]); if (!$grade->is_hidden()) { $meta = new activity_meta(); $meta->grade = true; @@ -224,9 +225,11 @@ protected static function forum_meta(cm_info $modinst) { FROM {forum} f WHERE f.id = :forumid"; $forumscale = $DB->get_records_sql($sql, $params); - if ((!empty($forumscale[$modinst->instance])) && + if ( + (!empty($forumscale[$modinst->instance])) && ($forumscale[$modinst->instance]->scale > 0) && - ($forumscale[$modinst->instance]->grade_forum != 0)) { + ($forumscale[$modinst->instance]->grade_forum != 0) + ) { return self::std_meta($modinst, 'posted'); } return null; // Whole forum grading off for this forum. @@ -268,28 +271,29 @@ protected static function quiz_meta(cm_info $modinst) { * @return int */ protected static function std_num_submissions( - $courseid, - $mod, - $maintable, - $mainkey, - $submittable, - $extraselect = '') { + $courseid, + $mod, + $maintable, + $mainkey, + $submittable, + $extraselect = '' + ) { global $DB; - static $modtotalsbyid = array(); + static $modtotalsbyid = []; if (!isset($modtotalsbyid[$maintable][$courseid])) { // Results are not cached, so lets get them. // Get people who are typically not students (people who can view grader report) so that we can exclude them! - list($graderids, $params) = get_enrolled_sql(\context_course::instance($courseid), 'moodle/grade:viewall'); + [$graderids, $params] = get_enrolled_sql(\context_course::instance($courseid), 'moodle/grade:viewall'); $params['courseid'] = $courseid; // Get the number of submissions for all $maintable activities in this course. $sql = "-- Snap sql SELECT m.id, COUNT(DISTINCT sb.userid) as totalsubmitted - FROM {".$maintable."} m - JOIN {".$submittable."} sb ON m.id = sb.$mainkey + FROM {" . $maintable . "} m + JOIN {" . $submittable . "} sb ON m.id = sb.$mainkey WHERE m.course = :courseid AND sb.userid NOT IN ($graderids) $extraselect @@ -328,11 +332,11 @@ protected static function assign_nums($courseid, $mod) { } $submitted = ASSIGN_SUBMISSION_STATUS_SUBMITTED; - return array( + return [ 'participants' => $participants, 'submissions' => $assign->count_submissions_with_status($submitted, $activitygroup), - 'ungraded' => $assign->count_submissions_need_grading($activitygroup) - ); + 'ungraded' => $assign->count_submissions_need_grading($activitygroup), + ]; } /** @@ -345,7 +349,7 @@ protected static function assign_nums($courseid, $mod) { protected static function data_num_submissions($courseid, $mod) { $modinstance = $mod->instance; - static $modtotalsbyinstance = array(); + static $modtotalsbyinstance = []; if (!isset($modtotalsbyinstance[$modinstance])) { global $DB; @@ -485,7 +489,7 @@ protected static function quiz_num_submissions_ungraded($courseid, $mod) { $coursecontext = \context_course::instance($courseid); // Get people who are typically not students (people who can view grader report) so that we can exclude them! - list($graderids, $params) = get_enrolled_sql($coursecontext, 'moodle/grade:viewall'); + [$graderids, $params] = get_enrolled_sql($coursecontext, 'moodle/grade:viewall'); $params['courseid'] = $courseid; if (!isset($totalsbyquizid)) { @@ -527,17 +531,18 @@ protected static function quiz_num_submissions_ungraded($courseid, $mod) { protected static function grade_row($courseid, $mod) { global $DB, $USER; - static $grades = array(); + static $grades = []; - if (isset($grades[$courseid.'_'.$mod->modname]) - && isset($grades[$courseid.'_'.$mod->modname][$mod->instance]) - ) { - return $grades[$courseid.'_'.$mod->modname][$mod->instance]; + if ( + isset($grades[$courseid . '_' . $mod->modname]) + && isset($grades[$courseid . '_' . $mod->modname][$mod->instance]) + ) { + return $grades[$courseid . '_' . $mod->modname][$mod->instance]; } $sql = "-- Snap sql SELECT m.id AS instanceid, gg.* - FROM {".$mod->modname."} m + FROM {" . $mod->modname . "} m JOIN {grade_items} gi ON m.id = gi.iteminstance @@ -557,16 +562,16 @@ protected static function grade_row($courseid, $mod) { OR gg.feedback IS NOT NULL ) "; - $params = array( + $params = [ 'modname' => $mod->modname, 'courseid1' => $courseid, 'courseid2' => $courseid, - 'userid' => $USER->id - ); - $grades[$courseid.'_'.$mod->modname] = $DB->get_records_sql($sql, $params); + 'userid' => $USER->id, + ]; + $grades[$courseid . '_' . $mod->modname] = $DB->get_records_sql($sql, $params); - if (isset($grades[$courseid.'_'.$mod->modname][$mod->instance])) { - return $grades[$courseid.'_'.$mod->modname][$mod->instance]; + if (isset($grades[$courseid . '_' . $mod->modname][$mod->instance])) { + return $grades[$courseid . '_' . $mod->modname][$mod->instance]; } else { return false; } @@ -588,7 +593,7 @@ protected static function course_participant_count($courseid, $mod) { $usercreatedcache = \cache::make('format_topcoll', 'activityusercreatedcache'); $createdusers = $usercreatedcache->get($courseid); $lock = null; - $newstudents = array(); + $newstudents = []; if (!empty($createdusers)) { $lock = self::lockcaches($courseid); @@ -598,7 +603,7 @@ protected static function course_participant_count($courseid, $mod) { $alluserroles = get_users_roles($context, $createdusers, false); foreach ($createdusers as $userid) { - $usershortnames = array(); + $usershortnames = []; foreach ($alluserroles[$userid] as $userrole) { $usershortnames[] = $userrole->shortname; } @@ -675,7 +680,7 @@ public static function course_get_students($courseid) { if (empty($studentroles)) { $studentarch = get_archetype_roles('student'); - $studentroles = array(); + $studentroles = []; foreach ($studentarch as $role) { $studentroles[] = $role->shortname; } @@ -685,14 +690,14 @@ public static function course_get_students($courseid) { $studentscache = \cache::make('format_topcoll', 'activitystudentscache'); $students = $studentscache->get($courseid); if (empty($students)) { - $students = array(); + $students = []; $context = \context_course::instance($courseid); $enrolledusers = get_enrolled_users($context, '', 0, 'u.id', null, 0, 0, true); $users = array_keys($enrolledusers); $alluserroles = get_users_roles($context, $users, false); foreach ($users as $userid) { - $usershortnames = array(); + $usershortnames = []; foreach ($alluserroles[$userid] as $userrole) { $usershortnames[] = $userrole->shortname; } @@ -747,7 +752,7 @@ public static function maxstudentsnotexceeded($courseid, $extrainfo = false) { } if ($extrainfo) { - return array('notexceeded' => $notexceeded, 'nostudents' => $studentcount, 'maxstudents' => $maxstudents); + return ['notexceeded' => $notexceeded, 'nostudents' => $studentcount, 'maxstudents' => $maxstudents]; } return $notexceeded; @@ -834,7 +839,7 @@ private static function userenrolmentchanged($userid, $courseid, $type) { $usercreatedcache = \cache::make('format_topcoll', 'activityusercreatedcache'); $createdusers = $usercreatedcache->get($courseid); if (empty($createdusers)) { - $createdusers = array(); + $createdusers = []; } $createdusers[] = $userid; $usercreatedcache->set($courseid, $createdusers); @@ -964,10 +969,10 @@ private static function calulatecoursemodules($courseid, $students, $modid = nul $modinfo = get_fast_modinfo($courseid, -1); $cms = $modinfo->get_cms(); // Array of cm_info objects. foreach ($cms as $themod) { - $modulecount[$themod->id] = array(0, array()); + $modulecount[$themod->id] = [0, []]; } } else { - $modulecount[$modid] = array(0, array()); + $modulecount[$modid] = [0, []]; } } foreach ($students as $userid) { @@ -1000,11 +1005,15 @@ private static function calulatecoursemodules($courseid, $students, $modid = nul */ private static function lockcaches($courseid) { $lockfactory = \core\lock\lock_config::get_lock_factory('format_topcoll'); - if ($lock = $lockfactory->get_lock('courseid'.$courseid, 5)) { + if ($lock = $lockfactory->get_lock('courseid' . $courseid, 5)) { return $lock; } - throw new \moodle_exception('cannotgetactivitycacheslock', 'format_topcoll', '', - get_string('cannotgetactivitycacheslock', 'format_topcoll', $courseid)); + throw new \moodle_exception( + 'cannotgetactivitycacheslock', + 'format_topcoll', + '', + get_string('cannotgetactivitycacheslock', 'format_topcoll', $courseid) + ); } /** diff --git a/classes/activity_meta.php b/classes/activity_meta.php index b4410c0..6d7c293 100644 --- a/classes/activity_meta.php +++ b/classes/activity_meta.php @@ -52,7 +52,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class activity_meta { - // Strings. /** * @var string $submitstrkey - language string key. diff --git a/classes/admin_setting_information.php b/classes/admin_setting_information.php index 4f6bb40..188c48a 100644 --- a/classes/admin_setting_information.php +++ b/classes/admin_setting_information.php @@ -40,7 +40,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. */ class admin_setting_information extends \admin_setting { - /** @var int The branch this is for. */ protected $mbranch; @@ -94,7 +93,7 @@ public function write_setting($data) { * @param string $query * @return string Returns an HTML string */ - public function output_html($data, $query='') { + public function output_html($data, $query = '') { global $CFG, $OUTPUT; $formats = \core_plugin_manager::instance()->get_present_plugins('format'); @@ -106,19 +105,21 @@ public function output_html($data, $query='') { } $classes[] = 'fa fa-heart'; - $attributes = array(); + $attributes = []; $attributes['aria-hidden'] = 'true'; $attributes['class'] = 'fa fa-heart'; $attributes['title'] = get_string('love', 'format_topcoll'); - $content = \html_writer::tag('span', $attributes['title'], array('class' => 'sr-only')); + $content = \html_writer::tag('span', $attributes['title'], ['class' => 'sr-only']); $content = \html_writer::tag('span', $content, $attributes); - $context['versioninfo'] = get_string('versioninfo', 'format_topcoll', - array( + $context['versioninfo'] = get_string( + 'versioninfo', + 'format_topcoll', + [ 'moodle' => $CFG->release, 'release' => $plugininfo->release, 'version' => $plugininfo->version, - 'love' => $content - ) + 'love' => $content, + ] ); if (!empty($plugininfo->maturity)) { @@ -126,25 +127,25 @@ public function output_html($data, $query='') { case MATURITY_ALPHA: $context['maturity'] = get_string('versionalpha', 'format_topcoll'); $context['maturityalert'] = 'danger'; - break; + break; case MATURITY_BETA: $context['maturity'] = get_string('versionbeta', 'format_topcoll'); $context['maturityalert'] = 'danger'; - break; + break; case MATURITY_RC: $context['maturity'] = get_string('versionrc', 'format_topcoll'); $context['maturityalert'] = 'warning'; - break; + break; case MATURITY_STABLE: $context['maturity'] = get_string('versionstable', 'format_topcoll'); $context['maturityalert'] = 'info'; - break; + break; } } if ($CFG->branch != $this->mbranch) { - $context['versioncheck'] = 'Release '.$plugininfo->release.', version '.$plugininfo->version; - $context['versioncheck'] .= ' is incompatible with Moodle '.$CFG->release; + $context['versioncheck'] = 'Release ' . $plugininfo->release . ', version ' . $plugininfo->version; + $context['versioncheck'] .= ' is incompatible with Moodle ' . $CFG->release; $context['versioncheck'] .= ', please get the correct version from '; $context['versioncheck'] .= 'Moodle.org. '; $context['versioncheck'] .= 'If none is available, then please consider supporting the format by funding it. '; diff --git a/classes/admin_setting_markdown.php b/classes/admin_setting_markdown.php index 1db67a8..1f7d14a 100644 --- a/classes/admin_setting_markdown.php +++ b/classes/admin_setting_markdown.php @@ -40,7 +40,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. */ class admin_setting_markdown extends \admin_setting { - /** @var string Filename */ private $filename; @@ -94,7 +93,7 @@ public function write_setting($data) { * @param string $query * @return string Returns an HTML string */ - public function output_html($data, $query='') { + public function output_html($data, $query = '') { global $CFG, $OUTPUT; $context = new \stdClass(); @@ -102,9 +101,9 @@ public function output_html($data, $query='') { $context->description = $this->description; if (file_exists("{$CFG->dirroot}/course/format/topcoll/{$this->filename}")) { - $filecontents = file_get_contents($CFG->dirroot.'/course/format/topcoll/'.$this->filename); + $filecontents = file_get_contents($CFG->dirroot . '/course/format/topcoll/' . $this->filename); } else { - $filecontents = 'Collapsed Topics format admin_setting_markdown -> file not found: '.$this->filename; + $filecontents = 'Collapsed Topics format admin_setting_markdown -> file not found: ' . $this->filename; } $context->markdown = format_text($filecontents, FORMAT_MARKDOWN); diff --git a/classes/observer.php b/classes/observer.php index 5545e10..97b70ea 100644 --- a/classes/observer.php +++ b/classes/observer.php @@ -34,13 +34,12 @@ defined('MOODLE_INTERNAL') || die(); -require_once($CFG->dirroot.'/course/format/lib.php'); // For course_get_format. +require_once($CFG->dirroot . '/course/format/lib.php'); // For course_get_format. /** * Event observers supported by this format. */ class format_topcoll_observer { - /** * Observer for the course_content_deleted event. * @@ -51,7 +50,7 @@ class format_topcoll_observer { */ public static function course_content_deleted(\core\event\course_content_deleted $event) { global $DB; - $DB->delete_records("user_preferences", array("name" => 'topcoll_toggle_'.$event->objectid)); // This is the $courseid. + $DB->delete_records("user_preferences", ["name" => 'topcoll_toggle_' . $event->objectid]); // This is the $courseid. } /* Events observed for the purpose of the activty functionality. diff --git a/classes/output/courseformat/content/cm.php b/classes/output/courseformat/content/cm.php index b4bba7d..90d915c 100644 --- a/classes/output/courseformat/content/cm.php +++ b/classes/output/courseformat/content/cm.php @@ -37,7 +37,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cm extends cm_base { - /** * Export this data so it can be used as the context for a mustache template. * @@ -54,7 +53,7 @@ public function export_for_template(\renderer_base $output): \stdClass { if (\format_topcoll\activity::activitymetaused($courseformat)) { $courseid = $this->mod->course; if (\format_topcoll\activity::maxstudentsnotexceeded($courseid)) { - $settingname = 'coursesectionactivityfurtherinformation'.$this->mod->modname; + $settingname = 'coursesectionactivityfurtherinformation' . $this->mod->modname; $setting = get_config('format_topcoll', $settingname); if ((!empty($setting)) && ($setting == 2)) { $data->cmmeta = $this->course_section_cm_get_meta($this->mod); @@ -95,23 +94,27 @@ protected function course_section_cm_get_meta(\cm_info $mod) { if ($meta->isteacher) { // Teacher - useful teacher meta data. - $engagementmeta = array(); + $engagementmeta = []; if (!$meta->submissionnotrequired) { /* Below, != 0 means we would get x out of 0 submissions, so at least show something as the module could now be hidden, but there is still useful information. */ if ($meta->numparticipants != 0) { - $engagementmeta[] = get_string('xofy'.$meta->submitstrkey, 'format_topcoll', - (object) array( + $engagementmeta[] = get_string( + 'xofy' . $meta->submitstrkey, + 'format_topcoll', + (object) [ 'completed' => $meta->numsubmissions, - 'participants' => $meta->numparticipants - ) + 'participants' => $meta->numparticipants, + ] ); } else { - $engagementmeta[] = get_string('x'.$meta->submitstrkey, 'format_topcoll', - (object) array( - 'completed' => $meta->numsubmissions - ) + $engagementmeta[] = get_string( + 'x' . $meta->submitstrkey, + 'format_topcoll', + (object) [ + 'completed' => $meta->numsubmissions, + ] ); } } @@ -120,45 +123,45 @@ protected function course_section_cm_get_meta(\cm_info $mod) { $engagementmeta[] = get_string('xungraded', 'format_topcoll', $meta->numrequiregrading); } if (!empty($engagementmeta)) { - $params = array( - 'id' => $mod->id - ); + $params = [ + 'id' => $mod->id, + ]; $file = 'view'; switch ($mod->modname) { case 'assign': $params['action'] = 'grading'; - break; + break; case 'quiz': $file = 'report'; $params['mode'] = 'overview'; - break; + break; } - $sectioncmmetacontext = array( + $sectioncmmetacontext = [ 'linkclass' => 'ct-activity-action', 'linkicon' => $OUTPUT->pix_icon('docs', get_string('info')), 'linktext' => implode(', ', $engagementmeta), 'linkurl' => new \moodle_url("/mod/{$mod->modname}/{$file}.php", $params), - 'type' => 'engagement' - ); + 'type' => 'engagement', + ]; $content = $OUTPUT->render_from_template('format_topcoll/sectioncmmeta', $sectioncmmetacontext); } } else { // Feedback meta. if (!empty($meta->grade)) { if (in_array($mod->modname, ['quiz', 'assign'])) { - $url = new \moodle_url('/mod/'.$mod->modname.'/view.php?id='.$mod->id); + $url = new \moodle_url('/mod/' . $mod->modname . '/view.php?id=' . $mod->id); } else { $url = new \moodle_url('/grade/report/user/index.php', ['id' => $courseid]); } - $sectioncmmetacontext = array( + $sectioncmmetacontext = [ 'linkicon' => $OUTPUT->pix_icon('t/message', get_string('feedback')), 'linktext' => get_string('feedbackavailable', 'format_topcoll'), 'linkurl' => $url, - 'type' => 'feedback' - ); + 'type' => 'feedback', + ]; $content = $OUTPUT->render_from_template('format_topcoll/sectioncmmeta', $sectioncmmetacontext); } } diff --git a/classes/output/courseformat/content/section/cmitem.php b/classes/output/courseformat/content/section/cmitem.php index 6c3d723..1098961 100644 --- a/classes/output/courseformat/content/section/cmitem.php +++ b/classes/output/courseformat/content/section/cmitem.php @@ -35,7 +35,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cmitem extends \core_courseformat\output\local\content\section\cmitem { - public function get_template_name(\renderer_base $renderer): string { return 'format_topcoll/local/content/section/cmitem'; } diff --git a/classes/output/courseformat/content/section/cmlist.php b/classes/output/courseformat/content/section/cmlist.php index e2cd16b..774f37f 100644 --- a/classes/output/courseformat/content/section/cmlist.php +++ b/classes/output/courseformat/content/section/cmlist.php @@ -35,7 +35,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cmlist extends \core_courseformat\output\local\content\section\cmlist { - public function get_template_name(\renderer_base $renderer): string { return 'format_topcoll/local/content/section/cmlist'; } diff --git a/classes/output/courseformat/content/section/controlmenu.php b/classes/output/courseformat/content/section/controlmenu.php index 60f5ebb..ecd6f3f 100644 --- a/classes/output/courseformat/content/section/controlmenu.php +++ b/classes/output/courseformat/content/section/controlmenu.php @@ -43,7 +43,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class controlmenu extends controlmenu_base { - /** @var course_format the course format class */ protected $format; @@ -120,8 +119,10 @@ public function section_control_items() { $tcsettings = $format->get_settings(); $controls = []; - if ((($tcsettings['layoutstructure'] == 1) || ($tcsettings['layoutstructure'] == 4)) && - $section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) { + if ( + (($tcsettings['layoutstructure'] == 1) || ($tcsettings['layoutstructure'] == 4)) && + $section->section && has_capability('moodle/course:setcurrentsection', $coursecontext) + ) { if ($course->marker == $section->section) { // Show the "light globe" on/off. $url->param('marker', 0); $highlightoff = get_string('highlightoff'); @@ -132,7 +133,7 @@ public function section_control_items() { 'pixattr' => ['class' => ''], 'attr' => [ 'class' => 'editing_highlight', - 'data-action' => 'removemarker' + 'data-action' => 'removemarker', ], ]; } else { @@ -145,7 +146,7 @@ public function section_control_items() { 'pixattr' => ['class' => ''], 'attr' => [ 'class' => 'editing_highlight', - 'data-action' => 'setmarker' + 'data-action' => 'setmarker', ], ]; } diff --git a/classes/output/format_renderer_migration_toolbox.php b/classes/output/format_renderer_migration_toolbox.php index 799db0e..eb06368 100644 --- a/classes/output/format_renderer_migration_toolbox.php +++ b/classes/output/format_renderer_migration_toolbox.php @@ -37,7 +37,6 @@ namespace format_topcoll\output; trait format_renderer_migration_toolbox { - /** * Generate a summary of the activities in a section * diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 8d59ed9..5a93740 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -42,7 +42,7 @@ use moodle_url; use section_info; -require_once($CFG->dirroot.'/course/format/lib.php'); // For course_get_format. +require_once($CFG->dirroot . '/course/format/lib.php'); // For course_get_format. class renderer extends section_renderer { use format_renderer_migration_toolbox; @@ -167,7 +167,7 @@ public function course_section_updated( * @return string HTML to output. */ protected function start_section_list() { - return html_writer::start_tag('ul', array('class' => 'ctopics')); + return html_writer::start_tag('ul', ['class' => 'ctopics']); } /** @@ -176,30 +176,30 @@ protected function start_section_list() { */ protected function start_toggle_section_list() { $classes = 'ctopics ctoggled topics'; - $attributes = array(); + $attributes = []; if (($this->mobiletheme === true) || ($this->tablettheme === true)) { $classes .= ' ctportable'; } if ($this->tcsettings['layoutcolumnorientation'] == 3) { // Dynamic columns. - $classes .= ' '.$this->get_row_class(); + $classes .= ' ' . $this->get_row_class(); } else if (!$this->userisediting) { if ($this->formatresponsive) { $style = ''; if ($this->tcsettings['layoutcolumnorientation'] == 1) { // Vertical columns. - $style .= 'width:'.$this->tccolumnwidth.'%;'; + $style .= 'width:' . $this->tccolumnwidth . '%;'; } else { $style .= 'width: 100%;'; // Horizontal columns. } if ($this->mobiletheme === false) { $classes .= ' ctlayout'; } - $style .= ' padding-left: '.$this->tccolumnpadding.'px; padding-right: '.$this->tccolumnpadding.'px;'; + $style .= ' padding-left: ' . $this->tccolumnpadding . 'px; padding-right: ' . $this->tccolumnpadding . 'px;'; $attributes['style'] = $style; } else { if ($this->tcsettings['layoutcolumnorientation'] == 1) { // Vertical columns. - $classes .= ' '.$this->get_column_class($this->tcsettings['layoutcolumns']); + $classes .= ' ' . $this->get_column_class($this->tcsettings['layoutcolumns']); } else { - $classes .= ' '.$this->get_row_class(); + $classes .= ' ' . $this->get_row_class(); } } } @@ -250,7 +250,7 @@ protected function section_right_content($section, $course, $onsectionpage, $sec if (empty($this->tcsettings)) { $this->tcsettings = $this->courseformat->get_settings(); } - $url = new moodle_url('/course/view.php', array('id' => $course->id, 'section' => $section->section)); + $url = new moodle_url('/course/view.php', ['id' => $course->id, 'section' => $section->section]); // Get the specific words from the language files. $topictext = null; if (($this->tcsettings['layoutstructure'] == 1) || ($this->tcsettings['layoutstructure'] == 4)) { @@ -261,20 +261,25 @@ protected function section_right_content($section, $course, $onsectionpage, $sec $topictext = get_string('setlayoutstructureday', 'format_topcoll'); } if ($this->tcsettings['viewsinglesectionenabled'] == 2) { - $title = get_string('viewonly', 'format_topcoll', array('sectionname' => $topictext.' '.$section->section)); + $title = get_string('viewonly', 'format_topcoll', ['sectionname' => $topictext . ' ' . $section->section]); switch ($this->tcsettings['layoutelement']) { // Toggle section x. case 1: case 3: case 5: case 8: - $o .= html_writer::link($url, - $topictext.html_writer::empty_tag('br'). - $section->section, array('title' => $title, 'class' => 'cps_centre')); + $o .= html_writer::link( + $url, + $topictext . html_writer::empty_tag('br') . + $section->section, + ['title' => $title, 'class' => 'cps_centre'] + ); break; default: - $o .= html_writer::link($url, + $o .= html_writer::link( + $url, $this->one_section_icon($title), - array('title' => $title, 'class' => 'cps_centre')); + ['title' => $title, 'class' => 'cps_centre'] + ); break; } } @@ -294,10 +299,10 @@ protected function one_section_icon($title) { if (empty($this->tconesectioniconfont)) { return $this->output->pix_icon('one_section', $title, 'format_topcoll'); } else { - $osicontext = array( + $osicontext = [ 'osifc' => $this->tconesectioniconfont, - 'osift' => $title - ); + 'osift' => $title, + ]; return $this->render_from_template('format_topcoll/onesectioniconfont', $osicontext); } } @@ -327,9 +332,9 @@ protected function section_left_content($section, $course, $onsectionpage) { case 2: case 5: case 6: - $attr = array('class' => 'cps_centre'); + $attr = ['class' => 'cps_centre']; if ($this->userisediting) { - $attr['id'] = 'tcnoid-'.$section->id; + $attr['id'] = 'tcnoid-' . $section->id; } $o .= html_writer::tag('span', $section->section, $attr); break; @@ -348,14 +353,14 @@ protected function section_left_content($section, $course, $onsectionpage) { */ protected function section_summary($section, $course, $mods) { $title = $this->courseformat->get_topcoll_section_name($course, $section, false); - $sectionsummarycontext = array( + $sectionsummarycontext = [ 'formatsummarytext' => $this->format_summary_text($section), 'rtl' => $this->rtl, 'sectionactivitysummary' => $this->section_activity_summary($section, $course, null), 'sectionavailability' => $this->section_availability($section), 'sectionno' => $section->section, - 'title' => $title - ); + 'title' => $title, + ]; $classattrextra = ''; $linkclasses = ''; @@ -379,8 +384,11 @@ protected function section_summary($section, $course, $mods) { } if ($section->uservisible) { - $title = html_writer::tag('a', $title, - array('href' => course_get_url($course, $section->section), 'class' => $linkclasses)); + $title = html_writer::tag( + 'a', + $title, + ['href' => course_get_url($course, $section->section), 'class' => $linkclasses] + ); } $sectionsummarycontext['heading'] = $this->section_heading($section, $title, 'section-title'); @@ -391,7 +399,7 @@ protected function section_summary_container($section) { $summarytext = $this->format_summary_text($section); if ($summarytext) { $classextra = ($this->tcsettings['showsectionsummary'] == 1) ? '' : ' summaryalwaysshown'; - $o = html_writer::start_tag('div', array('class' => 'summary' . $classextra)); + $o = html_writer::start_tag('div', ['class' => 'summary' . $classextra]); $o .= $this->format_summary_text($section); $o .= html_writer::end_tag('div'); } else { @@ -413,13 +421,13 @@ protected function section_summary_container($section) { protected function topcoll_section($section, $course, $onsectionpage, $sectionreturn = null) { $context = context_course::instance($course->id); - $sectioncontext = array( + $sectioncontext = [ 'rtl' => $this->rtl, 'sectionid' => $section->id, 'sectionno' => $section->section, 'sectionreturn' => $sectionreturn, - 'editing' => $this->userisediting - ); + 'editing' => $this->userisediting, + ]; if ($section->section != 0) { // Only in the non-general sections. @@ -502,7 +510,7 @@ protected function topcoll_section($section, $course, $onsectionpage, $sectionre $sectioncontext['usereditingicon'] = $this->output->pix_icon('t/edit', get_string('edit')); $sectioncontext['usereditingurl'] = new moodle_url( '/course/editsection.php', - array('id' => $section->id, 'sr' => $sectionreturn) + ['id' => $section->id, 'sr' => $sectionreturn] ); } @@ -547,12 +555,12 @@ protected function add_section_visibility_data(array &$data, $section, $courseco } protected function section_heading($section, $title, $classes = '') { - $attributes = array( + $attributes = [ 'data-for' => 'section_title', 'data-id' => $section->id, 'data-number' => $section->section, - 'id' => "sectionid-{$section->id}-title" - ); + 'id' => "sectionid-{$section->id}-title", + ]; if (!empty($classes)) { $attributes['class'] = $classes; } @@ -567,10 +575,10 @@ protected function section_heading($section, $title, $classes = '') { */ protected function toggle_icon_set(&$sectioncontext) { if ($this->tcsettings['toggleiconset'] == 'tif') { - $tifcontext = array( + $tifcontext = [ "tifcc" => $this->tcsettings['toggleiconfontclosed'], - "tifoc" => $this->tcsettings['toggleiconfontopen'] - ); + "tifoc" => $this->tcsettings['toggleiconfontopen'], + ]; switch ($this->tcsettings['toggleiconposition']) { case 2: $sectioncontext['tifpleft'] = false; @@ -599,15 +607,18 @@ protected function toggle_icon_set(&$sectioncontext) { * @return string HTML to output. */ protected function stealth_section($section, $course) { - $stealthsectioncontext = array( + $stealthsectioncontext = [ 'cscml' => $this->course_section_cmlist($section), - 'heading' => $this->section_heading($section, get_string('orphanedactivitiesinsectionno', '', $section->section), - 'section-title'), + 'heading' => $this->section_heading( + $section, + get_string('orphanedactivitiesinsectionno', '', $section->section), + 'section-title' + ), 'rightcontent' => $this->section_right_content($section, $course, false), 'rtl' => $this->rtl, 'sectionid' => $section->id, - 'sectionno' => $section->section - ); + 'sectionno' => $section->section, + ]; if ($this->tcsettings['layoutcolumnorientation'] == 3) { // Dynamic column layout. $stealthsectioncontext['columnclass'] = $this->get_column_class('D'); @@ -621,7 +632,11 @@ protected function stealth_section($section, $course) { $context = context_course::instance($course->id); $stealthsectioncontext['sectionvisibility'] = $this->add_section_visibility_data( - $stealthsectioncontext, $section, $context, true); + $stealthsectioncontext, + $section, + $context, + true + ); if ($this->courseformat->show_editor()) { $stealthsectioncontext['cmcontrols'] = @@ -639,11 +654,11 @@ protected function stealth_section($section, $course) { * @return string HTML to output. */ protected function section_hidden($section, $courseorid = null) { - $sectionhiddencontext = array( + $sectionhiddencontext = [ 'sectionavailability' => $this->section_availability($section), 'sectionno' => $section->section, - 'sectionid' => $section->id - ); + 'sectionid' => $section->id, + ]; $course = $this->courseformat->get_course(); if ($this->tcsettings['layoutcolumnorientation'] == 3) { // Dynamic column layout. @@ -684,8 +699,12 @@ public function single_section_page($displaysection) { if (!($thissection = $modinfo->get_section_info($displaysection))) { /* This section doesn't exist or is not available for the user. We actually already check this in course/view.php but just in case exit from this function as well. */ - print_error('unknowncoursesection', 'error', course_get_url($course), - format_string($course->fullname)); + print_error( + 'unknowncoursesection', + 'error', + course_get_url($course), + format_string($course->fullname) + ); } if (!$thissection->uservisible) { @@ -695,15 +714,15 @@ public function single_section_page($displaysection) { $maincoursepage = get_string('maincoursepage', 'format_topcoll'); - $singlesectioncontext = array( + $singlesectioncontext = [ 'maincoursepageicon' => $this->output->pix_icon('t/less', $maincoursepage), 'maincoursepagestr' => $maincoursepage, - 'maincoursepageurl' => new moodle_url('/course/view.php', array('id' => $course->id)), + 'maincoursepageurl' => new moodle_url('/course/view.php', ['id' => $course->id]), 'sectionnavlinks' => $this->section_nav_links(), // Title with section navigation links and jump to menu. 'sectionnavselection' => $this->section_nav_selection($course, null, $displaysection), - 'thissection' => $this->topcoll_section($thissection, $course, true, $displaysection) - ); + 'thissection' => $this->topcoll_section($thissection, $course, true, $displaysection), + ]; $sectionzero = $modinfo->get_section_info(0); if ($sectionzero->summary || !empty($modinfo->sections[0]) || $this->page->user_is_editing()) { @@ -755,9 +774,9 @@ public function multiple_section_page() { $shownonetoggle = false; $coursenumsections = $this->courseformat->get_last_section_number(); if ($coursenumsections > 0) { - $sectiondisplayarray = array(); + $sectiondisplayarray = []; $sectionoutput = ''; - $toggledsections = array(); + $toggledsections = []; $currentsectionfirst = false; if (($this->tcsettings['layoutstructure'] == 4) && (!$this->userisediting)) { $currentsectionfirst = true; @@ -830,7 +849,7 @@ public function multiple_section_page() { $sectionoutput .= $this->end_section_list(); if ((!$this->formatresponsive) && ($this->tcsettings['layoutcolumnorientation'] == 1)) { // Vertical columns. - $sectionoutput .= html_writer::start_tag('div', array('class' => $this->get_row_class())); + $sectionoutput .= html_writer::start_tag('div', ['class' => $this->get_row_class()]); } $sectionoutput .= $this->start_toggle_section_list(); @@ -854,8 +873,10 @@ public function multiple_section_page() { if (($currentsectionfirst == true) && ($showsection == true)) { // Show the section if we were meant to and it is the current section:.... $showsection = ($course->marker == $section); - } else if (($this->tcsettings['layoutstructure'] == 4) && - ($course->marker == $section) && (!$this->userisediting)) { + } else if ( + ($this->tcsettings['layoutstructure'] == 4) && + ($course->marker == $section) && (!$this->userisediting) + ) { $showsection = false; // Do not reshow current section. } if (!$showsection) { @@ -975,8 +996,10 @@ public function multiple_section_page() { $breakpoint = $numshownsections / $this->tcsettings['layoutcolumns']; } - if (($breaking == true) && ($shownsectioncount >= $breakpoint) && - ($columncount < $this->tcsettings['layoutcolumns'])) { + if ( + ($breaking == true) && ($shownsectioncount >= $breakpoint) && + ($columncount < $this->tcsettings['layoutcolumns']) + ) { $sectionoutput .= $this->end_section_list(); $sectionoutput .= $this->start_toggle_section_list(); $columncount++; @@ -1043,7 +1066,7 @@ public function multiple_section_page() { // Now initialise the JavaScript. $toggles = $this->togglelib->get_toggles(); - $this->page->requires->js_init_call('M.format_topcoll.init', array( + $this->page->requires->js_init_call('M.format_topcoll.init', [ $course->id, $toggles, $coursenumsections, @@ -1051,10 +1074,10 @@ public function multiple_section_page() { $this->defaultuserpreference, ((!$this->userisediting) && ($this->tcsettings['onesection'] == 2)), $shownonetoggle, - $this->userisediting)); + $this->userisediting, ]); /* Make sure the database has the correct state of the toggles if changed by the code. This ensures that a no-change page reload is correct. */ - set_user_preference('topcoll_toggle_'.$course->id, $toggles); + set_user_preference('topcoll_toggle_' . $course->id, $toggles); return $content; } @@ -1067,22 +1090,22 @@ public function multiple_section_page() { */ protected function toggle_all($toggledsections) { $sct = $this->courseformat->get_structure_collection_type(); - $toggleallcontext = array( + $toggleallcontext = [ 'rtl' => $this->rtl, 'sctcloseall' => get_string('sctcloseall', 'format_topcoll', $sct), 'sctopenall' => get_string('sctopenall', 'format_topcoll', $sct), 'toggleallhover' => ($this->tcsettings['toggleallhover'] == 2), - 'tctoggleiconsize' => $this->tctoggleiconsize - ); + 'tctoggleiconsize' => $this->tctoggleiconsize, + ]; $this->toggle_icon_set($toggleallcontext); if ((($this->mobiletheme === false) && ($this->tablettheme === false)) || ($this->userisediting)) { $toggleallcontext['spacer'] = $this->output->spacer(); } - $ariacontrolselements = array(); + $ariacontrolselements = []; foreach ($toggledsections as $toggledsection) { - $ariacontrolselements[] = 'toggledsection-'.$toggledsection; + $ariacontrolselements[] = 'toggledsection-' . $toggledsection; } $toggleallcontext['ariacontrols'] = implode(' ', $ariacontrolselements); @@ -1094,9 +1117,9 @@ protected function toggle_all($toggledsections) { * @return string HTML to output. */ protected function display_instructions() { - $displayinstructionscontext = array( - 'rtl' => $this->rtl - ); + $displayinstructionscontext = [ + 'rtl' => $this->rtl, + ]; if ((($this->mobiletheme === false) && ($this->tablettheme === false)) || ($this->userisediting)) { $displayinstructionscontext['spacer'] = $this->output->spacer(); @@ -1114,17 +1137,21 @@ protected function course_styles() { $this->tcsettings = $this->courseformat->get_settings(); } - $coursestylescontext = array(); + $coursestylescontext = []; $coursestylescontext['togglebackground'] = \format_topcoll\toolbox::hex2rgba( - $this->tcsettings['togglebackgroundcolour'], $this->tcsettings['togglebackgroundopacity']); + $this->tcsettings['togglebackgroundcolour'], + $this->tcsettings['togglebackgroundopacity'] + ); $coursestylescontext['toggleforegroundcolour'] = \format_topcoll\toolbox::hex2rgba( - $this->tcsettings['toggleforegroundcolour'], $this->tcsettings['toggleforegroundopacity']); + $this->tcsettings['toggleforegroundcolour'], + $this->tcsettings['toggleforegroundopacity'] + ); $coursestylescontext['tif'] = ($this->tcsettings['toggleiconset'] == 'tif'); if ($coursestylescontext['tif']) { switch ($this->tcsettings['togglealignment']) { case 1: $coursestylescontext['tiftogglealignment'] = 'start'; - break; + break; case 3: $coursestylescontext['tiftogglealignment'] = 'end'; break; @@ -1135,7 +1162,7 @@ protected function course_styles() { switch ($this->tcsettings['togglealignment']) { case 1: $coursestylescontext['togglealignment'] = 'left'; - break; + break; case 3: $coursestylescontext['togglealignment'] = 'right'; break; @@ -1152,20 +1179,25 @@ protected function course_styles() { } } $coursestylescontext['toggleforegroundhovercolour'] = \format_topcoll\toolbox::hex2rgba( - $this->tcsettings['toggleforegroundhovercolour'], $this->tcsettings['toggleforegroundhoveropacity']); + $this->tcsettings['toggleforegroundhovercolour'], + $this->tcsettings['toggleforegroundhoveropacity'] + ); $coursestylescontext['togglebackgroundhovercolour'] = \format_topcoll\toolbox::hex2rgba( - $this->tcsettings['togglebackgroundhovercolour'], $this->tcsettings['togglebackgroundhoveropacity']); + $this->tcsettings['togglebackgroundhovercolour'], + $this->tcsettings['togglebackgroundhoveropacity'] + ); $topcollsidewidth = get_string('topcollsidewidthlang', 'format_topcoll'); $topcollsidewidthdelim = strpos($topcollsidewidth, '-'); $topcollsidewidthlang = strcmp(substr($topcollsidewidth, 0, $topcollsidewidthdelim), current_language()); $topcollsidewidthval = substr($topcollsidewidth, $topcollsidewidthdelim + 1); // Dynamically changing widths with language. - if ((!$this->userisediting) && + if ( + (!$this->userisediting) && (($this->mobiletheme == false) && ($this->tablettheme == false)) && ($topcollsidewidthlang == 0) - ) { + ) { $coursestylescontext['topcollsidewidthval'] = $topcollsidewidthval; } else if ($this->userisediting) { $coursestylescontext['topcollsidewidthval'] = '40px'; @@ -1269,12 +1301,12 @@ protected function get_row_class() { } protected function get_column_class($columns) { - static $colclasses = array( + static $colclasses = [ 1 => 'col-sm-12', 2 => 'col-sm-6', 3 => 'col-md-4', 4 => 'col-lg-3', - 'D' => 'col-sm-12 col-md-12 col-lg-12 col-xl-6'); + 'D' => 'col-sm-12 col-md-12 col-lg-12 col-xl-6', ]; return $colclasses[$columns]; } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index c425319..bb009e6 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -27,8 +27,8 @@ namespace format_topcoll\privacy; -use \core_privacy\local\request\writer; -use \core_privacy\local\metadata\collection; +use core_privacy\local\request\writer; +use core_privacy\local\metadata\collection; /** * Implementation of the privacy subsystem plugin provider. @@ -39,14 +39,13 @@ class provider implements // This plugin has some sitewide user preferences to export. \core_privacy\local\request\user_preference_provider { - /** * Returns meta data about this system. * * @param collection $itemcollection The initialised item collection to add items to. * @return collection A listing of user data stored through this system. */ - public static function get_metadata(collection $items) : collection { + public static function get_metadata(collection $items): collection { $items->add_user_preference(\format_topcoll\toolbox::TOPCOLL_TOGGLE, 'privacy:metadata:preference:toggle'); return $items; @@ -59,7 +58,7 @@ public static function get_metadata(collection $items) : collection { */ public static function export_user_preferences(int $userid) { $preferences = get_user_preferences(null, null, $userid); - $togglelib = new \format_topcoll\togglelib; + $togglelib = new \format_topcoll\togglelib(); foreach ($preferences as $name => $value) { $courseid = null; if (strpos($name, \format_topcoll\toolbox::TOPCOLL_TOGGLE) === 0) { diff --git a/classes/togglelib.php b/classes/togglelib.php index 037b8a1..8587460 100644 --- a/classes/togglelib.php +++ b/classes/togglelib.php @@ -33,7 +33,6 @@ namespace format_topcoll; class togglelib { - // Digits used = ":;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxy"; // Note: An ':' is 58 Ascii so to go between six digit base 2 and this then add / subtract 58. // This has been chosen to avoid digits which are in the old method. @@ -216,12 +215,12 @@ private static function encode_value_to_character($val) { * Returns test result as HTML. */ public function test() { - $retr = '
A='.self::decode_character_to_value('A').' - back:'.self::encode_value_to_character(7).'
'; + $retr = '
A=' . self::decode_character_to_value('A') . ' - back:' . self::encode_value_to_character(7) . '
'; for ($i = 0; $i < 64; $i++) { $curr = self::encode_value_to_character($i); $val = self::decode_character_to_value($curr); $back = self::encode_value_to_character($val); - $retr .= $curr.'='.$val.'='.$back.' '; + $retr .= $curr . '=' . $val . '=' . $back . ' '; } $retr .= '
'; @@ -229,7 +228,7 @@ public function test() { $this->toggles = 'GjB'; // 001101 110000 001000 = 18 toggles. $retr .= 'Toggle string of GjB which is 001101 110000 001000 is:
'; for ($j = 1; $j <= 18; $j++) { - $retr .= 'TG: '.$j.' = '.(int)$this->get_toggle_state($j).' - '; + $retr .= 'TG: ' . $j . ' = ' . (int)$this->get_toggle_state($j) . ' - '; } $retr .= '
'; $retr .= 'Now set 5, 12, 15 (already set) and 18 and clear 3 and 7 is:
'; @@ -240,7 +239,7 @@ public function test() { $this->set_toggle_state(3, false); $this->set_toggle_state(7, false); for ($j = 1; $j <= 18; $j++) { - $retr .= 'TG: '.$j.' = '.(int)$this->get_toggle_state($j).' - '; + $retr .= 'TG: ' . $j . ' = ' . (int)$this->get_toggle_state($j) . ' - '; } $retr .= '
'; @@ -291,4 +290,3 @@ public static function clean_topcoll_param($param) { return $param; } } - diff --git a/classes/toolbox.php b/classes/toolbox.php index 29740f3..8cd8840 100644 --- a/classes/toolbox.php +++ b/classes/toolbox.php @@ -34,7 +34,6 @@ namespace format_topcoll; class toolbox { - protected static $instance; const TOPCOLL_TOGGLE = 'topcoll_toggle'; @@ -60,15 +59,15 @@ private static function hex2rgb($hex) { $hex = str_replace("#", "", $hex); if (strlen($hex) == 3) { - $r = hexdec(substr($hex, 0, 1).substr($hex, 0, 1)); - $g = hexdec(substr($hex, 1, 1).substr($hex, 1, 1)); - $b = hexdec(substr($hex, 2, 1).substr($hex, 2, 1)); + $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1)); + $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1)); + $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1)); } else { $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); } - $rgb = array('r' => $r, 'g' => $g, 'b' => $b); + $rgb = ['r' => $r, 'g' => $g, 'b' => $b]; return $rgb; // Returns the rgb as an array. } @@ -82,6 +81,6 @@ private static function hex2rgb($hex) { public static function hex2rgba($hex, $alpha) { $rgba = self::hex2rgb($hex); $rgba[] = $alpha; - return 'rgba('.implode(", ", $rgba).')'; // Returns the rgba values separated by commas. + return 'rgba(' . implode(", ", $rgba) . ')'; // Returns the rgba values separated by commas. } } diff --git a/db/access.php b/db/access.php index 391fbc0..503dce3 100644 --- a/db/access.php +++ b/db/access.php @@ -33,49 +33,49 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( - 'format/topcoll:changelayout' => array( +$capabilities = [ + 'format/topcoll:changelayout' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'format/topcoll:changecolour' => array( + 'format/topcoll:changecolour' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'format/topcoll:changetogglealignment' => array( + 'format/topcoll:changetogglealignment' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'format/topcoll:changetoggleiconset' => array( + 'format/topcoll:changetoggleiconset' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'format/topcoll:changeactivitymeta' => array( + 'format/topcoll:changeactivitymeta' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ) -); + 'manager' => CAP_ALLOW, + ], + ], +]; diff --git a/db/caches.php b/db/caches.php index e5d4eb7..b2aea3e 100644 --- a/db/caches.php +++ b/db/caches.php @@ -34,34 +34,34 @@ defined('MOODLE_INTERNAL') || die; -$definitions = array( +$definitions = [ // Caches student roles. - 'activitystudentrolescache' => array( + 'activitystudentrolescache' => [ 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, 'staticacceleration' => true, - 'staticaccelerationsize' => 2 - ), + 'staticaccelerationsize' => 2, + ], // Caches the number of 'students' who can access a given module on a given course. - 'activitymodulecountcache' => array( + 'activitymodulecountcache' => [ 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, - 'staticacceleration' => true - ), + 'staticacceleration' => true, + ], // Caches the ids of the 'students' on a given course. - 'activitystudentscache' => array( + 'activitystudentscache' => [ 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, - 'staticacceleration' => true - ), + 'staticacceleration' => true, + ], // Caches the ids of the new users on a given course. - 'activityusercreatedcache' => array( + 'activityusercreatedcache' => [ 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, - 'staticacceleration' => true - ) -); + 'staticacceleration' => true, + ], +]; diff --git a/db/events.php b/db/events.php index 61a5420..51d86bb 100644 --- a/db/events.php +++ b/db/events.php @@ -35,46 +35,46 @@ defined('MOODLE_INTERNAL') || die(); // List of observers. -$observers = array( +$observers = [ - array( + [ 'eventname' => '\core\event\course_content_deleted', 'callback' => 'format_topcoll_observer::course_content_deleted', - ), - array( + ], + [ 'eventname' => '\core\event\role_allow_view_updated', 'callback' => 'format_topcoll_observer::role_allow_view_updated', - ), - array( + ], + [ 'eventname' => '\core\event\role_updated', 'callback' => 'format_topcoll_observer::role_updated', - ), - array( + ], + [ 'eventname' => '\core\event\role_deleted', 'callback' => 'format_topcoll_observer::role_deleted', - ), - array( + ], + [ 'eventname' => '\core\event\user_enrolment_created', 'callback' => 'format_topcoll_observer::user_enrolment_created', - ), - array( + ], + [ 'eventname' => '\core\event\user_enrolment_updated', 'callback' => 'format_topcoll_observer::user_enrolment_updated', - ), - array( + ], + [ 'eventname' => '\core\event\user_enrolment_deleted', 'callback' => 'format_topcoll_observer::user_enrolment_deleted', - ), - array( + ], + [ 'eventname' => '\core\event\course_module_created', 'callback' => 'format_topcoll_observer::course_module_created', - ), - array( + ], + [ 'eventname' => '\core\event\course_module_updated', 'callback' => 'format_topcoll_observer::course_module_updated', - ), - array( + ], + [ 'eventname' => '\core\event\course_module_deleted', 'callback' => 'format_topcoll_observer::course_module_deleted', - ) -); + ], +]; diff --git a/db/upgrade.php b/db/upgrade.php index 64735d1..f962ac1 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -61,7 +61,7 @@ function xmldb_format_topcoll_upgrade($oldversion = 0) { $table->add_field('layoutstructure', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', null); // Adding key. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Create table. $dbman->create_table($table); @@ -144,7 +144,7 @@ function xmldb_format_topcoll_upgrade($oldversion = 0) { $records = $DB->get_records($table->getName()); foreach ($records as $record) { // Check that the course still exists - CONTRIB-4065... - if ($DB->record_exists('course', array('id' => $record->courseid))) { + if ($DB->record_exists('course', ['id' => $record->courseid])) { $courseformat = course_get_format($record->courseid); // In '/course/format/lib.php'. /* Only update if the current format is 'topcoll' as we must have an instance of 'format_topcoll' (in 'lib.php') returned by the above. Thanks to Marina Glancy for this :). @@ -153,9 +153,15 @@ function xmldb_format_topcoll_upgrade($oldversion = 0) { code desires entries in the course_format_settings table for courses of a format that belong to another format. */ if ($courseformat->get_format() == 'topcoll') { - $courseformat->restore_topcoll_setting($record->courseid, $record->layoutelement, $record->layoutstructure, - $record->layoutcolumns, $record->tgfgcolour, $record->tgbgcolour, - $record->tgbghvrcolour); // In '/course/format/topcoll/lib.php'. + $courseformat->restore_topcoll_setting( + $record->courseid, + $record->layoutelement, + $record->layoutstructure, + $record->layoutcolumns, + $record->tgfgcolour, + $record->tgbgcolour, + $record->tgbghvrcolour + ); // In '/course/format/topcoll/lib.php'. } } } @@ -165,7 +171,6 @@ function xmldb_format_topcoll_upgrade($oldversion = 0) { } if ($oldversion < 2017110301) { - /* During upgrade to Moodle 3.3 it could happen that general section (section 0) became 'invisible'. It should always be visible. */ $DB->execute("UPDATE {course_sections} SET visible=1 WHERE visible=0 AND section=0 AND course IN @@ -176,7 +181,7 @@ function xmldb_format_topcoll_upgrade($oldversion = 0) { if ($oldversion < 2020110902) { // Only upgrade if M3.9 version has not already done this. - if (!$DB->record_exists('config_plugins', array('plugin' => 'format_topcoll', 'name' => 'defaulttoggleforegroundcolour'))) { + if (!$DB->record_exists('config_plugins', ['plugin' => 'format_topcoll', 'name' => 'defaulttoggleforegroundcolour'])) { // Change in default names. $value = get_config('format_topcoll', 'defaulttgfgcolour'); set_config('defaulttoggleforegroundcolour', $value, 'format_topcoll'); diff --git a/format.php b/format.php index 57ca9f5..8193bc2 100644 --- a/format.php +++ b/format.php @@ -74,10 +74,10 @@ $renderer = $PAGE->get_renderer('format_topcoll'); $content = ''; -$contentcontext = array( +$contentcontext = [ 'title' => $courseformat->page_title(), - 'userisediting' => $PAGE->user_is_editing() -); + 'userisediting' => $PAGE->user_is_editing(), +]; if (!empty($displaysection)) { $courseformat->set_section_number($displaysection); $content = $renderer->single_section_page($displaysection); diff --git a/js/tc_colourpopup.php b/js/tc_colourpopup.php index b9147a0..4816328 100644 --- a/js/tc_colourpopup.php +++ b/js/tc_colourpopup.php @@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; -require_once($CFG->dirroot."/lib/pear/HTML/QuickForm/text.php"); +require_once($CFG->dirroot . "/lib/pear/HTML/QuickForm/text.php"); /** * HTML class for a colour popup type element @@ -70,7 +70,7 @@ public function toHtml() { global $PAGE; $id = $this->getAttribute('id'); $PAGE->requires->js('/course/format/topcoll/js/tc_colourpopup.js'); - $PAGE->requires->js_init_call('M.util.init_tccolour_popup', array($id)); + $PAGE->requires->js_init_call('M.util.init_tccolour_popup', [$id]); $value = $this->getValue(); if (!empty($value)) { if ($value[0] == '#') { @@ -84,19 +84,18 @@ public function toHtml() { $value = '-'; $colour = $this->getAttribute('defaultcolour'); } - $content = "_getAttrString($this->_attributes) . " >"; - $content .= html_writer::tag('span', ' ', array( - 'id' => 'colpicked_'.$id, + $content .= html_writer::tag('span', ' ', [ + 'id' => 'colpicked_' . $id, 'class' => 'tccolourpopupbox', 'tabindex' => '-1', - 'style' => 'background-color: #'.$colour.';') - ); - $content .= html_writer::start_tag('div', array( + 'style' => 'background-color: #' . $colour . ';', ]); + $content .= html_writer::start_tag('div', [ 'id' => 'colpick_' . $id, 'style' => "display: none;", - 'class' => 'tccolourpopupsel form-colourpicker defaultsnext')); - $content .= html_writer::tag('div', '', array('class' => 'admin_colourpicker clearfix')); + 'class' => 'tccolourpopupsel form-colourpicker defaultsnext', ]); + $content .= html_writer::tag('div', '', ['class' => 'admin_colourpicker clearfix']); $content .= html_writer::end_tag('div'); return $content; } @@ -114,7 +113,7 @@ public function _generateId() { static $idx = 1; if (!$this->getAttribute('id')) { - $this->updateAttributes(array('id' => 'id_' . substr(md5(microtime() . $idx++), 0, 6))); + $this->updateAttributes(['id' => 'id_' . substr(md5(microtime() . $idx++), 0, 6)]); } } diff --git a/lang/en_us/format_topcoll.php b/lang/en_us/format_topcoll.php index 0504916..0afa4f6 100644 --- a/lang/en_us/format_topcoll.php +++ b/lang/en_us/format_topcoll.php @@ -66,4 +66,3 @@ // Capabilities. $string['topcoll:changecolour'] = 'Change or reset the color'; - diff --git a/lib.php b/lib.php index 7c8ecf9..ea5a824 100644 --- a/lib.php +++ b/lib.php @@ -81,10 +81,12 @@ public function get_settings() { foreach ($this->settings as $settingname => $settingvalue) { if (isset($settingvalue)) { $settingvtype = gettype($settingvalue); - if ((($settingvtype == 'string') && ($settingvalue === '-')) || - (($settingvtype == 'integer') && ($settingvalue === 0))) { + if ( + (($settingvtype == 'string') && ($settingvalue === '-')) || + (($settingvtype == 'integer') && ($settingvalue === 0)) + ) { // Default value indicator is a hyphen or a number equal to 0. - $this->settings[$settingname] = get_config('format_topcoll', 'default'.$settingname); + $this->settings[$settingname] = get_config('format_topcoll', 'default' . $settingname); } } } @@ -172,7 +174,7 @@ public function get_default_section_name($section) { public function get_topcoll_section_name($course, $section, $additional) { $thesection = $this->get_section($section); if (is_null($thesection)) { - $thesection = new stdClass; + $thesection = new stdClass(); $thesection->name = ''; if (is_object($section)) { $thesection->section = $section->section; @@ -188,9 +190,11 @@ public function get_topcoll_section_name($course, $section, $additional) { // We can't add a node without any text. if ((string) $thesection->name !== '') { - $o .= format_string($thesection->name, true, array('context' => $context)); - if (($thesection->section != 0) && (($tcsettings['layoutstructure'] == 2) || - ($tcsettings['layoutstructure'] == 3) || ($tcsettings['layoutstructure'] == 5))) { + $o .= format_string($thesection->name, true, ['context' => $context]); + if ( + ($thesection->section != 0) && (($tcsettings['layoutstructure'] == 2) || + ($tcsettings['layoutstructure'] == 3) || ($tcsettings['layoutstructure'] == 5)) + ) { $o .= ' '; if (empty($tcsectionsettings['donotshowdate'])) { if ($additional == true) { // Break 'br' tags break backups! @@ -223,7 +227,7 @@ public function get_topcoll_section_name($course, $section, $additional) { case 3: case 4: // The word 'Toggle'. - $o .= '- ';
$this->assertEquals($thevalue, $theclass);
@@ -135,8 +139,11 @@ public function test_start_section_list() {
public function test_start_toggle_section_list() {
// With defaults unchanged.
$this->init();
- $theclass = self::call_method($this->outputus, 'start_toggle_section_list',
- array());
+ $theclass = self::call_method(
+ $this->outputus,
+ 'start_toggle_section_list',
+ []
+ );
$thevalue = '
- ';
$this->assertEquals($thevalue, $theclass);
@@ -145,7 +152,7 @@ public function test_start_toggle_section_list() {
public function test_page_title() {
// With defaults unchanged.
$this->init();
- $theclass = self::call_method($this->outputus, 'page_title', array());
+ $theclass = self::call_method($this->outputus, 'page_title', []);
$thevalue = 'Section';
$this->assertEquals($thevalue, $theclass);
@@ -158,15 +165,21 @@ public function test_section_right_content() {
$this->init();
$section = $this->courseformat->get_section(1);
$onsectionpage = false;
- $theclass = self::call_method($this->outputus, 'section_right_content',
- array($section, $this->course, $onsectionpage));
+ $theclass = self::call_method(
+ $this->outputus,
+ 'section_right_content',
+ [$section, $this->course, $onsectionpage]
+ );
$thevalue = 'wwwroot.'/course/view.php?id='.$this->course->id.'§ion=1">Topic
1'; + $thevalue .= 'href="' . $CFG->wwwroot . '/course/view.php?id=' . $this->course->id . '§ion=1">Topic
1'; $this->assertEquals($thevalue, $theclass); $onsectionpage = true; - $theclass = self::call_method($this->outputus, 'section_right_content', - array($section, $this->course, $onsectionpage)); + $theclass = self::call_method( + $this->outputus, + 'section_right_content', + [$section, $this->course, $onsectionpage] + ); $thevalue = ''; $this->assertEquals($thevalue, $theclass); } @@ -175,14 +188,20 @@ public function test_section_left_content() { $this->init(); $section = $this->courseformat->get_section(1); $onsectionpage = false; - $theclass = self::call_method($this->outputus, 'section_left_content', - array($section, $this->course, $onsectionpage)); + $theclass = self::call_method( + $this->outputus, + 'section_left_content', + [$section, $this->course, $onsectionpage] + ); $thevalue = '1'; $this->assertEquals($thevalue, $theclass); $onsectionpage = true; - $theclass = self::call_method($this->outputus, 'section_left_content', - array($section, $this->course, $onsectionpage)); + $theclass = self::call_method( + $this->outputus, + 'section_left_content', + [$section, $this->course, $onsectionpage] + ); $thevalue = ''; $this->assertEquals($thevalue, $theclass); } @@ -193,34 +212,43 @@ public function test_section_summary() { $this->init(); self::set_property($this->outputus, 'formatresponsive', true); $section = $this->courseformat->get_section(1); - $theclass = self::call_method($this->outputus, 'section_summary', - array($section, $this->course, null)); + $theclass = self::call_method( + $this->outputus, + 'section_summary', + [$section, $this->course, null] + ); - $sectionsummarycontext = array( - 'heading' => '
'Section 1
',
'columnwidth' => '100',
'rtl' => false,
'sectionavailability' => '',
'sectionno' => '1',
- 'title' => 'Section 1'
+ 'title' => 'Section 1',
+ ];
+ $sectionsummarycontext['formatsummarytext'] = self::call_method($this->outputus, 'format_summary_text', [$section]);
+ $sectionsummarycontext['sectionactivitysummary'] = self::call_method(
+ $this->outputus,
+ 'section_activity_summary',
+ [$section, $this->course, null]
+ );
+ $sectionsummarycontext['sectionavailability'] = self::call_method(
+ $this->outputus,
+ 'section_availability',
+ [$section]
);
- $sectionsummarycontext['formatsummarytext'] = self::call_method($this->outputus, 'format_summary_text', array($section));
- $sectionsummarycontext['sectionactivitysummary'] = self::call_method($this->outputus, 'section_activity_summary',
- array($section, $this->course, null));
- $sectionsummarycontext['sectionavailability'] = self::call_method($this->outputus, 'section_availability',
- array($section));
- $thevalue = self::call_method($this->outputus, 'render_from_template', array('format_topcoll/sectionsummary',
- $sectionsummarycontext));
+ $thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/sectionsummary',
+ $sectionsummarycontext, ]);
$this->assertEquals($thevalue, $theclass);
}
public function test_topcoll_section() {
$this->init();
- set_user_preference('topcoll_toggle_'.$this->course->id, 'Z');
+ set_user_preference('topcoll_toggle_' . $this->course->id, 'Z');
set_config('defaultuserpreference', 0, 'format_topcoll');
set_config('defaulttogglepersistence', 1, 'format_topcoll');
self::set_property($this->outputus, 'formatresponsive', false);
@@ -230,53 +258,65 @@ public function test_topcoll_section() {
$onsectionpage = false;
$sectionreturn = null;
- $theclass = self::call_method($this->outputus, 'topcoll_section',
- array($section1, $this->course, $onsectionpage));
+ $theclass = self::call_method(
+ $this->outputus,
+ 'topcoll_section',
+ [$section1, $this->course, $onsectionpage]
+ );
- $sectioncontext = array(
+ $sectioncontext = [
'columnclass' => 'col-sm-12',
'contentaria' => true,
- 'cscml' => self::call_method($this->outputus, 'course_section_cmlist', array($section1)).
- self::call_method($this->outputus, 'course_section_add_cm_control', array($this->course, $section1->section,
- $sectionreturn)),
- 'leftcontent' => self::call_method($this->outputus, 'section_left_content', array($section1, $this->course,
- $onsectionpage)),
- 'heading' => 'Section 1 - Toggle
',
'nomtore' => true,
- 'rightcontent' => self::call_method($this->outputus, 'section_right_content', array($section1, $this->course,
- $onsectionpage)),
+ 'rightcontent' => self::call_method($this->outputus, 'section_right_content', [$section1, $this->course,
+ $onsectionpage, ]),
'rtl' => false,
- 'sectionavailability' => self::call_method($this->outputus, 'section_availability', array($section1)),
+ 'sectionavailability' => self::call_method($this->outputus, 'section_availability', [$section1]),
'sectionid' => $section1->id,
'sectionno' => $section1->section,
'sectionpage' => $onsectionpage,
'sectionreturn' => $sectionreturn,
- 'sectionsummary' => self::call_method($this->outputus, 'section_summary_container', array($section1)),
+ 'sectionsummary' => self::call_method($this->outputus, 'section_summary_container', [$section1]),
'sectionsummarywhencollapsed' => false,
'toggleiconset' => 'arrow',
'toggleiconsize' => 'tc-medium',
- 'toggleopen' => $section1->toggle
- );
- $thevalue = self::call_method($this->outputus, 'render_from_template', array('format_topcoll/section', $sectioncontext));
+ 'toggleopen' => $section1->toggle,
+ ];
+ $thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/section', $sectioncontext]);
$this->assertEquals($thevalue, $theclass);
$onsectionpage = true;
self::set_property($this->outputus, 'formatresponsive', true);
- $theclass = self::call_method($this->outputus, 'topcoll_section',
- array($section1, $this->course, $onsectionpage));
+ $theclass = self::call_method(
+ $this->outputus,
+ 'topcoll_section',
+ [$section1, $this->course, $onsectionpage]
+ );
$sectioncontext['columnclass'] = '';
$sectioncontext['columnwidth'] = '';
- $sectioncontext['leftcontent'] = self::call_method($this->outputus, 'section_left_content',
- array($section1, $this->course, $onsectionpage));
- $sectioncontext['rightcontent'] = self::call_method($this->outputus, 'section_right_content',
- array($section1, $this->course, $onsectionpage));
+ $sectioncontext['leftcontent'] = self::call_method(
+ $this->outputus,
+ 'section_left_content',
+ [$section1, $this->course, $onsectionpage]
+ );
+ $sectioncontext['rightcontent'] = self::call_method(
+ $this->outputus,
+ 'section_right_content',
+ [$section1, $this->course, $onsectionpage]
+ );
$sectioncontext['sectionpage'] = $onsectionpage;
- $sectioncontext['heading'] = 'Section 1
';
+ $sectioncontext['heading'] = 'Section 1
';
- $thevalue = self::call_method($this->outputus, 'render_from_template', array('format_topcoll/section', $sectioncontext));
+ $thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/section', $sectioncontext]);
$this->assertEquals($thevalue, $theclass);
}
@@ -285,49 +325,54 @@ public function test_section_hidden() {
$section = $this->courseformat->get_section(1);
$section->visible = false;
- $theclass = self::call_method($this->outputus, 'section_hidden',
- array($section, null));
+ $theclass = self::call_method(
+ $this->outputus,
+ 'section_hidden',
+ [$section, null]
+ );
- $sectionhiddencontext = array(
+ $sectionhiddencontext = [
'columnclass' => 'col-sm-12',
- 'heading' => 'Section 1
',
'leftcontent' => '1',
'nomtore' => true,
'rightcontent' => '',
'rtl' => false,
'sectionid' => $section->id,
- 'sectionno' => '1'
- );
- $sectionhiddencontext['sectionavailability'] = self::call_method($this->outputus, 'section_availability', array($section));
+ 'sectionno' => '1',
+ ];
+ $sectionhiddencontext['sectionavailability'] = self::call_method($this->outputus, 'section_availability', [$section]);
- $thevalue = self::call_method($this->outputus, 'render_from_template', array('format_topcoll/sectionhidden',
- $sectionhiddencontext));
+ $thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/sectionhidden',
+ $sectionhiddencontext, ]);
$this->assertEquals($thevalue, $theclass);
-
}
public function test_stealth_section() {
$this->init();
$section = $this->courseformat->get_section(1);
- $theclass = self::call_method($this->outputus, 'stealth_section',
- array($section, $this->course));
+ $theclass = self::call_method(
+ $this->outputus,
+ 'stealth_section',
+ [$section, $this->course]
+ );
- $stealthsectioncontext = array(
+ $stealthsectioncontext = [
'columnclass' => 'col-sm-12',
- 'cscml' => self::call_method($this->outputus, 'course_section_cmlist', array($section)),
- 'heading' => ''.get_string('orphanedactivitiesinsectionno', '', $section->section).'
',
- 'rightcontent' => self::call_method($this->outputus, 'section_right_content', array($section, $this->course, false)),
+ 'cscml' => self::call_method($this->outputus, 'course_section_cmlist', [$section]),
+ 'heading' => '' . get_string('orphanedactivitiesinsectionno', '', $section->section) . '
',
+ 'rightcontent' => self::call_method($this->outputus, 'section_right_content', [$section, $this->course, false]),
'rtl' => false,
'sectionid' => $section->id,
'sectionno' => $section->section,
- 'sectionvisibility' => true
- );
+ 'sectionvisibility' => true,
+ ];
- $thevalue = self::call_method($this->outputus, 'render_from_template', array('format_topcoll/stealthsection',
- $stealthsectioncontext));
+ $thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/stealthsection',
+ $stealthsectioncontext, ]);
$this->assertEquals($thevalue, $theclass);
}
@@ -388,20 +433,20 @@ public function test_multiple_section_page_horizontal() {
global $CFG;
$this->init();
- set_user_preference('topcoll_toggle_'.$this->course->id, null);
+ set_user_preference('topcoll_toggle_' . $this->course->id, null);
set_config('defaultuserpreference', 0, 'format_topcoll');
set_config('defaulttogglepersistence', 1, 'format_topcoll');
$section0 = $this->courseformat->get_section(0);
$section1 = $this->courseformat->get_section(1);
$section1->toggle = false;
- $thevalue = self::call_method($this->outputus, 'multiple_section_page', array());
+ $thevalue = self::call_method($this->outputus, 'multiple_section_page', []);
- $theoutput = file_get_contents($CFG->dirroot.'/course/format/topcoll/tests/phpu_data/test_multiple_section_page_css.txt');
+ $theoutput = file_get_contents($CFG->dirroot . '/course/format/topcoll/tests/phpu_data/test_multiple_section_page_css.txt');
$theoutput .= '';
- $theoutput .= self::call_method($this->outputus, 'topcoll_section', array($section0, $this->course, false, 0));
+ $theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section0, $this->course, false, 0]);
$theoutput .= '
';
- $theoutput .= self::call_method($this->outputus, 'topcoll_section', array($section1, $this->course, false));
+ $theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section1, $this->course, false]);
$theoutput .= '
';
$this->assertEquals($thevalue, $theoutput);
@@ -411,7 +456,7 @@ public function test_multiple_section_page_vertical() {
global $CFG;
$this->init(1, 1);
- set_user_preference('topcoll_toggle_'.$this->course->id, 'Z');
+ set_user_preference('topcoll_toggle_' . $this->course->id, 'Z');
set_config('defaultuserpreference', 0, 'format_topcoll');
set_config('defaulttogglepersistence', 1, 'format_topcoll');
@@ -419,14 +464,14 @@ public function test_multiple_section_page_vertical() {
$section1 = $this->courseformat->get_section(1);
$section1->toggle = true;
- $thevalue = self::call_method($this->outputus, 'multiple_section_page', array());
+ $thevalue = self::call_method($this->outputus, 'multiple_section_page', []);
- $theoutput = file_get_contents($CFG->dirroot.'/course/format/topcoll/tests/phpu_data/test_multiple_section_page_css.txt');
+ $theoutput = file_get_contents($CFG->dirroot . '/course/format/topcoll/tests/phpu_data/test_multiple_section_page_css.txt');
$theoutput .= '';
- $theoutput .= self::call_method($this->outputus, 'topcoll_section', array($section0, $this->course, false, 0));
+ $theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section0, $this->course, false, 0]);
$theoutput .= '
';
$theoutput .= '';
- $theoutput .= self::call_method($this->outputus, 'topcoll_section', array($section1, $this->course, false));
+ $theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section1, $this->course, false]);
$theoutput .= '
';
$this->assertEquals($thevalue, $theoutput);
@@ -436,16 +481,16 @@ public function test_multiple_section_page_no_sections() {
global $CFG;
$this->init(0);
- set_user_preference('topcoll_toggle_'.$this->course->id, null);
+ set_user_preference('topcoll_toggle_' . $this->course->id, null);
set_config('defaultuserpreference', 0, 'format_topcoll');
set_config('defaulttogglepersistence', 1, 'format_topcoll');
$section0 = $this->courseformat->get_section(0);
- $thevalue = self::call_method($this->outputus, 'multiple_section_page', array());
+ $thevalue = self::call_method($this->outputus, 'multiple_section_page', []);
- $theoutput = file_get_contents($CFG->dirroot.'/course/format/topcoll/tests/phpu_data/test_multiple_section_page_css.txt');
+ $theoutput = file_get_contents($CFG->dirroot . '/course/format/topcoll/tests/phpu_data/test_multiple_section_page_css.txt');
$theoutput .= '';
- $theoutput .= self::call_method($this->outputus, 'topcoll_section', array($section0, $this->course, false, 0));
+ $theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section0, $this->course, false, 0]);
$theoutput .= '
';
$this->assertEquals($thevalue, $theoutput);
@@ -455,23 +500,23 @@ public function test_toggle_all() {
global $CFG;
$this->init();
- $theclass = self::call_method($this->outputus, 'toggle_all', array(array(1)));
+ $theclass = self::call_method($this->outputus, 'toggle_all', [[1]]);
- $toggleallcontext = array(
+ $toggleallcontext = [
'ariacontrols' => 'toggledsection-1',
'toggleiconset' => 'arrow',
'rtl' => false,
'sctcloseall' => 'Close all topics',
'sctopenall' => 'Open all topics',
- 'spacer' => '',
'toggleallhover' => true,
'tctoggleiconsize' => 'tc-medium',
- 'togglepos' => 'left'
+ 'togglepos' => 'left',
- );
- $thevalue = self::call_method($this->outputus, 'render_from_template', array('format_topcoll/toggleall',
- $toggleallcontext));
+ ];
+ $thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/toggleall',
+ $toggleallcontext, ]);
$this->assertEquals($thevalue, $theclass);
}
@@ -480,15 +525,15 @@ public function test_display_instructions() {
global $CFG;
$this->init();
- $theclass = self::call_method($this->outputus, 'display_instructions', array());
+ $theclass = self::call_method($this->outputus, 'display_instructions', []);
- $displayinstructionscontext = array(
+ $displayinstructionscontext = [
'rtl' => false,
- 'spacer' => '',
- );
- $thevalue = self::call_method($this->outputus, 'render_from_template', array('format_topcoll/displayinstructions',
- $displayinstructionscontext));
+ ];
+ $thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/displayinstructions',
+ $displayinstructionscontext, ]);
$this->assertEquals($thevalue, $theclass);
}
diff --git a/tests/courseformattoolbox_test.php b/tests/courseformattoolbox_test.php
index c7453bc..d43ad6d 100644
--- a/tests/courseformattoolbox_test.php
+++ b/tests/courseformattoolbox_test.php
@@ -32,7 +32,6 @@
* @group format_topcoll
*/
class courseformattoolbox_test extends \advanced_testcase {
-
protected function setUp(): void {
$this->resetAfterTest(true);
@@ -40,7 +39,8 @@ protected function setUp(): void {
}
public function test_hex2rgba() {
- $theoutput = \format_topcoll\toolbox::hex2rgba('ffaabb', '0.8');;
+ $theoutput = \format_topcoll\toolbox::hex2rgba('ffaabb', '0.8');
+ ;
$thevalue = 'rgba(255, 170, 187, 0.8)';
$this->assertEquals($thevalue, $theoutput);
diff --git a/tests/privacy_provider_test.php b/tests/privacy_provider_test.php
index 0cda13f..6371249 100644
--- a/tests/privacy_provider_test.php
+++ b/tests/privacy_provider_test.php
@@ -27,16 +27,15 @@
namespace format_topcoll;
-use \core_privacy\local\metadata\collection;
-use \core_privacy\local\request\writer;
-use \format_topcoll\privacy\provider;
+use core_privacy\local\metadata\collection;
+use core_privacy\local\request\writer;
+use format_topcoll\privacy\provider;
/**
* Privacy unit tests for the Collapsed Topics course format.
* @group format_topcoll
*/
class privacy_provider_test extends \core_privacy\tests\provider_testcase {
-
protected $outputus;
protected $course;
protected $courseformat;
@@ -78,8 +77,10 @@ protected function set_up() {
global $PAGE;
$this->outputus = $PAGE->get_renderer('format_topcoll');
// Ref: https://docs.moodle.org/dev/Writing_PHPUnit_tests.
- $this->course = $this->getDataGenerator()->create_course(array('format' => 'topcoll', 'numsections' => $this->numsections),
- array('createsections' => true));
+ $this->course = $this->getDataGenerator()->create_course(
+ ['format' => 'topcoll', 'numsections' => $this->numsections],
+ ['createsections' => true]
+ );
$this->courseformat = course_get_format($this->course);
self::set_property($this->outputus, 'courseformat', $this->courseformat);
@@ -116,12 +117,12 @@ public function test_export_user_preferences_no_pref() {
* Ensure that export_user_preferences returns request data.
*/
public function test_export_user_preferences() {
- $togglelib = new \format_topcoll\togglelib;
+ $togglelib = new \format_topcoll\togglelib();
$this->set_up();
$this->setAdminUser();
- set_user_preference('topcoll_toggle_'.$this->course->id, 'FAB');
+ set_user_preference('topcoll_toggle_' . $this->course->id, 'FAB');
$user = \core_user::get_user_by_username('admin');
provider::export_user_preferences($user->id);
@@ -134,7 +135,7 @@ public function test_export_user_preferences() {
$this->assertCount(1, $prefs);
- $toggle = $prefs['topcoll_toggle_'.$this->course->id];
+ $toggle = $prefs['topcoll_toggle_' . $this->course->id];
$this->assertEquals('FAB', $toggle->value);
$description = get_string('privacy:request:preference:toggle', 'format_topcoll', (object) [
diff --git a/tests/togglelib_test.php b/tests/togglelib_test.php
index f8cb131..2b16bdb 100644
--- a/tests/togglelib_test.php
+++ b/tests/togglelib_test.php
@@ -32,9 +32,8 @@
* @group format_topcoll
*/
class togglelib_test extends \advanced_testcase {
-
public function test_decode_toggle_state() {
- $togglelib = new \format_topcoll\togglelib;
+ $togglelib = new \format_topcoll\togglelib();
$mindigit = $togglelib->get_min_digit();
$maxdigit = $togglelib->get_max_digit();
@@ -52,22 +51,24 @@ public function test_decode_toggle_state() {
$testval = 0;
while ($currentouterdigit != $maxdigit) {
while ($currentinnerdigit != $maxdigit) {
- $this->assertEquals(sprintf('%012d', decbin($testval)),
- $togglelib->decode_toggle_state($currentouterdigit.$currentinnerdigit));
+ $this->assertEquals(
+ sprintf('%012d', decbin($testval)),
+ $togglelib->decode_toggle_state($currentouterdigit . $currentinnerdigit)
+ );
$currentinnerdigit = chr(ord($currentinnerdigit) + 1);
$testval++;
}
- $this->assertEquals(sprintf('%012d', decbin($testval)), $togglelib->decode_toggle_state($currentouterdigit.$maxdigit));
+ $this->assertEquals(sprintf('%012d', decbin($testval)), $togglelib->decode_toggle_state($currentouterdigit . $maxdigit));
$testval++;
$currentinnerdigit = $mindigit;
$currentouterdigit = chr(ord($currentouterdigit) + 1);
}
$currentinnerdigit = $mindigit;
while ($currentinnerdigit != $maxdigit) {
- $this->assertEquals(sprintf('%012d', decbin($testval)), $togglelib->decode_toggle_state($maxdigit.$currentinnerdigit));
+ $this->assertEquals(sprintf('%012d', decbin($testval)), $togglelib->decode_toggle_state($maxdigit . $currentinnerdigit));
$currentinnerdigit = chr(ord($currentinnerdigit) + 1);
$testval++;
}
- $this->assertEquals(sprintf('%012d', decbin($testval)), $togglelib->decode_toggle_state($maxdigit.$maxdigit));
+ $this->assertEquals(sprintf('%012d', decbin($testval)), $togglelib->decode_toggle_state($maxdigit . $maxdigit));
}
}
diff --git a/version.php b/version.php
index ec65b21..8083eff 100644
--- a/version.php
+++ b/version.php
@@ -36,6 +36,6 @@
$plugin->version = 2023042402;
$plugin->maturity = MATURITY_STABLE;
$plugin->requires = 2023042400.00; // 4.2 (Build: 20230424).
-$plugin->supported = array(402, 402);
+$plugin->supported = [402, 402];
$plugin->component = 'format_topcoll';
$plugin->release = '402.1.2';
From 1f8fe10bb376119acc941468dcf3f8530e62626c Mon Sep 17 00:00:00 2001
From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com>
Date: Sat, 7 Oct 2023 19:24:23 +0100
Subject: [PATCH 26/31] M4.3
---
.github/workflows/ci.yml | 9 ++++-----
Readme.md | 14 +++++++-------
Support.md | 8 ++++----
settings.php | 2 +-
version.php | 8 ++++----
5 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index cc0b96a..9c068e4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -21,10 +21,9 @@ jobs:
strategy:
fail-fast: false
matrix:
- include:
- - php: 8.0
- moodle-branch: 'MOODLE_402_STABLE'
- database: mariadb
+ php: ['8.0', '8.2']
+ moodle-branch: ['MOODLE_403_STABLE']
+ database: [mariadb]
steps:
- name: Check out repository code
@@ -42,7 +41,7 @@ jobs:
- name: Initialise moodle-plugin-ci
run: |
- composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
+ composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
diff --git a/Readme.md b/Readme.md
index 33298fc..ec1a22e 100644
--- a/Readme.md
+++ b/Readme.md
@@ -3,29 +3,29 @@
Topic based course format with an individual 'toggle' for each topic except 0.
This file contains general information about the format. If you're reading this as an educator then you can learn about the format
-from the documentation on http://docs.moodle.org/402/en/Collapsed_Topics_course_format. If you get stuck and your Moodle support
+from the documentation on http://docs.moodle.org/403/en/Collapsed_Topics_course_format. If you get stuck and your Moodle support
are unable to help / not sure what to do, then please go to https://moodle.org/mod/forum/view.php?id=47. If you like the format,
then please do spread the word to other educators. The main page for the format is https://moodle.org/plugins/format_topcoll.
Required version of Moodle
==========================
-This version works with Moodle 4.2 version 2023042400.00 (Build: 20230424) and above within the MOODLE_402_STABLE branch until the
+This version works with Moodle 4.3 version 2023100900.00 (Build: 20231009) and above within the MOODLE_403_STABLE branch until the
next release.
-Please ensure that your hardware and software complies with 'Requirements' in '[Installing Moodle](https://docs.moodle.org/402/en/Installing_Moodle)'.
+Please ensure that your hardware and software complies with 'Requirements' in '[Installing Moodle](https://docs.moodle.org/403/en/Installing_Moodle)'.
Downloads and documentation
===========================
The primary source for downloading this branch of the format is https://moodle.org/plugins/view.php?plugin=format_topcoll
-with 'Select Moodle version:' set at 'Moodle 4.2'.
+with 'Select Moodle version:' set at 'Moodle 4.3'.
-The secondary source is a tagged version with the V402 prefix on https://github.com/gjb2048/moodle-format_topcoll/tags
+The secondary source is a tagged version with the V403 prefix on https://github.com/gjb2048/moodle-format_topcoll/tags
If you download from the development area - https://github.com/gjb2048/moodle-format_topcoll/ - consider that
the code is unstable and not for use in production environments. This is because I develop the next version in stages
and use GitHub as a means of backup. Therefore the code is not finished, subject to alteration and requires testing.
-Documented on http://docs.moodle.org/402/en/Collapsed_Topics_course_format
+Documented on http://docs.moodle.org/403/en/Collapsed_Topics_course_format
Free software
=============
@@ -275,6 +275,6 @@ Developed and maintained by
G J Barnard MSc. BSc(Hons)(Sndw). MBCS. CEng. CITP. PGCE.
- Moodle profile | [Moodle.org](https://moodle.org/user/profile.php?id=442195)
-- @gjbarnard | [Twitter](https://twitter.com/gjbarnard)
+- @gjbarnard | [X](https://twitter.com/gjbarnard)
- Web profile | [About.me](https://about.me/gjbarnard)
- Website | [Website](https://gjbarnard.co.uk)
diff --git a/Support.md b/Support.md
index d37e8be..b8643de 100644
--- a/Support.md
+++ b/Support.md
@@ -19,7 +19,7 @@ If you'd like to sponsor, get support or fund improvements, then please do get i
- gjbarnard | Gmail dt com address.
- GitHub | Please outline your issue / improvement on '[GitHub](https://github.com/gjb2048/moodle-format_topcoll/issues)'.
-- @gjbarnard | '[Twitter](https://twitter.com/gjbarnard)'.
+- @gjbarnard | '[X](https://twitter.com/gjbarnard)'.
Sponsors
========
@@ -49,10 +49,10 @@ benefits.
Required version of Moodle
==========================
-This version works with Moodle 4.2 version 2023042400.00 (Build: 20230424) and above within the MOODLE_402_STABLE branch until the
+This version works with Moodle 4.3 version 2023100900.00 (Build: 20231009) and above within the MOODLE_403_STABLE branch until the
next release.
-Please ensure that your hardware and software complies with 'Requirements' in '[Installing Moodle](https://docs.moodle.org/402/en/Installing_Moodle)'.
+Please ensure that your hardware and software complies with 'Requirements' in '[Installing Moodle](https://docs.moodle.org/403/en/Installing_Moodle)'.
Reporting issues
================
@@ -78,6 +78,6 @@ Developed and maintained by
G J Barnard MSc. BSc(Hons)(Sndw). MBCS. CEng. CITP. PGCE.
- Moodle profile | [Moodle.org](https://moodle.org/user/profile.php?id=442195)
-- @gjbarnard | [Twitter](https://twitter.com/gjbarnard)
+- @gjbarnard | [X](https://twitter.com/gjbarnard)
- Web profile | [About.me](https://about.me/gjbarnard)
- Website | [Website](https://gjbarnard.co.uk)
diff --git a/settings.php b/settings.php
index a69842e..9f3d81f 100644
--- a/settings.php
+++ b/settings.php
@@ -49,7 +49,7 @@
));
// Information.
- $page->add(new \format_topcoll\admin_setting_information('format_topcoll/formatinformation', '', '', 402));
+ $page->add(new \format_topcoll\admin_setting_information('format_topcoll/formatinformation', '', '', 403));
// Support.md.
$page->add(new \format_topcoll\admin_setting_markdown('format_topcoll/formatsupport', '', '', 'Support.md'));
diff --git a/version.php b/version.php
index 8083eff..7971081 100644
--- a/version.php
+++ b/version.php
@@ -33,9 +33,9 @@
*/
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2023042402;
+$plugin->version = 2023100700;
$plugin->maturity = MATURITY_STABLE;
-$plugin->requires = 2023042400.00; // 4.2 (Build: 20230424).
-$plugin->supported = [402, 402];
+$plugin->requires = 2023100900.00; // 4.3 (Build: 20231009).
+$plugin->supported = [403, 403];
$plugin->component = 'format_topcoll';
-$plugin->release = '402.1.2';
+$plugin->release = '403.1.0';
From 0f272945ae7fb3014322c318864ad7203759c4ce Mon Sep 17 00:00:00 2001
From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com>
Date: Sun, 8 Oct 2023 13:45:13 +0100
Subject: [PATCH 27/31] AJAX in progress.
---
classes/output/renderer.php | 5 ++++-
settopcollpref.php | 37 +++++++++++++++++++++++--------------
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/classes/output/renderer.php b/classes/output/renderer.php
index 5a93740..2512896 100644
--- a/classes/output/renderer.php
+++ b/classes/output/renderer.php
@@ -1239,7 +1239,10 @@ protected function set_user_preferences() {
$this->defaulttogglepersistence = clean_param(get_config('format_topcoll', 'defaulttogglepersistence'), PARAM_INT);
if ($this->defaulttogglepersistence == 1) {
- user_preference_allow_ajax_update('topcoll_toggle_' . $this->course->id, PARAM_RAW);
+ //user_preference_allow_ajax_update('topcoll_toggle_' . $this->course->id, PARAM_RAW);
+ //$USER->ajax_updatable_user_prefs[$name] = PARAM_RAW;
+ global $USER;
+ $USER->topcoll_user_pref['topcoll_toggle_' . $this->course->id] = PARAM_RAW;
$userpreference = get_user_preferences('topcoll_toggle_' . $this->course->id);
} else {
$userpreference = null;
diff --git a/settopcollpref.php b/settopcollpref.php
index a47fed5..51b88c1 100644
--- a/settopcollpref.php
+++ b/settopcollpref.php
@@ -37,19 +37,28 @@
// Get the name of the preference to update, and check that it is allowed.
$name = required_param('pref', PARAM_RAW);
-if (!isset($USER->ajax_updatable_user_prefs[$name])) {
- print_error('notallowedtoupdateprefremotely');
-}
-
-// Get and set the value.
-$value = \format_topcoll\togglelib::required_topcoll_param('value');
-// Update.
-if ($value) {
- if (!set_user_preference($name, $value)) {
- print_error('errorsettinguserpref');
- }
- echo 'OK';
+if (!isset($USER->topcoll_user_pref[$name])) {
+ // User's session does not contain the given preference, so the request is invalid.
+ header('HTTP/1.1 400 Bad Request');
+ //echo '{"code": 400, "message": "'.get_string('notallowedtoupdateprefremotely', 'error').'"}';
+ throw new moodle_exception(get_string('notallowedtoupdateprefremotely', 'error'));
} else {
- header('HTTP/1.1 406 Not Acceptable');
- echo 'Not Acceptable';
+ try {
+ // Get and set the value.
+ //throw new coding_exception('clean_topcoll_param() cannot process objects.');
+ $value = \format_topcoll\togglelib::required_topcoll_param('value');
+ // Update.
+ if (!$value) {
+ set_user_preference($name, $value); // Always returns true or a coding exception.
+ header('HTTP/1.1 200 OK');
+ echo '{"code": 200, "message": "OK"}';
+ } else {
+ header('HTTP/1.1 406 Not Acceptable');
+ //echo '{"code": 406, "message": "Toggle value contains a character outside of the range 58 to 121 decimal."}';
+ throw new invalid_parameter_exception("Toggle value contains a character outside of the range 58 to 121 decimal.");
+ }
+ } catch (coding_exception $ce) {
+ header('HTTP/1.1 500 Internal Server Error');
+ throw $ce;
+ }
}
From 8397e49922f81f3845f2a5147c70737770430923 Mon Sep 17 00:00:00 2001
From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com>
Date: Sun, 8 Oct 2023 14:00:55 +0100
Subject: [PATCH 28/31] Affects of MDL-76974 in progress.
---
classes/observer.php | 2 +-
classes/output/renderer.php | 8 +++-----
classes/privacy/provider.php | 6 +++---
classes/togglelib.php | 6 ++++--
classes/toolbox.php | 2 --
settopcollpref.php | 7 ++-----
tests/courseformatrenderer_test.php | 12 ++++++------
tests/privacy_provider_test.php | 4 ++--
8 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/classes/observer.php b/classes/observer.php
index 97b70ea..ab9e7a5 100644
--- a/classes/observer.php
+++ b/classes/observer.php
@@ -50,7 +50,7 @@ class format_topcoll_observer {
*/
public static function course_content_deleted(\core\event\course_content_deleted $event) {
global $DB;
- $DB->delete_records("user_preferences", ["name" => 'topcoll_toggle_' . $event->objectid]); // This is the $courseid.
+ $DB->delete_records("user_preferences", ["name" => \format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $event->objectid]); // This is the $courseid.
}
/* Events observed for the purpose of the activty functionality.
diff --git a/classes/output/renderer.php b/classes/output/renderer.php
index 2512896..23fd753 100644
--- a/classes/output/renderer.php
+++ b/classes/output/renderer.php
@@ -1077,7 +1077,7 @@ public function multiple_section_page() {
$this->userisediting, ]);
/* Make sure the database has the correct state of the toggles if changed by the code.
This ensures that a no-change page reload is correct. */
- set_user_preference('topcoll_toggle_' . $course->id, $toggles);
+ set_user_preference(\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $course->id, $toggles);
return $content;
}
@@ -1239,11 +1239,9 @@ protected function set_user_preferences() {
$this->defaulttogglepersistence = clean_param(get_config('format_topcoll', 'defaulttogglepersistence'), PARAM_INT);
if ($this->defaulttogglepersistence == 1) {
- //user_preference_allow_ajax_update('topcoll_toggle_' . $this->course->id, PARAM_RAW);
- //$USER->ajax_updatable_user_prefs[$name] = PARAM_RAW;
global $USER;
- $USER->topcoll_user_pref['topcoll_toggle_' . $this->course->id] = PARAM_RAW;
- $userpreference = get_user_preferences('topcoll_toggle_' . $this->course->id);
+ $USER->topcoll_user_pref[\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $this->course->id] = PARAM_RAW;
+ $userpreference = get_user_preferences(\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $this->course->id);
} else {
$userpreference = null;
}
diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php
index bb009e6..4f80a45 100644
--- a/classes/privacy/provider.php
+++ b/classes/privacy/provider.php
@@ -46,7 +46,7 @@ class provider implements
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $items): collection {
- $items->add_user_preference(\format_topcoll\toolbox::TOPCOLL_TOGGLE, 'privacy:metadata:preference:toggle');
+ $items->add_user_preference(\format_topcoll\togglelib::TOPCOLL_TOGGLE, 'privacy:metadata:preference:toggle');
return $items;
}
@@ -61,8 +61,8 @@ public static function export_user_preferences(int $userid) {
$togglelib = new \format_topcoll\togglelib();
foreach ($preferences as $name => $value) {
$courseid = null;
- if (strpos($name, \format_topcoll\toolbox::TOPCOLL_TOGGLE) === 0) {
- $courseid = substr($name, strlen(\format_topcoll\toolbox::TOPCOLL_TOGGLE) + 1);
+ if (strpos($name, \format_topcoll\togglelib::TOPCOLL_TOGGLE) === 0) {
+ $courseid = substr($name, strlen(\format_topcoll\togglelib::TOPCOLL_TOGGLE) + 1);
writer::export_user_preference(
'format_topcoll',
diff --git a/classes/togglelib.php b/classes/togglelib.php
index 8587460..b4fcedd 100644
--- a/classes/togglelib.php
+++ b/classes/togglelib.php
@@ -33,6 +33,8 @@
namespace format_topcoll;
class togglelib {
+ const TOPCOLL_TOGGLE = 'topcoll_toggle';
+
// Digits used = ":;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxy";
// Note: An ':' is 58 Ascii so to go between six digit base 2 and this then add / subtract 58.
// This has been chosen to avoid digits which are in the old method.
@@ -271,12 +273,12 @@ public static function required_topcoll_param($parname) {
*/
public static function clean_topcoll_param($param) {
if (is_array($param)) {
- throw new coding_exception('clean_topcoll_param() can not process arrays.');
+ throw new coding_exception('clean_topcoll_param() cannot process arrays.');
} else if (is_object($param)) {
if (method_exists($param, '__toString')) {
$param = $param->__toString();
} else {
- throw new coding_exception('clean_topcoll_param() can not process objects.');
+ throw new coding_exception('clean_topcoll_param() cannot process objects.');
}
}
diff --git a/classes/toolbox.php b/classes/toolbox.php
index 8cd8840..db30238 100644
--- a/classes/toolbox.php
+++ b/classes/toolbox.php
@@ -36,8 +36,6 @@
class toolbox {
protected static $instance;
- const TOPCOLL_TOGGLE = 'topcoll_toggle';
-
private function __construct() {
}
diff --git a/settopcollpref.php b/settopcollpref.php
index 51b88c1..384b285 100644
--- a/settopcollpref.php
+++ b/settopcollpref.php
@@ -40,21 +40,18 @@
if (!isset($USER->topcoll_user_pref[$name])) {
// User's session does not contain the given preference, so the request is invalid.
header('HTTP/1.1 400 Bad Request');
- //echo '{"code": 400, "message": "'.get_string('notallowedtoupdateprefremotely', 'error').'"}';
throw new moodle_exception(get_string('notallowedtoupdateprefremotely', 'error'));
} else {
try {
// Get and set the value.
- //throw new coding_exception('clean_topcoll_param() cannot process objects.');
$value = \format_topcoll\togglelib::required_topcoll_param('value');
// Update.
- if (!$value) {
+ if ($value) {
set_user_preference($name, $value); // Always returns true or a coding exception.
header('HTTP/1.1 200 OK');
- echo '{"code": 200, "message": "OK"}';
+ echo '{"message": "'.$name.' preference set"}';
} else {
header('HTTP/1.1 406 Not Acceptable');
- //echo '{"code": 406, "message": "Toggle value contains a character outside of the range 58 to 121 decimal."}';
throw new invalid_parameter_exception("Toggle value contains a character outside of the range 58 to 121 decimal.");
}
} catch (coding_exception $ce) {
diff --git a/tests/courseformatrenderer_test.php b/tests/courseformatrenderer_test.php
index 91a334d..68b0b20 100644
--- a/tests/courseformatrenderer_test.php
+++ b/tests/courseformatrenderer_test.php
@@ -248,7 +248,7 @@ public function test_section_summary() {
public function test_topcoll_section() {
$this->init();
- set_user_preference('topcoll_toggle_' . $this->course->id, 'Z');
+ set_user_preference(\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $this->course->id, 'Z');
set_config('defaultuserpreference', 0, 'format_topcoll');
set_config('defaulttogglepersistence', 1, 'format_topcoll');
self::set_property($this->outputus, 'formatresponsive', false);
@@ -433,7 +433,7 @@ public function test_multiple_section_page_horizontal() {
global $CFG;
$this->init();
- set_user_preference('topcoll_toggle_' . $this->course->id, null);
+ set_user_preference(\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $this->course->id, null);
set_config('defaultuserpreference', 0, 'format_topcoll');
set_config('defaulttogglepersistence', 1, 'format_topcoll');
$section0 = $this->courseformat->get_section(0);
@@ -456,7 +456,7 @@ public function test_multiple_section_page_vertical() {
global $CFG;
$this->init(1, 1);
- set_user_preference('topcoll_toggle_' . $this->course->id, 'Z');
+ set_user_preference(\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $this->course->id, 'Z');
set_config('defaultuserpreference', 0, 'format_topcoll');
set_config('defaulttogglepersistence', 1, 'format_topcoll');
@@ -481,7 +481,7 @@ public function test_multiple_section_page_no_sections() {
global $CFG;
$this->init(0);
- set_user_preference('topcoll_toggle_' . $this->course->id, null);
+ set_user_preference(\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $this->course->id, null);
set_config('defaultuserpreference', 0, 'format_topcoll');
set_config('defaulttogglepersistence', 1, 'format_topcoll');
$section0 = $this->courseformat->get_section(0);
@@ -509,7 +509,7 @@ public function test_toggle_all() {
'sctcloseall' => 'Close all topics',
'sctopenall' => 'Open all topics',
'spacer' => '',
+ '/theme/image.php/boost/core/1/spacer" />',
'toggleallhover' => true,
'tctoggleiconsize' => 'tc-medium',
'togglepos' => 'left',
@@ -530,7 +530,7 @@ public function test_display_instructions() {
$displayinstructionscontext = [
'rtl' => false,
'spacer' => '',
+ '/theme/image.php/boost/core/1/spacer" />',
];
$thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/displayinstructions',
$displayinstructionscontext, ]);
diff --git a/tests/privacy_provider_test.php b/tests/privacy_provider_test.php
index 6371249..9fb36df 100644
--- a/tests/privacy_provider_test.php
+++ b/tests/privacy_provider_test.php
@@ -122,7 +122,7 @@ public function test_export_user_preferences() {
$this->set_up();
$this->setAdminUser();
- set_user_preference('topcoll_toggle_' . $this->course->id, 'FAB');
+ set_user_preference(\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $this->course->id, 'FAB');
$user = \core_user::get_user_by_username('admin');
provider::export_user_preferences($user->id);
@@ -135,7 +135,7 @@ public function test_export_user_preferences() {
$this->assertCount(1, $prefs);
- $toggle = $prefs['topcoll_toggle_' . $this->course->id];
+ $toggle = $prefs[\format_topcoll\togglelib::TOPCOLL_TOGGLE.'_' . $this->course->id];
$this->assertEquals('FAB', $toggle->value);
$description = get_string('privacy:request:preference:toggle', 'format_topcoll', (object) [
From 72ed0ea5945c6d0a2fafdb3b9f8db44dfae43a7e Mon Sep 17 00:00:00 2001
From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com>
Date: Sun, 8 Oct 2023 14:15:37 +0100
Subject: [PATCH 29/31] MDL-76974
---
module.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/module.js b/module.js
index 3877830..5cf8be3 100644
--- a/module.js
+++ b/module.js
@@ -402,6 +402,10 @@ M.format_topcoll.encode_value_to_character = function(val) {
* @param String the value to set it to.
*/
M.format_topcoll.set_user_preference = function(name, value) {
+ // Note: Using own version instead of core_user/repository.setUserPreference(name, value) as I'm encoding the course id in
+ // the name of the preference, and that breaks the checking code, set_user_preferences() in user/externallib.php, that
+ // expects preferences to be statically named / cached in format_topcoll_user_preferences() in lib.php. Thus cannot be
+ // dynamic. Long term solution is using 'core/ajax' with db/services.php. Ref: MDL-76974.
YUI().use('io', function(Y) {
var url = M.cfg.wwwroot + '/course/format/topcoll/settopcollpref.php?sesskey=' + M.cfg.sesskey + '&pref=' + encodeURI(name) + '&value=' + encodeURI(value); // jshint ignore:line
From 3adebf9032fd161ef9fcc502409bb295ebea17e6 Mon Sep 17 00:00:00 2001
From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com>
Date: Sun, 8 Oct 2023 18:34:14 +0100
Subject: [PATCH 30/31] No 8.2 for now.
---
.github/workflows/ci.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9c068e4..69ab25a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: ['8.0', '8.2']
+ php: ['8.0'] # Note in 8.2 Creation of dynamic properties are deprecated and thus PHPUnit and Behat tests will fail, so 8.2 removed.
moodle-branch: ['MOODLE_403_STABLE']
database: [mariadb]
From 89e3417917b44b48f9715b9827b16bc34ef1c4a8 Mon Sep 17 00:00:00 2001
From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com>
Date: Sun, 8 Oct 2023 18:44:59 +0100
Subject: [PATCH 31/31] V403.1.0
---
Changes.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Changes.md b/Changes.md
index d967942..bfa5784 100644
--- a/Changes.md
+++ b/Changes.md
@@ -1,8 +1,9 @@
Version Information
===================
-Version 402.1.2 - TBR
+Version 403.1.0 - 08/10/2023
----------------------------
+1. First Moodle 4.3 release.
Version 402.1.1 - 14/08/2023
----------------------------
- ';
- $theoutput .= self::call_method($this->outputus, 'topcoll_section', array($section1, $this->course, false));
+ $theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section1, $this->course, false]);
$theoutput .= '