Commit 479faca4 authored by Ferran Recio Calderó's avatar Ferran Recio Calderó
Browse files

MDL-73762 core_courseformat: fix coursedisplay dependency

For legacy reasons, the course renderings uses a format setting to know
if the page is multiple sections per page or a single section per page.
This format specific dependency is not solved using a get_course_display
format method any plugin can extend.
parent 23856b10
......@@ -277,6 +277,20 @@ abstract class base {
return $this->course;
}
/**
* Get the course display value for the current course.
*
* Formats extending topics or weeks will use coursedisplay as this setting name
* so they don't need to override the method. However, if the format uses a different
* display logic it must override this method to ensure the core renderers know
* if a COURSE_DISPLAY_MULTIPAGE or COURSE_DISPLAY_SINGLEPAGE is being used.
*
* @return int The current value (COURSE_DISPLAY_MULTIPAGE or COURSE_DISPLAY_SINGLEPAGE)
*/
public function get_course_display(): int {
return $this->get_course()->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE;
}
/**
* Return the current course modinfo.
*
......
......@@ -158,7 +158,7 @@ class content implements renderable, templatable {
// OR it is hidden but the course has a setting to display hidden sections as unavilable.
$showsection = $thissection->uservisible ||
($thissection->visible && !$thissection->available && !empty($thissection->availableinfo)) ||
(!$thissection->visible && !$course->hiddensections);
(!$thissection->visible && !($course->hiddensections ?? false));
if (!$showsection) {
continue;
}
......
......@@ -195,11 +195,10 @@ class section implements renderable, templatable {
$section = $this->section;
$format = $this->format;
$course = $this->format->get_course();
$showsummary = ($section->section != 0 &&
$section->section != $format->get_section_number() &&
$course->coursedisplay == COURSE_DISPLAY_MULTIPAGE &&
$format->get_course_display() == COURSE_DISPLAY_MULTIPAGE &&
!$format->show_editor()
);
......@@ -310,10 +309,8 @@ class section implements renderable, templatable {
protected function add_format_data(stdClass &$data, array $haspartials, renderer_base $output): bool {
$section = $this->section;
$format = $this->format;
$course = $this->format->get_course();
$coursedisplay = $course->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE;
$data->iscoursedisplaymultipage = ($coursedisplay == COURSE_DISPLAY_MULTIPAGE);
$data->iscoursedisplaymultipage = ($format->get_course_display() == COURSE_DISPLAY_MULTIPAGE);
if ($data->num === 0 && !$data->iscoursedisplaymultipage) {
$data->collapsemenu = true;
......
......@@ -75,7 +75,7 @@ class header implements renderable, templatable {
$data->title = $output->section_title_without_link($section, $course);
$coursedisplay = $course->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE;
$coursedisplay = $format->get_course_display();
$data->headerdisplaymultipage = false;
if ($coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$data->headerdisplaymultipage = true;
......
......@@ -1043,7 +1043,7 @@ abstract class section_renderer extends core_course_renderer {
continue;
}
if (!$format->show_editor() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
if (!$format->show_editor() && $format->get_course_display() == COURSE_DISPLAY_MULTIPAGE) {
// Display section summary only.
echo $this->section_summary($thissection, $course, null);
} else {
......
......@@ -126,7 +126,7 @@ class format_legacy extends core_courseformat\base {
$usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
}
} else {
$usercoursedisplay = $course->coursedisplay;
$usercoursedisplay = $course->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE;
}
if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
......@@ -268,11 +268,11 @@ class format_legacy extends core_courseformat\base {
'type' => PARAM_INT,
),
'hiddensections' => array(
'default' => $courseconfig->hiddensections,
'default' => $courseconfig->hiddensections ?? 0,
'type' => PARAM_INT,
),
'coursedisplay' => array(
'default' => $courseconfig->coursedisplay,
'default' => $courseconfig->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE,
'type' => PARAM_INT,
),
);
......
......@@ -135,7 +135,7 @@ class format_topics extends core_courseformat\base {
$usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
}
} else {
$usercoursedisplay = $course->coursedisplay;
$usercoursedisplay = $course->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE;
}
if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
......
......@@ -6,6 +6,7 @@ Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
* New core_courseformat\base::uses_course_index() to define whether the course format uses course index or not.
* New core_courseformat\base::supports_components() to specify if the format is compatible with reactive components.
* New core_courseformat\base::uses_indentation() to specify if the format is compatible with activity indentation.
* New core_courseformat\base::get_course_display() if the course uses COURSE_DISPLAY_SINGLEPAGE or COURSE_DISPLAY_MULTIPAGE layout.
=== 3.10 ===
* Added the missing callback supports_ajax() to format_social.
......
......@@ -145,7 +145,7 @@ class format_weeks extends core_courseformat\base {
$usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
}
} else {
$usercoursedisplay = $course->coursedisplay;
$usercoursedisplay = $course->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE;
}
if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
......@@ -268,7 +268,7 @@ class format_weeks extends core_courseformat\base {
'type' => PARAM_INT,
),
'coursedisplay' => array(
'default' => $courseconfig->coursedisplay,
'default' => $courseconfig->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE,
'type' => PARAM_INT,
),
'automaticenddate' => array(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment