Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 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   * Admin Bookmarks Block page.
  19   *
  20   * @package    block_admin_bookmarks
  21   * @copyright  2011 Moodle
  22   * @author     2006 vinkmar
  23   *             2011 Rossiani Wijaya (updated)
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  /**
  28   * The admin bookmarks block class
  29   */
  30  class block_admin_bookmarks extends block_base {
  31  
  32      /** @var string */
  33      public $blockname = null;
  34  
  35  
  36      /** @var bool|null */
  37      protected $docked = null;
  38  
  39      /**
  40       * Set the initial properties for the block
  41       */
  42      function init() {
  43          $this->blockname = get_class($this);
  44          $this->title = get_string('pluginname', $this->blockname);
  45      }
  46  
  47      /**
  48       * All multiple instances of this block
  49       * @return bool Returns false
  50       */
  51      function instance_allow_multiple() {
  52          return false;
  53      }
  54  
  55      /**
  56       * Set the applicable formats for this block to all
  57       * @return array
  58       */
  59      function applicable_formats() {
  60          if (has_capability('moodle/site:config', context_system::instance())) {
  61              return array('all' => true);
  62          } else {
  63              return array('site' => true);
  64          }
  65      }
  66  
  67      /**
  68       * Gets the content for this block
  69       */
  70      function get_content() {
  71  
  72          global $CFG;
  73  
  74          // First check if we have already generated, don't waste cycles
  75          if ($this->content !== null) {
  76              return $this->content;
  77          }
  78  
  79          $this->content = new stdClass();
  80  
  81          if (get_user_preferences('admin_bookmarks')) {
  82              require_once($CFG->libdir.'/adminlib.php');
  83              $adminroot = admin_get_root(false, false);  // settings not required - only pages
  84  
  85              $bookmarks = explode(',', get_user_preferences('admin_bookmarks'));
  86              /// Accessibility: markup as a list.
  87              $contents = array();
  88              foreach($bookmarks as $bookmark) {
  89                  $temp = $adminroot->locate($bookmark);
  90                  if ($temp instanceof admin_settingpage) {
  91                      $contenturl = new moodle_url('/admin/settings.php', array('section'=>$bookmark));
  92                      $contentlink = html_writer::link($contenturl, $temp->visiblename);
  93                      $contents[] = html_writer::tag('li', $contentlink);
  94                  } else if ($temp instanceof admin_externalpage) {
  95                      $contenturl = new moodle_url($temp->url);
  96                      $contentlink = html_writer::link($contenturl, $temp->visiblename);
  97                      $contents[] = html_writer::tag('li', $contentlink);
  98                  } else if ($temp instanceof admin_category) {
  99                      $contenturl = new moodle_url('/admin/category.php', array('category' => $bookmark));
 100                      $contentlink = html_writer::link($contenturl, $temp->visiblename);
 101                      $contents[] = html_writer::tag('li', $contentlink);
 102                  }
 103              }
 104              $this->content->text = html_writer::tag('ol', implode('', $contents), array('class' => 'list'));
 105          } else {
 106              $bookmarks = array();
 107          }
 108  
 109          $this->content->footer = '';
 110          $this->page->settingsnav->initialise();
 111          $node = $this->page->settingsnav->get('root', navigation_node::TYPE_SITE_ADMIN);
 112          if (!$node || !$node->contains_active_node()) {
 113              return $this->content;
 114          }
 115          $section = $node->find_active_node()->key;
 116  
 117          if ($section == 'search' || empty($section)){
 118              // the search page can't be properly bookmarked at present
 119              $this->content->footer = '';
 120          } else if (in_array($section, $bookmarks)) {
 121              $deleteurl = new moodle_url('/blocks/admin_bookmarks/delete.php', array('section'=>$section, 'sesskey'=>sesskey()));
 122              $this->content->footer =  html_writer::link($deleteurl, get_string('unbookmarkthispage','admin'));
 123          } else {
 124              $createurl = new moodle_url('/blocks/admin_bookmarks/create.php', array('section'=>$section, 'sesskey'=>sesskey()));
 125              $this->content->footer = html_writer::link($createurl, get_string('bookmarkthispage','admin'));
 126          }
 127  
 128          return $this->content;
 129      }
 130  
 131      /**
 132       * Returns the role that best describes the admin bookmarks block.
 133       *
 134       * @return string
 135       */
 136      public function get_aria_role() {
 137          return 'navigation';
 138      }
 139  }
 140  
 141