diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index 41b93702..2176c8d1 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -130,6 +130,15 @@ public function export_for_template(renderer_base $output) { $data->singlesection = array_shift($data->sections); $data->sectionreturn = $singlesectionno; $data->maincoursepage = new url('/course/view.php', ['id' => $course->id]); + + // Override the visibility if the user can see the section. + // Reference: lib/modinfolib.php with regards to 'uservisible'. + $section = $format->get_section($singlesectionno); + if (!$section->visible && $section->uservisible) { + $data->singlesection->visibility->notavailable = false; + $data->singlesection->visibility->hiddenfromstudents = true; + } + } else { $toolbox = toolbox::get_instance(); $coursesectionimages = $DB->get_records('format_grid_image', ['courseid' => $course->id]); @@ -261,6 +270,14 @@ public function export_for_template(renderer_base $output) { // Visibility information. $sectionimages[$section->id]->ishidden = $sectionvisiblity[$section->id]->ishidden; if ($sectionimages[$section->id]->ishidden) { + + // Override the visibility if the user can see the section. + // Reference: lib/modinfolib.php with regards to 'uservisible'. + if ($section->uservisible) { + $sectionvisiblity[$section->id]->visibility->notavailable = false; + $sectionvisiblity[$section->id]->visibility->hiddenfromstudents = true; + } + $sectionimages[$section->id]->visibility = $sectionvisiblity[$section->id]->visibility; $sectionimages[$section->id]->hiddenfromstudents = (!empty($sectionimages[$section->id]->visibility->hiddenfromstudents));