[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/settings/ -> block_settings.php (source)

   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   * This file contains classes used to manage the navigation structures in Moodle
  19   * and was introduced as part of the changes occuring in Moodle 2.0
  20   *
  21   * @since Moodle 2.0
  22   * @package block_settings
  23   * @copyright 2009 Sam Hemelryk
  24   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  /**
  28   * The settings navigation tree block class
  29   *
  30   * Used to produce the settings navigation block new to Moodle 2.0
  31   *
  32   * @package block_settings
  33   * @copyright 2009 Sam Hemelryk
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class block_settings extends block_base {
  37  
  38      /** @var string */
  39      public static $navcount;
  40      public $blockname = null;
  41      /** @var bool */
  42      protected $contentgenerated = false;
  43      /** @var bool|null */
  44      protected $docked = null;
  45  
  46      /**
  47       * Set the initial properties for the block
  48       */
  49      function init() {
  50          $this->blockname = get_class($this);
  51          $this->title = get_string('pluginname', $this->blockname);
  52      }
  53  
  54      /**
  55       * All multiple instances of this block
  56       * @return bool Returns true
  57       */
  58      function instance_allow_multiple() {
  59          return false;
  60      }
  61  
  62      /**
  63       * The settings block cannot be hidden by default as it is integral to
  64       * the navigation of Moodle.
  65       *
  66       * @return false
  67       */
  68      function  instance_can_be_hidden() {
  69          return false;
  70      }
  71  
  72      /**
  73       * Set the applicable formats for this block to all
  74       * @return array
  75       */
  76      function applicable_formats() {
  77          return array('all' => true);
  78      }
  79  
  80      /**
  81       * Allow the user to configure a block instance
  82       * @return bool Returns true
  83       */
  84      function instance_allow_config() {
  85          return true;
  86      }
  87  
  88      function instance_can_be_docked() {
  89          return (parent::instance_can_be_docked() && (empty($this->config->enabledock) || $this->config->enabledock=='yes'));
  90      }
  91  
  92      function get_required_javascript() {
  93          global $PAGE;
  94          $adminnode = $PAGE->settingsnav->find('siteadministration', navigation_node::TYPE_SITE_ADMIN);
  95          parent::get_required_javascript();
  96          $arguments = array(
  97              'instanceid' => $this->instance->id,
  98              'adminnodeid' => $adminnode ? $adminnode->id : null
  99          );
 100          $this->page->requires->js_call_amd('block_settings/settingsblock', 'init', $arguments);
 101      }
 102  
 103      /**
 104       * Gets the content for this block by grabbing it from $this->page
 105       */
 106      function get_content() {
 107          global $CFG, $OUTPUT;
 108          // First check if we have already generated, don't waste cycles
 109          if ($this->contentgenerated === true) {
 110              return true;
 111          }
 112          // JS for navigation moved to the standard theme, the code will probably have to depend on the actual page structure
 113          // $this->page->requires->js('/lib/javascript-navigation.js');
 114          block_settings::$navcount++;
 115  
 116          // Check if this block has been docked
 117          if ($this->docked === null) {
 118              $this->docked = get_user_preferences('nav_in_tab_panel_settingsnav'.block_settings::$navcount, 0);
 119          }
 120  
 121          // Check if there is a param to change the docked state
 122          if ($this->docked && optional_param('undock', null, PARAM_INT)==$this->instance->id) {
 123              unset_user_preference('nav_in_tab_panel_settingsnav'.block_settings::$navcount, 0);
 124              $url = $this->page->url;
 125              $url->remove_params(array('undock'));
 126              redirect($url);
 127          } else if (!$this->docked && optional_param('dock', null, PARAM_INT)==$this->instance->id) {
 128              set_user_preferences(array('nav_in_tab_panel_settingsnav'.block_settings::$navcount=>1));
 129              $url = $this->page->url;
 130              $url->remove_params(array('dock'));
 131              redirect($url);
 132          }
 133  
 134          $renderer = $this->page->get_renderer('block_settings');
 135          $this->content = new stdClass();
 136          $this->content->text = $renderer->settings_tree($this->page->settingsnav);
 137  
 138          // only do search if you have moodle/site:config
 139          if (!empty($this->content->text)) {
 140              if (has_capability('moodle/site:config',context_system::instance()) ) {
 141                  $this->content->footer = $renderer->search_form(new moodle_url("$CFG->wwwroot/$CFG->admin/search.php"), optional_param('query', '', PARAM_RAW));
 142              } else {
 143                  $this->content->footer = '';
 144              }
 145  
 146              if (!empty($this->config->enabledock) && $this->config->enabledock == 'yes') {
 147                  user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav'.block_settings::$navcount, PARAM_INT);
 148              }
 149          }
 150  
 151          $this->contentgenerated = true;
 152          return true;
 153      }
 154  
 155      /**
 156       * Returns the role that best describes the settings block.
 157       *
 158       * @return string 'navigation'
 159       */
 160      public function get_aria_role() {
 161          return 'navigation';
 162      }
 163  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1