From 5725b0f950bea1ef8e38d33cbda57a05478c756e Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Mon, 7 Feb 2022 15:26:36 +1100 Subject: [PATCH] MDL-73721 enrol: Pre-fill enrolled users node Add the Enrolled users in the tertiary navigation when the user has the capability to view enrolled users but not review enrolments but has other user administration capabilities in the course. --- .../output/participants_action_bar.php | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/classes/output/participants_action_bar.php b/lib/classes/output/participants_action_bar.php index 8b9910fe699..e04bb17170b 100644 --- a/lib/classes/output/participants_action_bar.php +++ b/lib/classes/output/participants_action_bar.php @@ -16,6 +16,7 @@ namespace core\output; +use context_course; use moodle_page; use navigation_node; use moodle_url; @@ -84,8 +85,21 @@ class participants_action_bar implements \renderable { return []; } - $nodes = $this->get_ordered_nodes(); + // Pre-populate the formatted tertiary nav items with the "Enrolled users" node if user can view the participants page. + $coursecontext = context_course::instance($this->course->id); + $canviewparticipants = course_can_view_participants($coursecontext); $formattedcontent = []; + $enrolmentsheading = get_string('enrolments', 'enrol'); + if ($canviewparticipants) { + $participantsurl = (new moodle_url('/user/index.php', ['id' => $this->course->id]))->out(); + $formattedcontent[] = [ + $enrolmentsheading => [ + $participantsurl => get_string('enrolledusers', 'enrol'), + ] + ]; + } + + $nodes = $this->get_ordered_nodes(); foreach ($nodes as $description => $content) { list($stringid, $location) = explode(':', $description); $heading = get_string($stringid, $location); @@ -107,14 +121,18 @@ class participants_action_bar implements \renderable { } } if ($items) { - $formattedcontent[][$heading] = $items; + if ($heading === $enrolmentsheading) { + // Merge the contents of the "Enrolments" group with the ones from the course settings nav. + $formattedcontent[0][$heading] = array_merge($formattedcontent[0][$heading], $items); + } else { + $formattedcontent[][$heading] = $items; + } } } // Need to do some funky code here to find out if we have added third party navigation nodes. $thirdpartynodearray = $this->get_thirdparty_node_array() ?: []; - $formattedcontent = array_merge($formattedcontent, $thirdpartynodearray); - return $formattedcontent; + return array_merge($formattedcontent, $thirdpartynodearray); } /**