Merge branch 'MDL-70014_311' of https://github.com/stronk7/moodle into MOODLE_311_STABLE
[moodle.git] / contentbank / classes / helper.php
blob463f7ede33720ff3adf617ebe7886aa9e82febf9
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Contains helper class for the content bank.
20 * @package core_contentbank
21 * @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_contentbank;
27 /**
28 * Helper class for the content bank.
30 * @package core_contentbank
31 * @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class helper {
36 /**
37 * Getting content bank page ready for the breadcrumbs.
39 * @param \context $context Context of the current page.
40 * @param string $title Title of the current page.
41 * @param bool $internal True if is an internal page, false otherwise.
43 public static function get_page_ready(\context $context, string $title, bool $internal = false): void {
44 global $PAGE, $DB;
46 $PAGE->set_context($context);
47 $cburl = new \moodle_url('/contentbank/index.php', ['contextid' => $context->id]);
49 switch ($context->contextlevel) {
50 case CONTEXT_COURSE:
51 $courseid = $context->instanceid;
52 $course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
53 $PAGE->set_course($course);
54 \navigation_node::override_active_url(new \moodle_url('/course/view.php', ['id' => $courseid]));
55 $PAGE->navbar->add($title, $cburl);
56 $PAGE->set_pagelayout('incourse');
57 break;
58 case CONTEXT_COURSECAT:
59 $coursecat = $context->instanceid;
60 \navigation_node::override_active_url(new \moodle_url('/course/index.php', ['categoryid' => $coursecat]));
61 $PAGE->navbar->add($title, $cburl);
62 $PAGE->set_pagelayout('coursecategory');
63 break;
64 default:
65 if ($node = $PAGE->navigation->find('contentbank', \global_navigation::TYPE_CUSTOM)) {
66 $node->make_active();
68 $PAGE->set_pagelayout('standard');