Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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          $cburl = new \moodle_url('/contentbank/index.php', ['contextid' => $context->id]);
  48  
  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();
  67                  }
  68                  $PAGE->set_pagelayout('standard');
  69          }
  70      }
  71  }