Merge branch 'MDL-73373-master' of https://github.com/peterRd/moodle

This commit is contained in:
Jun Pataleta 2022-02-16 21:14:26 +08:00
commit 6b65550240
13 changed files with 141 additions and 30 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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/');

View File

@ -55,7 +55,8 @@ Feature: Staff can assign user roles
@javascript
Scenario: Enrol at activity level using custom field search
When I am on the "page1" "Activity" page logged in as "admin"
And I navigate to "Locally assigned roles" in current page administration
And I navigate to "Permissions" in current page administration
And I select "Locally assigned roles" from the "jump" singleselect
And I follow "Teacher"
And I set the field "addselect_searchtext" to "Kermit"
# The Behat 'I should see' step doesn't work for optgroup labels.
@ -70,7 +71,8 @@ Feature: Staff can assign user roles
| user | role | contextlevel | reference |
| user1 | editingteacher | Activity module | page1 |
When I am on the "page1" "Activity" page logged in as "admin"
And I navigate to "Locally assigned roles" in current page administration
And I navigate to "Permissions" in current page administration
And I select "Locally assigned roles" from the "jump" singleselect
And I follow "Teacher"
And I set the field "removeselect_searchtext" to "Kermit"
# The Behat 'I should see' step doesn't work for optgroup labels.

View File

@ -89,6 +89,7 @@ class secondary extends view {
],
self::TYPE_CUSTOM => [
'contentbank' => 5,
'participants' => 1, // In site home, 'participants' is classified differently.
],
];
@ -110,7 +111,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,

View File

@ -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;
}
}
}

View File

@ -47,7 +47,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;
}
@ -70,7 +71,10 @@ class participants_action_bar implements \renderable {
'override',
'roles',
'otherusers',
'permissions'
'permissions',
'roleoverride',
'rolecheck',
'roleassign',
]
];
}
@ -130,9 +134,13 @@ 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() ?: [];
return 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;
}
/**

View File

@ -1341,7 +1341,8 @@ class global_navigation extends navigation_node {
// courses: Additional courses are added here.
// users: Other users information loaded here.
$this->rootnodes = array();
if (get_home_page() == HOMEPAGE_SITE) {
$defaulthomepage = get_home_page();
if ($defaulthomepage == HOMEPAGE_SITE) {
// The home element should be my moodle because the root element is the site
if (isloggedin() && !isguestuser()) { // Makes no sense if you aren't logged in
$this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'),
@ -1370,6 +1371,12 @@ class global_navigation extends navigation_node {
'mycourses',
new pix_icon('i/course', '')
);
// We do not need to show this node in the breadcrumbs if the default homepage is mycourses.
// It will be automatically handled by the breadcrumb generator.
if ($defaulthomepage == HOMEPAGE_MYCOURSES) {
$this->rootnodes['mycourses']->mainnavonly = true;
}
$this->rootnodes['courses'] = $this->add(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_ROOTNODE, null, 'courses');
if (!core_course_category::user_top()) {
$this->rootnodes['courses']->hide();

View 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']
]
];
}
}

View File

@ -35,34 +35,35 @@ Feature: In a book, verify log entries
And I navigate to "Print book" in current page administration
And I am on the "Test book" "book activity" page
And I navigate to "Download IMS CP" in current page administration
And I am on the "Test book" "book activity" page
And I navigate to "Logs" in current page administration
And I navigate to "Reports > Logs" in site administration
And I set the field "menuid" to "Course 1"
And I press "Get these logs"
Then I should see "Book exported"
And I should see "Book printed"
And I should see "Chapter viewed" in the "#report_log_r4_c5" "css_element"
And I should see "Chapter viewed" in the "#report_log_r5_c5" "css_element"
And I should see "Chapter viewed" in the "#report_log_r6_c5" "css_element"
And I should see "Chapter viewed" in the "#report_log_r7_c5" "css_element"
And I should see "Chapter updated" in the "#report_log_r7_c5" "css_element"
And I should see "Chapter viewed" in the "#report_log_r8_c5" "css_element"
And I should see "Chapter updated" in the "#report_log_r9_c5" "css_element"
And I should see "Chapter viewed" in the "#report_log_r10_c5" "css_element"
And I should see "Chapter created" in the "#report_log_r11_c5" "css_element"
And I click on "Chapter viewed" "link" in the "#report_log_r6_c5" "css_element"
And I should see "Chapter created" in the "#report_log_r9_c5" "css_element"
And I click on "Chapter viewed" "link" in the "#report_log_r4_c5" "css_element"
And I switch to "action" window
And I change window size to "large"
And I should see "1. First chapter edited" in the ".book_content" "css_element"
And I switch to the main window
And I click on "Chapter viewed" "link" in the "#report_log_r7_c5" "css_element"
And I click on "Chapter viewed" "link" in the "#report_log_r5_c5" "css_element"
And I switch to "action" window
And I should see "2. Second chapter" in the ".book_content" "css_element"
And I switch to the main window
And I click on "Chapter updated" "link" in the "#report_log_r9_c5" "css_element"
And I click on "Chapter updated" "link" in the "#report_log_r7_c5" "css_element"
And I switch to "action" window
And I should see "1. First chapter edited" in the ".book_content" "css_element"
And I switch to the main window
And I click on "Chapter created" "link" in the "#report_log_r9_c5" "css_element"
And I switch to "action" window
And I should see "2. Second chapter" in the ".book_content" "css_element"
And I switch to the main window
And I click on "Chapter created" "link" in the "#report_log_r11_c5" "css_element"
And I switch to "action" window
And I should see "2. Second chapter" in the ".book_content" "css_element"
And I switch to the main window
And I click on "Chapter created" "link" in the "#report_log_r13_c5" "css_element"
And I switch to "action" window
And I should see "1. First chapter edited" in the ".book_content" "css_element"
And I switch to the main window

View File

@ -60,6 +60,7 @@ function report_competency_extend_navigation_module($navigation, $cm) {
context_course::instance($cm->course))) {
$url = new moodle_url('/report/competency/index.php', array('id' => $cm->course, 'mod' => $cm->id));
$name = get_string('pluginname', 'report_competency');
$navigation->add($name, $url, navigation_node::TYPE_SETTING, null, 'competencybreakdown');
$navigation->add($name, $url, navigation_node::TYPE_SETTING, null, 'competencybreakdown')
->set_show_in_secondary_navigation(false);
}
}

View File

@ -126,7 +126,8 @@ function report_log_can_access_user_report($user, $course) {
function report_log_extend_navigation_module($navigation, $cm) {
if (has_capability('report/log:view', context_course::instance($cm->course))) {
$url = new moodle_url('/report/log/index.php', array('chooselog'=>'1','id'=>$cm->course,'modid'=>$cm->id));
$navigation->add(get_string('logs'), $url, navigation_node::TYPE_SETTING, null, 'logreport');
$navigation->add(get_string('logs'), $url, navigation_node::TYPE_SETTING, null, 'logreport')
->set_show_in_secondary_navigation(false);
}
}

View File

@ -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]));