Skip to content

Commit

Permalink
Merge branch 'MOODLE_403' of github.com:gjb2048/moodle-format_topcoll…
Browse files Browse the repository at this point in the history
… into MOODLE_403_STABLE
  • Loading branch information
trevor-c committed Apr 5, 2024
2 parents 7a4340f + 88e9780 commit 7a19ac6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand Down
6 changes: 6 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Version Information
===================

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
----------------------------
1. First Moodle 4.3 release.
Expand Down
34 changes: 16 additions & 18 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -800,7 +796,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--;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -897,29 +894,29 @@ public function multiple_section_page() {
}
if ($testhidden) {
if (!$course->hiddensections && $thissection->available) {
$thissection->ishidden = true;
$extrasectioninfo[$thissection->id]->ishidden = true;
$sectiondisplayarray[] = $thissection;
}
}
} else {
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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
24 changes: 24 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,30 @@ 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]));
}
// Don't show.
return false;
}
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());
Expand Down
20 changes: 9 additions & 11 deletions tests/courseformatrenderer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 .= '<ul class="ctopics">';
$theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section0, $this->course, false, 0]);
$theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section0, $this->course, false, 0, $toggle]);
$theoutput .= '</ul><ul class="ctopics ctoggled topics row">';
$theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section1, $this->course, false]);
$theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section1, $this->course, false, null, $toggle]);
$theoutput .= '</ul>';

$this->assertEquals($thevalue, $theoutput);
Expand All @@ -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 .= '<ul class="ctopics">';
$theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section0, $this->course, false, 0]);
$theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section0, $this->course, false, 0, $toggle]);
$theoutput .= '</ul><div class="row">';
$theoutput .= '<ul class="ctopics ctoggled topics col-sm-12">';
$theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section1, $this->course, false]);
$theoutput .= self::call_method($this->outputus, 'topcoll_section', [$section1, $this->course, false, null, $toggle]);
$theoutput .= '</ul></div>';

$this->assertEquals($thevalue, $theoutput);
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 7a19ac6

Please sign in to comment.