mirror of
https://github.com/moodle/moodle.git
synced 2025-03-18 22:50:19 +01:00
MDL-73683 core_courseformat: format section visible logic
Move the section visible logic to the format base class. This way format plugins can decide whenever a section is visible or not instead of using format custom settings from core.
This commit is contained in:
parent
c7a2e19ee0
commit
d7d154bd8b
@ -388,14 +388,8 @@ class core_course_external extends external_api {
|
||||
// We didn't this before to be able to retrieve stealth activities.
|
||||
foreach ($coursecontents as $sectionnumber => $sectioncontents) {
|
||||
$section = $sections[$sectionnumber];
|
||||
// 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 OR
|
||||
// the course is configured to show hidden sections name.
|
||||
$showsection = $section->uservisible ||
|
||||
($section->visible && !$section->available && !empty($section->availableinfo)) ||
|
||||
(!$section->visible && empty($courseformat->get_course()->hiddensections));
|
||||
|
||||
if (!$showsection) {
|
||||
if (!$courseformat->is_section_visible($section)) {
|
||||
unset($coursecontents[$sectionnumber]);
|
||||
continue;
|
||||
}
|
||||
|
@ -1210,6 +1210,28 @@ abstract class base {
|
||||
return ($sectionnum && ($course = $this->get_course()) && $course->marker == $sectionnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
// Previous to Moodle 4.0 thas logic was hardcoded. To prevent errors in the contrib plugins
|
||||
// the default logic is the same required for topics and weeks format and still uses
|
||||
// a "hiddensections" format setting.
|
||||
$course = $this->get_course();
|
||||
$hidesections = $course->hiddensections ?? true;
|
||||
// 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,
|
||||
// OR it is hidden but the course has a setting to display hidden sections as unavailable.
|
||||
return $section->uservisible ||
|
||||
($section->visible && !$section->available && !empty($section->availableinfo)) ||
|
||||
(!$section->visible && !$hidesections);
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the course editor must be displayed.
|
||||
*
|
||||
|
2
course/format/classes/external/get_state.php
vendored
2
course/format/classes/external/get_state.php
vendored
@ -102,7 +102,7 @@ class get_state extends external_api {
|
||||
// Sections and course modules state.
|
||||
$sections = $modinfo->get_section_info_all();
|
||||
foreach ($sections as $section) {
|
||||
if (!empty($section->uservisible)) {
|
||||
if ($courseformat->is_section_visible($section)) {
|
||||
// Only return this section data if it's visible by current user on the course page.
|
||||
$sectionstate = new $sectionclass($courseformat, $section);
|
||||
$result->section[] = $sectionstate->export_for_template($renderer);
|
||||
|
@ -153,13 +153,7 @@ class content implements renderable, templatable {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 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,
|
||||
// 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);
|
||||
if (!$showsection) {
|
||||
if (!$format->is_section_visible($thissection)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ class course implements renderable {
|
||||
|
||||
$sections = $modinfo->get_section_info_all();
|
||||
foreach ($sections as $section) {
|
||||
if (!empty($section->uservisible)) {
|
||||
if ($format->is_section_visible($section)) {
|
||||
$data->sectionlist[] = $section->id;
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class section implements renderable {
|
||||
|
||||
foreach ($modinfo->sections[$section->section] as $modnumber) {
|
||||
$mod = $modinfo->cms[$modnumber];
|
||||
if ($mod->is_visible_on_course_page()) {
|
||||
if ($section->uservisible && $mod->is_visible_on_course_page()) {
|
||||
$data->cmlist[] = $mod->id;
|
||||
}
|
||||
}
|
||||
|
@ -1033,13 +1033,8 @@ abstract class section_renderer extends core_course_renderer {
|
||||
// Activities inside this section are 'orphaned', this section will be printed as 'stealth' below.
|
||||
continue;
|
||||
}
|
||||
// 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,
|
||||
// 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);
|
||||
if (!$showsection) {
|
||||
|
||||
if (!$format->is_section_visible($thissection)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -111,14 +111,15 @@ class stateupdates implements JsonSerializable {
|
||||
}
|
||||
$course = $this->format->get_course();
|
||||
$modinfo = course_modinfo::instance($course);
|
||||
$format = $this->format;
|
||||
|
||||
$section = $modinfo->get_section_info_by_id($sectionid, MUST_EXIST);
|
||||
|
||||
if (!$section->uservisible) {
|
||||
if (!$format->is_section_visible($section)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sectionclass = $this->format->get_output_classname('state\\section');
|
||||
$sectionclass = $format->get_output_classname('state\\section');
|
||||
$currentstate = new $sectionclass($this->format, $section);
|
||||
|
||||
$this->add_update('section', $action, $currentstate->export_for_template($this->output));
|
||||
@ -162,12 +163,13 @@ class stateupdates implements JsonSerializable {
|
||||
|
||||
$cm = $modinfo->get_cm($cmid);
|
||||
$section = $modinfo->get_section_info_by_id($cm->section);
|
||||
$format = $this->format;
|
||||
|
||||
if (!$section->uservisible || !$cm->is_visible_on_course_page()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cmclass = $this->format->get_output_classname('state\\cm');
|
||||
$cmclass = $format->get_output_classname('state\\cm');
|
||||
$currentstate = new $cmclass($this->format, $section, $cm);
|
||||
|
||||
$this->add_update('cm', $action, $currentstate->export_for_template($this->output));
|
||||
|
Loading…
x
Reference in New Issue
Block a user