From e1d022a04ca9fc7f6ba78feb16d4b423739f0a48 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:40:38 +0000 Subject: [PATCH 1/7] V403.1.1 start. --- Changes.md | 3 +++ version.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Changes.md b/Changes.md index bfa5784..2493495 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,9 @@ Version Information =================== +Version 403.1.1 - TBR +---------------------------- + Version 403.1.0 - 08/10/2023 ---------------------------- 1. First Moodle 4.3 release. diff --git a/version.php b/version.php index 7971081..a18bc82 100644 --- a/version.php +++ b/version.php @@ -33,9 +33,9 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023100700; +$plugin->version = 2023100701; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2023100900.00; // 4.3 (Build: 20231009). $plugin->supported = [403, 403]; $plugin->component = 'format_topcoll'; -$plugin->release = '403.1.0'; +$plugin->release = '403.1.1'; From 775a5676fff88dbbcc2a561452b57d34f224c277 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:18:29 +0000 Subject: [PATCH 2/7] Fix 'Orphaned Section still appear in Index Drawer' - #146. --- Changes.md | 1 + lib.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Changes.md b/Changes.md index 2493495..59a3fd8 100644 --- a/Changes.md +++ b/Changes.md @@ -3,6 +3,7 @@ Version 403.1.1 - TBR ---------------------------- +1. Fix 'Orphaned Section still appear in Index Drawer' - #146. Version 403.1.0 - 08/10/2023 ---------------------------- diff --git a/lib.php b/lib.php index ea5a824..f710d04 100644 --- a/lib.php +++ b/lib.php @@ -235,6 +235,28 @@ public function get_topcoll_section_name($course, $section, $additional) { return $o; } + /** + * Returns if an specific section is visible to the current user. + * + * Formats can overrride this method to implement any special section logic. + * + * @param section_info $section the section modinfo + * @return bool; + */ + public function is_section_visible(section_info $section): bool { + if ($section->section > $this->get_last_section_number()) { + // Stealth section. + global $PAGE; + $context = context_course::instance($this->course->id); + if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) { + $modinfo = get_fast_modinfo($this->course); + // If the stealth section has modules then is visible. + return (!empty($modinfo->sections[$section->section])); + } + } + return parent::is_section_visible($section); + } + public function get_section_dates($section, $course = null, $tcsettings = null) { if (empty($tcsettings) && empty($course)) { return $this->format_topcoll_get_section_dates($section, $this->get_course()); From e4c6a6ddf28971b1e4aa63c831c046a8cbf729d4 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Sat, 10 Feb 2024 21:32:49 +0000 Subject: [PATCH 3/7] Fix 'Orphaned Section still appear in Index Drawer' pt2 - #146. --- lib.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib.php b/lib.php index f710d04..b7c66f2 100644 --- a/lib.php +++ b/lib.php @@ -253,6 +253,8 @@ public function is_section_visible(section_info $section): bool { // If the stealth section has modules then is visible. return (!empty($modinfo->sections[$section->section])); } + // Don't show. + return false; } return parent::is_section_visible($section); } From 4c3a38127ee8252a72462a1aa177eaa92172152c Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:15:49 +0000 Subject: [PATCH 4/7] Clarify. --- classes/output/renderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 23fd753..3b66f31 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -800,7 +800,7 @@ public function multiple_section_page() { while ($loopsection <= $coursenumsections) { $nextweekdate = $weekdate - ($weekofseconds); if (($this->courseformat->is_section_visible($thissection)) && ($nextweekdate <= $timenow)) { - $numsections++; // Section not shown so do not count in columns calculation. + $numsections++; // Section is shown so do count in columns calculation. } $weekdate = $nextweekdate; $section--; From aad47ce8a3c0cb3f9228e3f41e259877c22396ac Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:16:47 +0000 Subject: [PATCH 5/7] actions/checkout -> v4 --- .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 69ab25a..2c1d26a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin From c95f2b346fe078397cae8d18aa1658fd30f9018b Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Wed, 28 Feb 2024 12:28:19 +0000 Subject: [PATCH 6/7] Fix deprecation warnings for PHP 8.2 --- classes/output/renderer.php | 32 ++++++++++++++--------------- tests/courseformatrenderer_test.php | 20 ++++++++---------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 3b66f31..eeea70d 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -155,8 +155,7 @@ public function course_section_updated( if ($section->section > $course->numsections) { $output = $this->stealth_section($section, $course); } else { - $section->toggle = true; // TODO. - $output = $this->topcoll_section($section, $course, false); + $output = $this->topcoll_section($section, $course, false, null, true); } return $output; @@ -415,10 +414,11 @@ protected function section_summary_container($section) { * @param stdClass $course The course entry from DB. * @param bool $onsectionpage true if being printed on a section page. * @param int $sectionreturn The section to return to after an action. + * @param ?bool $toggle true if toggle is enabled, false otherwise, null if not set * * @return string HTML to output. */ - protected function topcoll_section($section, $course, $onsectionpage, $sectionreturn = null) { + protected function topcoll_section($section, $course, $onsectionpage, $sectionreturn = null, $toggle = null) { $context = context_course::instance($course->id); $sectioncontext = [ @@ -471,11 +471,7 @@ protected function topcoll_section($section, $course, $onsectionpage, $sectionre $this->toggle_icon_set($sectioncontext); $sectioncontext['toggleiconsize'] = $this->tctoggleiconsize; - if ((!($section->toggle === null)) && ($section->toggle == true)) { - $sectioncontext['toggleopen'] = true; - } else { - $sectioncontext['toggleopen'] = false; - } + $sectioncontext['toggleopen'] = !empty($toggle); if ($this->userisediting) { $title = $this->section_title($section, $course); @@ -862,6 +858,7 @@ public function multiple_section_page() { $nextweekdate = $weekdate - ($weekofseconds); } $thissection = $modinfo->get_section_info($section); + $extrasectioninfo[$thissection->id] = new \stdClass(); /* Show the section if the user is permitted to access it, OR if it's not available but there is some available info text which explains the reason & should display. */ @@ -897,7 +894,7 @@ public function multiple_section_page() { } if ($testhidden) { if (!$course->hiddensections && $thissection->available) { - $thissection->ishidden = true; + $extrasectioninfo[$thissection->id]->ishidden = true; $sectiondisplayarray[] = $thissection; } } @@ -905,21 +902,21 @@ public function multiple_section_page() { if ($this->isoldtogglepreference == true) { $togglestate = substr($this->togglelib->get_toggles(), $section, 1); if ($togglestate == '1') { - $thissection->toggle = true; + $extrasectioninfo[$thissection->id]->toggle = true; } else { - $thissection->toggle = false; + $extrasectioninfo[$thissection->id]->toggle = false; } } else { - $thissection->toggle = $this->togglelib->get_toggle_state($thissection->section); + $extrasectioninfo[$thissection->id]->toggle = $this->togglelib->get_toggle_state($thissection->section); } if ($this->courseformat->is_section_current($thissection)) { $this->currentsection = $thissection->section; - $thissection->toggle = true; // Open current section regardless of toggle state. + $extrasectioninfo[$thissection->id]->toggle = true; // Open current section regardless of toggle state. $this->togglelib->set_toggle_state($thissection->section, true); } - $thissection->isshown = true; + $extrasectioninfo[$thissection->id]->isshown = true; $sectiondisplayarray[] = $thissection; } @@ -965,9 +962,9 @@ public function multiple_section_page() { $sectionoutput .= $this->section_hidden($thissection); } else if (!empty($thissection->issummary)) { $sectionoutput .= $this->section_summary($thissection, $course, null); - } else if (!empty($thissection->isshown)) { + } else if (!empty($extrasectioninfo[$thissection->id]->isshown)) { if ((!$this->userisediting) && ($this->tcsettings['onesection'] == 2)) { - if ($thissection->toggle) { + if ($extrasectioninfo[$thissection->id]->toggle) { if (!empty($shownonetoggle)) { // Make sure the current section is not closed if set above. if ($shownonetoggle != $thissection->section) { @@ -981,7 +978,8 @@ public function multiple_section_page() { } } } - $sectionoutput .= $this->topcoll_section($thissection, $course, false); + $sectionoutput .= $this->topcoll_section($thissection, $course, false, + null, $extrasectioninfo[$thissection->id]->toggle); $toggledsections[] = $thissection->section; } diff --git a/tests/courseformatrenderer_test.php b/tests/courseformatrenderer_test.php index 68b0b20..2d3d94f 100644 --- a/tests/courseformatrenderer_test.php +++ b/tests/courseformatrenderer_test.php @@ -253,15 +253,14 @@ public function test_topcoll_section() { set_config('defaulttogglepersistence', 1, 'format_topcoll'); self::set_property($this->outputus, 'formatresponsive', false); $section1 = $this->courseformat->get_section(1); - $section1->section = 1; - $section1->toggle = true; + $toggle = true; $onsectionpage = false; $sectionreturn = null; $theclass = self::call_method( $this->outputus, 'topcoll_section', - [$section1, $this->course, $onsectionpage] + [$section1, $this->course, $onsectionpage, null, $toggle] ); $sectioncontext = [ @@ -287,7 +286,7 @@ public function test_topcoll_section() { 'sectionsummarywhencollapsed' => false, 'toggleiconset' => 'arrow', 'toggleiconsize' => 'tc-medium', - 'toggleopen' => $section1->toggle, + 'toggleopen' => $toggle, ]; $thevalue = self::call_method($this->outputus, 'render_from_template', ['format_topcoll/section', $sectioncontext]); $this->assertEquals($thevalue, $theclass); @@ -323,7 +322,6 @@ public function test_topcoll_section() { public function test_section_hidden() { $this->init(); $section = $this->courseformat->get_section(1); - $section->visible = false; $theclass = self::call_method( $this->outputus, @@ -438,15 +436,15 @@ public function test_multiple_section_page_horizontal() { set_config('defaulttogglepersistence', 1, 'format_topcoll'); $section0 = $this->courseformat->get_section(0); $section1 = $this->courseformat->get_section(1); - $section1->toggle = false; + $toggle = false; $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 .= ''; $this->assertEquals($thevalue, $theoutput); @@ -462,16 +460,16 @@ public function test_multiple_section_page_vertical() { $section0 = $this->courseformat->get_section(0); $section1 = $this->courseformat->get_section(1); - $section1->toggle = true; + $toggle = true; $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 .= '
'; $theoutput .= '
'; $this->assertEquals($thevalue, $theoutput); From 88e978034c800297b999d60606194ded8f72d668 Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:32:40 +0000 Subject: [PATCH 7/7] V403.1.1 --- Changes.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index 59a3fd8..f9a3f21 100644 --- a/Changes.md +++ b/Changes.md @@ -1,9 +1,11 @@ Version Information =================== -Version 403.1.1 - TBR +Version 403.1.1 - 11/03/2024 ---------------------------- 1. Fix 'Orphaned Section still appear in Index Drawer' - #146. +2. Fix 'Deprecated warnings in PHP 8.2' - #147, a big thanks to [PhMemmel](https://github.com/PhMemmel) + for the patch in #148. Version 403.1.0 - 08/10/2023 ----------------------------