Skip to content

Commit

Permalink
overrid get_course_display because the format always uses COURSE_DISP…
Browse files Browse the repository at this point in the history
…LAY_SINGLEPAGE
  • Loading branch information
davidherney committed Jun 10, 2024
1 parent 730d478 commit a4c7039
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
9 changes: 3 additions & 6 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
*/
class content extends content_base {

/** @var stdClass Local format data */
private static $formatdata;

/**
* @var bool Topic format has add section after each topic.
*
Expand Down Expand Up @@ -89,8 +86,8 @@ public function export_for_template(\renderer_base $output) {
// The current section format has extra navigation.
if ($currentsection || $currentsection === 0) {

$usessectionsnavigation = isset($format::$formatdata->configmenu->displaynavigation) ?
$format::$formatdata->configmenu->displaynavigation : null;
$usessectionsnavigation = isset($format::$formatdata[$course->id]->configmenu->displaynavigation) ?
$format::$formatdata[$course->id]->configmenu->displaynavigation : null;

if (empty($usessectionsnavigation)) {
$usessectionsnavigation = get_config('format_menutopic', 'defaultsectionsnavigation');
Expand Down Expand Up @@ -135,7 +132,7 @@ public function export_for_template(\renderer_base $output) {
/**
* Export sections array data.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @param \renderer_base $output typically, the renderer that's calling this function
* @return array data context for a mustache template
*/
protected function export_sections(\renderer_base $output): array {
Expand Down
4 changes: 2 additions & 2 deletions classes/output/courseformat/content/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class section extends section_base {
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output typically, the renderer that's calling this function
* @param \renderer_base $output typically, the renderer that's calling this function
* @return array data context for a mustache template
*/
public function export_for_template(\renderer_base $output): stdClass {
global $USER, $PAGE;
global $PAGE;

$format = $this->format;
$course = $format->get_course();
Expand Down
4 changes: 2 additions & 2 deletions classes/output/courseformat/content/section/cmlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function export_for_template(\renderer_base $output): stdClass {
return $data;
}

$templatetopic = \format_menutopic::$formatdata->configmenu->templatetopic;
$displaynousedmod = \format_menutopic::$formatdata->configmenu->displaynousedmod;
$templatetopic = \format_menutopic::$formatdata[$course->id]->configmenu->templatetopic;
$displaynousedmod = \format_menutopic::$formatdata[$course->id]->configmenu->displaynousedmod;
if (!$format->show_editor() && $templatetopic && !$displaynousedmod) {
return $data;
}
Expand Down
4 changes: 2 additions & 2 deletions classes/output/courseformat/content/section/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function format_summary_text(): string {
$course = $this->format->get_course();
$context = context_course::instance($section->course);

if (\format_menutopic::$formatdata->configmenu->templatetopic) {
if (\format_menutopic::$formatdata[$course->id]->configmenu->templatetopic) {
$section->summary = $this->replace_resources($section);
}

Expand Down Expand Up @@ -181,7 +181,7 @@ private function replace_resources(section_info $section) {
// Display the link to the module (or do nothing if module has no url).
$cmdata = $cm->export_for_template($this->output);
$cmdata->modinline = true;
$cmdata->hideicons = !\format_menutopic::$formatdata->configmenu->icons_templatetopic;
$cmdata->hideicons = !\format_menutopic::$formatdata[$course->id]->configmenu->icons_templatetopic;
$cmdata->uniqueid = 'cm_' . $mod->id . '_' . time() . '_' . rand(0, 1000);
$cmdata->singlename = $instancename;

Expand Down
17 changes: 14 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function __construct($format, $courseid) {

if (!empty($courseid)) {

$course = get_course($courseid);
$course = $this->get_course();

$section = optional_param('section', -1, PARAM_INT);

Expand All @@ -112,7 +112,7 @@ protected function __construct($format, $courseid) {

if (!empty($displaysection) || $displaysection === 0) {
// Retrieve course format option fields and add them to the $course object.
$firstsection = $this->get_course_display() == COURSE_DISPLAY_MULTIPAGE ? 1 : 0;
$firstsection = $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE ? 1 : 0;

$displaysection = $displaysection === 0 && $firstsection == 1 ? 1 : $displaysection;

Expand Down Expand Up @@ -591,6 +591,17 @@ public function get_config_for_external() {
return $this->get_format_options();
}

/**
* Get the course display value for the current course.
*
* It must be overridden because the format always uses COURSE_DISPLAY_SINGLEPAGE.
*
* @return int The current value (COURSE_DISPLAY_MULTIPAGE or COURSE_DISPLAY_SINGLEPAGE)
*/
public function get_course_display(): int {
return COURSE_DISPLAY_SINGLEPAGE;
}

/**
* Load configuration data.
*
Expand Down Expand Up @@ -789,7 +800,7 @@ public function load_formatdata() {
}

self::$localcourse = $course;
self::$formatdata = $formatdata;
self::$formatdata[$course->id] = $formatdata;

return $formatdata;
}
Expand Down

0 comments on commit a4c7039

Please sign in to comment.