From 99941c0d13f374a4b5f2a77336e1999a4e93d164 Mon Sep 17 00:00:00 2001 From: meirzamoodle Date: Sun, 28 Jan 2024 14:59:28 +0700 Subject: [PATCH] MDL-78850 course: allow to show/hide the course index drawer This new API makes it easy for the developer to hide or show the course index drawer. --- course/lib.php | 5 +++++ lib/pagelib.php | 25 +++++++++++++++++++++++++ lib/tests/moodle_page_test.php | 13 +++++++++++++ 3 files changed, 43 insertions(+) diff --git a/course/lib.php b/course/lib.php index a8074c50473..b1416e0a5cd 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3750,6 +3750,11 @@ function core_course_core_calendar_get_valid_event_timestart_range(\calendar_eve function core_course_drawer(): string { global $PAGE; + // If the course index is explicitly set and if it should be hidden. + if ($PAGE->get_show_course_index() === false) { + return ''; + } + // Only add course index on non-site course pages. if (!$PAGE->course || $PAGE->course->id == SITEID) { return ''; diff --git a/lib/pagelib.php b/lib/pagelib.php index 3fba00ac248..f5b3b9f1f8d 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -432,6 +432,11 @@ class moodle_page { */ protected $_forcelockallblocks = false; + /** + * @var bool Indicates whether the course index drawer should be shown. + */ + protected bool $_showcourseindex = true; + /** * Force the settings menu to be displayed on this page. This will only force the * settings menu on an activity / resource page that is being displayed on a theme that @@ -2477,4 +2482,24 @@ class moodle_page { public function get_navigation_overflow_state(): bool { return $this->_navigationoverflow; } + + /** + * Set the status for displaying the course index. + * + * @param bool $state + * - `true` (default) if the course index should be shown. + * - `false` if the course index should be hidden. + */ + public function set_show_course_index(bool $state): void { + $this->_showcourseindex = $state; + } + + /** + * Get the current status for displaying the course index. + * + * @return bool + */ + public function get_show_course_index(): bool { + return $this->_showcourseindex; + } } diff --git a/lib/tests/moodle_page_test.php b/lib/tests/moodle_page_test.php index 793a3ff6f69..a74dabcc7b5 100644 --- a/lib/tests/moodle_page_test.php +++ b/lib/tests/moodle_page_test.php @@ -875,6 +875,19 @@ class moodle_page_test extends \advanced_testcase { $this->testpage->force_lock_all_blocks(); $this->assertFalse($this->testpage->user_can_edit_blocks()); } + + /** + * Test the method to set and retrieve the show_course_index property. + * + * @covers ::set_show_course_index + * @covers ::get_show_course_index + * @return void + */ + public function test_show_course_index(): void { + $page = new \moodle_page(); + $page->set_show_course_index(false); + $this->assertFalse($page->get_show_course_index()); + } } /**