Skip to content

Commit

Permalink
Merge branch 'MDL-73316' of https://github.com/Chocolate-lightning/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 17, 2022
2 parents 472568f + 0d279d3 commit 4f0b70b
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
7 changes: 6 additions & 1 deletion contentbank/index.php
Expand Up @@ -46,11 +46,16 @@
require_login($PAGE->course->id);
}
$PAGE->set_url('/contentbank/index.php');
$PAGE->set_context($context);
if ($contextid == \context_system::instance()->id) {
$PAGE->set_context(context_course::instance($contextid));
} else {
$PAGE->set_context($context);
}
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->add_body_class('limitedwidth');
$PAGE->set_pagetype('contentbank');
$PAGE->set_secondary_active_tab('contentbank');

// Get all contents managed by active plugins where the user has permission to render them.
$contenttypes = [];
Expand Down
1 change: 1 addition & 0 deletions course/admin.php
Expand Up @@ -38,6 +38,7 @@
if ($courseid == $SITE->id) {
$title = get_string('frontpagesettings');
$node = $PAGE->settingsnav->find('frontpage', navigation_node::TYPE_SETTING);
$PAGE->set_primary_active_tab('home');
} else {
$title = get_string('courseadministration');
$node = $PAGE->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE);
Expand Down
2 changes: 1 addition & 1 deletion course/view.php
Expand Up @@ -207,7 +207,7 @@

if ($course->id == SITEID) {
// This course is not a real course.
redirect($CFG->wwwroot .'/');
redirect($CFG->wwwroot .'/?redirect=0');
}

// Determine whether the user has permission to download course content.
Expand Down
8 changes: 7 additions & 1 deletion index.php
Expand Up @@ -102,7 +102,13 @@
$editing = $PAGE->user_is_editing();
$PAGE->set_title($SITE->fullname);
$PAGE->set_heading($SITE->fullname);
$PAGE->has_secondary_navigation_setter(false);
if (has_capability('moodle/course:update', context_system::instance())) {
$PAGE->has_secondary_navigation_setter(true);
$PAGE->set_secondary_active_tab('coursehome');
} else {
$PAGE->has_secondary_navigation_setter(false);
}

$courserenderer = $PAGE->get_renderer('core', 'course');

if ($hassiteconfig) {
Expand Down
39 changes: 31 additions & 8 deletions lib/classes/navigation/views/secondary.php
Expand Up @@ -120,10 +120,24 @@ protected function get_default_module_mapping(): array {
],
self::TYPE_CUSTOM => [
'advgrading' => 2,
'contentbank' => 12,
],
];
}

/**
* Defines the default structure for the secondary nav in a category context.
*
* In a category context, we are curating nodes from the settingsnav object.
* The following mapping construct specifies the type of the node, the key
* and in what order we want the node - defined as per the mockups.
*
* @return array
*/
protected function get_default_category_mapping(): array {
return [];
}

/**
* Define the keys of the course secondary nav nodes that should be forced into the "more" menu by default.
*
Expand Down Expand Up @@ -174,11 +188,9 @@ public function initialise(): void {

switch ($context->contextlevel) {
case CONTEXT_COURSE:
if ($this->page->course->id != $SITE->id) {
$this->headertitle = get_string('courseheader');
$this->load_course_navigation();
$defaultmoremenunodes = $this->get_default_course_more_menu_nodes();
}
$this->headertitle = get_string('courseheader');
$this->load_course_navigation();
$defaultmoremenunodes = $this->get_default_course_more_menu_nodes();
break;
case CONTEXT_MODULE:
$this->headertitle = get_string('activityheader');
Expand Down Expand Up @@ -371,7 +383,7 @@ protected function get_course_overflow_nodes(): ?navigation_node {
} else {
$node = $this->page->settingsnav->find('courseadmin', navigation_node::TYPE_COURSE);
}
$coursesettings = $node->get_children_key_list();
$coursesettings = $node ? $node->get_children_key_list() : [];
$thissettings = $this->get_children_key_list();
$diff = array_diff($coursesettings, $thissettings);

Expand Down Expand Up @@ -565,18 +577,27 @@ protected function load_module_navigation(): void {
protected function load_category_navigation(): void {
$settingsnav = $this->page->settingsnav;
$mainnode = $settingsnav->find('categorysettings', self::TYPE_CONTAINER);
$nodes = $this->get_default_category_mapping();

if ($mainnode) {
$url = new \moodle_url('/course/index.php', ['categoryid' => $this->context->instanceid]);
$this->add($this->context->get_context_name(), $url, self::TYPE_CONTAINER, null, 'categorymain');
$this->load_remaining_nodes($mainnode, []);

// Add the initial nodes.
$nodesordered = $this->get_leaf_nodes($mainnode, $nodes);
$this->add_ordered_nodes($nodesordered);

// We have finished inserting the initial structure.
// Populate the menu with the rest of the nodes available.
$this->load_remaining_nodes($mainnode, $nodes);
}
}

/**
* Load the site admin navigation
*/
protected function load_admin_navigation(): void {
global $PAGE;
global $PAGE, $SITE;

$settingsnav = $this->page->settingsnav;
$node = $settingsnav->find('root', self::TYPE_SITE_ADMIN);
Expand Down Expand Up @@ -607,6 +628,8 @@ protected function load_admin_navigation(): void {
$siteadminnode->add_node(clone $child);
}
}
} else if ($this->page->course->id == $SITE->id) {
$this->load_course_navigation();
}
}

Expand Down
9 changes: 9 additions & 0 deletions lib/navigationlib.php
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core_contentbank\contentbank;

defined('MOODLE_INTERNAL') || die();

/**
Expand Down Expand Up @@ -5357,6 +5359,13 @@ protected function load_category_settings() {
$categorynode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'checkpermissions', new pix_icon('i/checkpermissions', ''));
}

$cb = new contentbank();
if ($cb->is_context_allowed($catcontext)
&& has_capability('moodle/contentbank:access', $catcontext)) {
$url = new \moodle_url('/contentbank/index.php', ['contextid' => $catcontext->id]);
$categorynode->add(get_string('contentbank'), $url, self::TYPE_CUSTOM, null, 'contentbank', new \pix_icon('i/contentbank', ''));
}

// Add the context locking node.
$this->add_context_locking_node($categorynode, $catcontext);

Expand Down
3 changes: 3 additions & 0 deletions question/bank/editquestion/question.php
Expand Up @@ -339,6 +339,9 @@
$PAGE->set_heading($COURSE->fullname);
$PAGE->activityheader->disable();
$PAGE->navbar->add($streditingquestion);
if ($PAGE->course->id == $SITE->id) {
$PAGE->set_primary_active_tab('home');
}

// Display a heading, question editing form and possibly some extra content needed for
// for this question type.
Expand Down
4 changes: 4 additions & 0 deletions question/edit.php
Expand Up @@ -36,6 +36,10 @@
}
$PAGE->set_url($url);

if ($PAGE->course->id == $SITE->id) {
$PAGE->set_primary_active_tab('home');
}

$questionbank = new core_question\local\bank\view($contexts, $thispageurl, $COURSE, $cm);

$context = $contexts->lowest();
Expand Down

0 comments on commit 4f0b70b

Please sign in to comment.