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