See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]
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. 13 // 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/>. 16 17 /** 18 * Contains helper class for the content bank. 19 * 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 23 */ 24 25 namespace core_contentbank; 26 27 /** 28 * Helper class for the content bank. 29 * 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 33 */ 34 class helper { 35 36 /** 37 * Getting content bank page ready for the breadcrumbs. 38 * 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. 42 */ 43 public static function get_page_ready(\context $context, string $title, bool $internal = false): void { 44 global $PAGE, $DB; 45 46 $PAGE->set_context($context); 47 $PAGE->set_heading(self::get_page_heading($context)); 48 $PAGE->set_secondary_active_tab('contentbank'); 49 $cburl = new \moodle_url('/contentbank/index.php', ['contextid' => $context->id]); 50 51 switch ($context->contextlevel) { 52 case CONTEXT_COURSE: 53 $courseid = $context->instanceid; 54 $course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST); 55 $PAGE->set_course($course); 56 \navigation_node::override_active_url(new \moodle_url('/course/view.php', ['id' => $courseid])); 57 $PAGE->navbar->add($title, $cburl); 58 $PAGE->set_pagelayout('incourse'); 59 break; 60 case CONTEXT_COURSECAT: 61 $coursecat = $context->instanceid; 62 \navigation_node::override_active_url(new \moodle_url('/course/index.php', ['categoryid' => $coursecat])); 63 $PAGE->navbar->add($title, $cburl); 64 $PAGE->set_pagelayout('coursecategory'); 65 break; 66 default: 67 if ($node = $PAGE->navigation->find('contentbank', \global_navigation::TYPE_CUSTOM)) { 68 $node->make_active(); 69 } 70 $PAGE->set_pagelayout('standard'); 71 } 72 } 73 74 /** 75 * Get the page heading based on the current context 76 * 77 * @param \context $context The current context of the page 78 * @return string 79 */ 80 public static function get_page_heading(\context $context): string { 81 global $SITE; 82 83 $title = get_string('contentbank'); 84 if ($context->id == \context_system::instance()->id) { 85 $title = $SITE->fullname; 86 } else if ($context->contextlevel == CONTEXT_COURSE) { 87 $course = get_course($context->instanceid); 88 $title = $course->fullname; 89 } else if ($context->contextlevel == CONTEXT_COURSECAT) { 90 $category = \core_course_category::get($context->instanceid); 91 $title = $category->get_formatted_name(); 92 } 93 94 return $title; 95 } 96 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body