Skip to content

Commit

Permalink
Merge branch 'mdl-80248_fix' into moodle_404_test
Browse files Browse the repository at this point in the history
  • Loading branch information
james-cnz committed Feb 4, 2024
2 parents b3a2d41 + 59655e1 commit 72e22b6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 45 deletions.
6 changes: 3 additions & 3 deletions classes/output/courseformat/content/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function add_cm_data(\stdClass &$data, \renderer_base $output): bool {
// ADDED.
$pageid = ($sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) ?
$section->id : $sectionextra->parentid;
$onpage = ($pageid == $format->get_sectionid());
$onpage = ($pageid == $format->get_sectionid()) || ($format->get_sectionid() === null);
// END ADDED.
$showcmlist = ($section->uservisible || $section->section == 0); // CHANGED.

Expand Down Expand Up @@ -197,7 +197,7 @@ protected function add_format_data(\stdClass &$data, array $haspartials, \render

// REMOVED coursedisplay setting.

if ($sectionextra->levelsan < 2 && ($section->id == $format->get_sectionid())) {
if ($sectionextra->levelsan < 2 && ($section->id == $format->get_sectionid() || $format->get_sectionid() === null)) {
$data->collapsemenu = true;
}

Expand All @@ -221,7 +221,7 @@ protected function add_format_data(\stdClass &$data, array $haspartials, \render
$course = $this->format->get_course();
$pageid = ($sectionextra->levelsan < FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) ?
$section->id : $sectionextra->parentid;
$onpage = ($pageid == $format->get_sectionid());
$onpage = ($pageid == $format->get_sectionid()) || ($format->get_sectionid() === null);
$sectionstyle = " sectionid-{$section->id}";
$iscollapsible = false;
// Determine the section type.
Expand Down
11 changes: 7 additions & 4 deletions format.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@
$renderer = $PAGE->get_renderer('format_multitopic');

// ADDED.
if ($sectionid) {
$displaysection = $DB->get_record('course_sections',
['id' => $sectionid, 'course' => $course->id], '*', MUST_EXIST);
if (is_object($displaysection) && property_exists($displaysection, 'id')) {
$displaysection = $displaysection;
} else if ($sectionid) {
$displaysection = (object)['id' => $sectionid];
} else {
$displaysection = $displaysection ?? 0;
}
// END ADDED.
if (isset($displaysection)) {
if (!is_null($displaysection)) {
$format->set_sectionnum($displaysection);
}
$outputclass = $format->get_output_classname('content');
Expand Down
69 changes: 31 additions & 38 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,85 +474,78 @@ public function get_default_section_name($section) : string {
}

/**
* Set the section to show.
* Set if the current format instance will show all pages or an individual one.
*
* @param int|null $sectionid null for general section or a sectionid.
* @param ?int $sectionid null for all pages, or a page's sectionid.
*/
public function set_sectionid(?int $sectionid): void {
$this->set_sectionnum($sectionid ? (object)['id' => $sectionid] : 0);
$this->set_sectionnum(isset($sectionid) ? (object)['id' => $sectionid] : null);
}

/**
* Get the section to show.
* Get if the current format instance will show all pages or an individual one.
*
* @return int the sectionid.
* @return ?int null for all pages or the page's sectionid.
*/
public function get_sectionid(): int {
if ($this->singlesectionid === null) {
$this->singlesectionid = $this->get_section(0)->id;
$this->singlesection = 0;
}
public function get_sectionid(): ?int {
return $this->singlesectionid;
}

/**
* Set which section page will be shown.
* Set which section page the current format instance will show.
*
* @param int $singlesection a section number
* @param int $singlesection a page's section number
* @deprecated
*/
public function set_section_number(int $singlesection): void {
$this->set_sectionnum($singlesection);
}

/**
* Set the current section number to display.
* Set the current page to display.
*
* @param int|stdClass|\section_info|null $singlesection section or num.
* @param \section_info|stdClass|int|null $section null for all pages or a page's section info or number.
*/
public function set_sectionnum($singlesection): void {
if ($singlesection === null) {
$singlesection = 0;
}
if (!is_object($singlesection) || !isset($singlesection->level)) {
$singlesection = $this->get_section($singlesection);
public function set_sectionnum($section): void {
if ($section === null) {
$this->singlesection = null;
$this->singlesectionid = null;
return;
}

$sectionextra = $this->fmt_get_section_extra($section);

// If display section is a topic, get the page it is on instead.
if (isset($singlesection) && $singlesection->level >= FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) {
if ($sectionextra->levelsan >= FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) {
$sectionsextra = $this->fmt_get_sections_extra();
$singlesectionextra = $sectionsextra[$singlesection->id];
if (isset($singlesectionextra) && $singlesectionextra->levelsan >= FORMAT_MULTITOPIC_SECTION_LEVEL_TOPIC) {
$singlesectionextra = $sectionsextra[$singlesectionextra->parentid];
$singlesection = $singlesectionextra->sectionbase;
}
$sectionextra = $sectionsextra[$sectionextra->parentid];
}

$this->singlesectionid = $singlesection->id;
$this->singlesection = $singlesection->section;
$this->singlesectionid = $sectionextra->id;
$this->singlesection = $sectionextra->section;
}

/**
* Get the current section number to display.
* Get the current page's section number to display.
*
* @return int the current section number.
* @return ?int the current page's section number or null when there is no single page.
*/
public function get_sectionnum(): int {
if ($this->singlesection === null) {
$this->singlesectionid = $this->get_section(0)->id;
$this->singlesection = 0;
}
public function get_sectionnum(): ?int {
return $this->singlesection;
}

/**
* Get the current section number to show.
* Get the section number of the page the current format instance will show.
*
* @return int the section number
* @return int the page's section number
* @deprecated
*/
public function get_section_number(): int {
return $this->get_sectionnum();
if ($this->singlesection === null) {
return 0;
}

return $this->singlesection;
}

/**
Expand Down

0 comments on commit 72e22b6

Please sign in to comment.