From 0cb4e3304e36e59954380ec970f48fb0524761e0 Mon Sep 17 00:00:00 2001
From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com>
Date: Mon, 4 Mar 2024 13:28:41 +0000
Subject: [PATCH] Cope with course index.

---
 classes/output/courseformat/content.php | 5 -----
 lib.php                                 | 8 +++++++-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php
index 145f1a40..3f928905 100644
--- a/classes/output/courseformat/content.php
+++ b/classes/output/courseformat/content.php
@@ -376,11 +376,6 @@ protected function get_grid_sections(\renderer_base $output, $settings): array {
                 continue;
             }
 
-            $sectionformatoptions = $format->get_format_options($thissection);
-            if ($sectionformatoptions['sectionhideingrid'] == 2) { // Yes.
-                continue;
-            }
-
             $section = new stdClass();
             $section->id = $thissection->id;
             $section->num = $thissection->section;
diff --git a/lib.php b/lib.php
index 11d37bdd..0847f3f2 100755
--- a/lib.php
+++ b/lib.php
@@ -207,9 +207,9 @@ public function get_default_section_name($section) {
      * @return bool;
      */
     public function is_section_visible(section_info $section): bool {
+        global $PAGE;
         if ($section->section > $this->get_last_section_number()) {
             // Stealth section.
-            global $PAGE;
             $context = context_course::instance($this->course->id);
             if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
                 $modinfo = get_fast_modinfo($this->course);
@@ -218,6 +218,12 @@ public function is_section_visible(section_info $section): bool {
             }
             // Don't show.
             return false;
+        } else if (!$PAGE->user_is_editing()) {
+            $sectionformatoptions = $this->get_format_options($section);
+            if ($sectionformatoptions['sectionhideingrid'] == 2) { // Yes.
+                // Don't show.
+                return false;
+            }
         }
         return parent::is_section_visible($section);
     }