Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warnings for PHP 8.2 #148

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 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 @@ -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
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
Loading