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:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user