mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-73373 roles: Enable tertiary navigation in module context
This commit is contained in:
parent
6652ec135b
commit
81492f900f
@ -183,6 +183,12 @@ switch ($context->contextlevel) {
|
||||
break;
|
||||
}
|
||||
|
||||
$PAGE->set_navigation_overflow_state(false);
|
||||
|
||||
// Within a course context we need to explicitly set active tab as there isn't a reference in the nav tree.
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$PAGE->set_secondary_active_tab('participants');
|
||||
}
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$backurl = null;
|
||||
@ -199,7 +205,7 @@ if ($roleid) {
|
||||
|
||||
if ($backurl) {
|
||||
echo $OUTPUT->render(new single_button($backurl, get_string('back'), 'get'));
|
||||
} else if ($isfrontpage) {
|
||||
} else if ($context->contextlevel == CONTEXT_COURSE || $context->contextlevel == CONTEXT_MODULE) {
|
||||
// The front page doesn't have an intermediate page 'other users' but needs similar tertiary nav like a standard course.
|
||||
echo $OUTPUT->render_participants_tertiary_nav($course);
|
||||
}
|
||||
|
@ -126,9 +126,9 @@ if (!is_null($reportuser)) {
|
||||
$rolenames = role_get_names($context);
|
||||
}
|
||||
|
||||
$PAGE->set_navigation_overflow_state(false);
|
||||
echo $OUTPUT->header();
|
||||
// Display the participants tertiary action bar if within a course context.
|
||||
if ($course && $context->contextlevel == CONTEXT_COURSE) {
|
||||
if ($context->contextlevel == CONTEXT_COURSE || $context->contextlevel == CONTEXT_MODULE) {
|
||||
echo $OUTPUT->render_participants_tertiary_nav($course);
|
||||
}
|
||||
|
||||
|
@ -204,10 +204,12 @@ if ($capability && ($allowoverrides || ($allowsafeoverrides && is_safe_capabilit
|
||||
}
|
||||
}
|
||||
|
||||
$PAGE->set_navigation_overflow_state(false);
|
||||
echo $OUTPUT->header();
|
||||
if ($context->contextlevel == CONTEXT_COURSE && $course) {
|
||||
if ($context->contextlevel == CONTEXT_COURSE || $context->contextlevel == CONTEXT_MODULE) {
|
||||
echo $OUTPUT->render_participants_tertiary_nav($course);
|
||||
}
|
||||
|
||||
echo $OUTPUT->heading($title);
|
||||
|
||||
$adminurl = new moodle_url('/admin/');
|
||||
|
@ -88,6 +88,7 @@ class secondary extends view {
|
||||
],
|
||||
self::TYPE_CUSTOM => [
|
||||
'contentbank' => 5,
|
||||
'participants' => 1, // In site home, 'participants' is classified differently.
|
||||
],
|
||||
];
|
||||
|
||||
@ -109,7 +110,7 @@ class secondary extends view {
|
||||
'modedit' => 1,
|
||||
"mod_{$this->page->activityname}_useroverrides" => 3, // Overrides are module specific.
|
||||
"mod_{$this->page->activityname}_groupoverrides" => 4,
|
||||
'roleassign' => 5,
|
||||
'roleassign' => 7.2,
|
||||
'filtermanage' => 6,
|
||||
'roleoverride' => 7,
|
||||
'rolecheck' => 7.1,
|
||||
|
@ -73,7 +73,7 @@ abstract class view extends navigation_node {
|
||||
foreach ($nodes as $type => $leaves) {
|
||||
foreach ($leaves as $leaf => $location) {
|
||||
if ($node = $source->find($leaf, $type)) {
|
||||
$nodesordered["$location"] = $node;
|
||||
$nodesordered["$location"] = $nodesordered["$location"] ?? $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,8 @@ class participants_action_bar implements \renderable {
|
||||
public function __construct(object $course, moodle_page $page, ?string $renderedcontent) {
|
||||
$this->course = $course;
|
||||
$this->page = $page;
|
||||
$this->node = $this->page->settingsnav->find('users', navigation_node::TYPE_CONTAINER);
|
||||
$node = $this->page->context->contextlevel == CONTEXT_MODULE ? 'modulesettings' : 'users';
|
||||
$this->node = $this->page->settingsnav->find($node, null);
|
||||
$this->renderedcontent = $renderedcontent;
|
||||
}
|
||||
|
||||
@ -69,7 +70,10 @@ class participants_action_bar implements \renderable {
|
||||
'override',
|
||||
'roles',
|
||||
'otherusers',
|
||||
'permissions'
|
||||
'permissions',
|
||||
'roleoverride',
|
||||
'rolecheck',
|
||||
'roleassign',
|
||||
]
|
||||
];
|
||||
}
|
||||
@ -111,9 +115,12 @@ class participants_action_bar implements \renderable {
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
// If we are accessing a page from a module context additional nodes will not be visible.
|
||||
if ($this->page->context->contextlevel !== CONTEXT_MODULE) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
82
lib/tests/output/participants_action_bar_test.php
Normal file
82
lib/tests/output/participants_action_bar_test.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core\output;
|
||||
use ReflectionMethod;
|
||||
|
||||
/**
|
||||
* Participants tertiary navigation renderable test
|
||||
*
|
||||
* @package core
|
||||
* @category output
|
||||
* @copyright 2021 onwards Peter Dias
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class participants_action_bar_test extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test the get_content_for_select function
|
||||
*
|
||||
* @dataProvider get_content_for_select_provider
|
||||
* @param string $type Whether we are checking content in the course/module
|
||||
* @param int $expectedcount Expected number of 1st level tertiary items
|
||||
* @param array $expecteditems Expected keys of the 1st level tertiary items.
|
||||
*/
|
||||
public function test_get_content_for_select($type, $expectedcount, $expecteditems) {
|
||||
global $PAGE;
|
||||
$this->resetAfterTest();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$module = $this->getDataGenerator()->create_module('assign', [
|
||||
'course' => $course->id
|
||||
]);
|
||||
if ($type == 'course') {
|
||||
$context = \context_course::instance($course->id);
|
||||
$url = new \moodle_url('/course/view.php', ['id' => $course->id]);
|
||||
} else {
|
||||
$url = new \moodle_url('/mod/assign/view.php', ['id' => $module->id]);
|
||||
$context = \context_module::instance($module->cmid);
|
||||
$cm = get_coursemodule_from_instance('assign', $module->id, $course->id);
|
||||
$PAGE->set_cm($cm);
|
||||
}
|
||||
|
||||
$this->setAdminUser();
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_context($context);
|
||||
$output = new participants_action_bar($course, $PAGE, null);
|
||||
$method = new ReflectionMethod('\core\output\participants_action_bar', 'get_content_for_select');
|
||||
$method->setAccessible(true);
|
||||
$renderer = $PAGE->get_renderer('core');
|
||||
|
||||
$response = $method->invoke($output, $renderer);
|
||||
$this->assertCount($expectedcount, $response);
|
||||
$this->assertSame($expecteditems, array_keys(array_merge(...$response)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for test_get_content_for_select
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_content_for_select_provider() {
|
||||
return [
|
||||
'Get dropdown content when in a course context' => [
|
||||
'course', 3, ['Enrolments', 'Groups', 'Permissions']
|
||||
],
|
||||
'Get dropdown content when in a module context' => [
|
||||
'module', 1, ['Permissions']
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
@ -117,7 +117,7 @@ echo $OUTPUT->render_participants_tertiary_nav($course, html_writer::div($enrolb
|
||||
'data-table-uniqueid' => $participanttable->uniqueid,
|
||||
]));
|
||||
|
||||
echo $OUTPUT->heading(get_string('participants'));
|
||||
echo $OUTPUT->heading(get_string('enrolledusers', 'enrol'));
|
||||
|
||||
$filterset = new \core_user\table\participants_filterset();
|
||||
$filterset->add_filter(new integer_filter('courseid', filter::JOINTYPE_DEFAULT, [(int)$course->id]));
|
||||
|
Loading…
x
Reference in New Issue
Block a user