Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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   * Page helper.
  19   *
  20   * @package    tool_dataprivacy
  21   * @copyright  2018 David Monllao
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_dataprivacy;
  26  use context_system;
  27  use moodle_url;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  /**
  32   * Page helper.
  33   *
  34   * @package    tool_dataprivacy
  35   * @copyright  2018 David Monllao
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class page_helper {
  39  
  40      /**
  41       * Sets up $PAGE for data privacy admin pages.
  42       *
  43       * @param moodle_url $url The page URL.
  44       * @param string $title The page's title.
  45       * @param string $attachtoparentnode The parent navigation node where this page can be accessed from.
  46       * @param string $requiredcapability The required capability to view this page.
  47       */
  48      public static function setup(moodle_url $url, $title, $attachtoparentnode = '',
  49                                   $requiredcapability = 'tool/dataprivacy:managedataregistry') {
  50          global $PAGE, $SITE;
  51  
  52          $context = context_system::instance();
  53  
  54          require_login();
  55          if (isguestuser()) {
  56              print_error('noguest');
  57          }
  58  
  59          // TODO Check that data privacy is enabled.
  60          require_capability($requiredcapability, $context);
  61  
  62          $PAGE->navigation->override_active_url($url);
  63  
  64          $PAGE->set_url($url);
  65          $PAGE->set_context($context);
  66          $PAGE->set_pagelayout('admin');
  67          $PAGE->set_title($title);
  68          $PAGE->set_heading($SITE->fullname);
  69  
  70          // If necessary, override the settings navigation to add this page into the breadcrumb navigation.
  71          if ($attachtoparentnode) {
  72              if ($siteadmin = $PAGE->settingsnav->find('root', \navigation_node::TYPE_SITE_ADMIN)) {
  73                  $PAGE->navbar->add($siteadmin->get_content(), $siteadmin->action());
  74              }
  75              if ($dataprivacy = $PAGE->settingsnav->find('privacy', \navigation_node::TYPE_SETTING)) {
  76                  $PAGE->navbar->add($dataprivacy->get_content(), $dataprivacy->action());
  77              }
  78              if ($dataregistry = $PAGE->settingsnav->find($attachtoparentnode, \navigation_node::TYPE_SETTING)) {
  79                  $PAGE->navbar->add($dataregistry->get_content(), $dataregistry->action());
  80              }
  81  
  82              $PAGE->navbar->add($title, $url);
  83          }
  84      }
  85  }