From 25699339d999c0294abdf561abba93956ec6c57d Mon Sep 17 00:00:00 2001 From: Mathew May Date: Thu, 3 Feb 2022 14:22:23 +0800 Subject: [PATCH] MDL-73743 navigation: Add more nav nodes to site home --- admin/tool/monitor/lib.php | 2 +- lib/classes/navigation/views/secondary.php | 36 ++++++++++++++-------- lib/navigationlib.php | 17 ++++++---- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/admin/tool/monitor/lib.php b/admin/tool/monitor/lib.php index df11ac9b12e..72d10cbc1f3 100644 --- a/admin/tool/monitor/lib.php +++ b/admin/tool/monitor/lib.php @@ -57,7 +57,7 @@ function tool_monitor_extend_navigation_frontpage($navigation, $course, $context $url = new moodle_url('/admin/tool/monitor/managerules.php', array('courseid' => $course->id)); $settingsnode = navigation_node::create(get_string('managerules', 'tool_monitor'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/settings', '')); - $reportnode = $navigation->get('frontpagereports'); + $reportnode = $navigation->get('coursereports'); if (isset($settingsnode) && !empty($reportnode)) { $reportnode->add_node($settingsnode); diff --git a/lib/classes/navigation/views/secondary.php b/lib/classes/navigation/views/secondary.php index bec16dbc1c6..0d07339c100 100644 --- a/lib/classes/navigation/views/secondary.php +++ b/lib/classes/navigation/views/secondary.php @@ -364,6 +364,8 @@ class secondary extends view { * node by default. */ protected function load_course_navigation(?navigation_node $rootnode = null): void { + global $SITE; + $rootnode = $rootnode ?? $this; $course = $this->page->course; // Initialise the main navigation and settings nav. @@ -372,7 +374,15 @@ class secondary extends view { $navigation = $this->page->navigation; $url = new \moodle_url('/course/view.php', ['id' => $course->id]); - $rootnode->add(get_string('course'), $url, self::TYPE_COURSE, null, 'coursehome'); + $firstnodeidentifier = get_string('course'); + $issitecourse = $course->id == $SITE->id; + if ($issitecourse) { + $firstnodeidentifier = get_string('home'); + if ($frontpage = $settingsnav->get('frontpage')) { + $settingsnav = $frontpage; + } + } + $rootnode->add($firstnodeidentifier, $url, self::TYPE_COURSE, null, 'coursehome'); $nodes = $this->get_default_course_mapping(); $nodesordered = $this->get_leaf_nodes($settingsnav, $nodes['settings'] ?? []); @@ -381,17 +391,19 @@ class secondary extends view { // Try to get any custom nodes defined by a user which may include containers. $expectedcourseadmin = $this->get_expected_course_admin_nodes(); + $courseadminnode = $settingsnav; + if (!$issitecourse) { + $courseadminnode = $settingsnav->get('courseadmin'); + } - foreach ($settingsnav->children as $value) { - if ($value->key == 'courseadmin') { - foreach ($value->children as $other) { - if (array_search($other->key, $expectedcourseadmin) === false) { - $othernode = $this->get_first_action_for_node($other); - $recursivenode = $othernode && !$this->get($othernode->key) ? $othernode : $other; - // Get the first node and check whether it's been added already. - // Also check if the first node is an external link. If it is, add all children. - $this->add_external_nodes_to_secondary($recursivenode, $recursivenode); - } + if ($courseadminnode) { + foreach ($courseadminnode->children as $other) { + if (array_search($other->key, $expectedcourseadmin) === false) { + $othernode = $this->get_first_action_for_node($other); + $recursivenode = $othernode && !$this->get($othernode->key) ? $othernode : $other; + // Get the first node and check whether it's been added already. + // Also check if the first node is an external link. If it is, add all children. + $this->add_external_nodes_to_secondary($recursivenode, $recursivenode); } } } @@ -429,7 +441,7 @@ class secondary extends view { // Start with getting the base node for the front page or the course. $node = null; - if ($this->page->course == $SITE->id) { + if ($this->page->course->id == $SITE->id) { $node = $this->page->settingsnav->find('frontpage', navigation_node::TYPE_SETTING); } else { $node = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE); diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 01e55d549e6..b75670537cc 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -2961,7 +2961,8 @@ class global_navigation extends navigation_node { // Participants. if ($navoptions->participants) { - $coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id='.$course->id), self::TYPE_CUSTOM, get_string('participants'), 'participants'); + $coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id='.$course->id), + self::TYPE_CUSTOM, get_string('participants'), 'participants'); } // Blogs. @@ -5517,7 +5518,8 @@ class settings_navigation extends navigation_node { if ($adminoptions->update) { // Add the course settings link $url = new moodle_url('/admin/settings.php', array('section'=>'frontpagesettings')); - $frontpage->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', '')); + $frontpage->add(get_string('settings'), $url, self::TYPE_SETTING, null, + 'editsettings', new pix_icon('i/settings', '')); } // add enrol nodes @@ -5526,12 +5528,15 @@ class settings_navigation extends navigation_node { // Manage filters if ($adminoptions->filters) { $url = new moodle_url('/filter/manage.php', array('contextid'=>$coursecontext->id)); - $frontpage->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', '')); + $frontpage->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, + null, 'filtermanagement', new pix_icon('i/filter', '')); } // View course reports. if ($adminoptions->reports) { - $frontpagenav = $frontpage->add(get_string('reports'), null, self::TYPE_CONTAINER, null, 'frontpagereports', + $frontpagenav = $frontpage->add(get_string('reports'), new moodle_url('/report/view.php', + ['courseid' => $coursecontext->instanceid]), + self::TYPE_CONTAINER, null, 'coursereports', new pix_icon('i/stats', '')); $coursereports = core_component::get_plugin_list('coursereport'); foreach ($coursereports as $report=>$dir) { @@ -5554,13 +5559,13 @@ class settings_navigation extends navigation_node { // Backup this course if ($adminoptions->backup) { $url = new moodle_url('/backup/backup.php', array('id'=>$course->id)); - $frontpage->add(get_string('backup'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/backup', '')); + $frontpage->add(get_string('backup'), $url, self::TYPE_SETTING, null, 'backup', new pix_icon('i/backup', '')); } // Restore to this course if ($adminoptions->restore) { $url = new moodle_url('/backup/restorefile.php', array('contextid'=>$coursecontext->id)); - $frontpage->add(get_string('restore'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/restore', '')); + $frontpage->add(get_string('restore'), $url, self::TYPE_SETTING, null, 'restore', new pix_icon('i/restore', '')); } // Questions