Moodle 2.2.4 release
[moodle.git] / blocks / settings / block_settings.php
blob3e2aea838e3f249f277bfc79d970400f72a1eef0
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This file contains classes used to manage the navigation structures in Moodle
20 * and was introduced as part of the changes occuring in Moodle 2.0
22 * @since 2.0
23 * @package blocks
24 * @copyright 2009 Sam Hemelryk
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 /**
29 * The settings navigation tree block class
31 * Used to produce the settings navigation block new to Moodle 2.0
33 * @package blocks
34 * @copyright 2009 Sam Hemelryk
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class block_settings extends block_base {
39 /** @var string */
40 public static $navcount;
41 public $blockname = null;
42 /** @var bool */
43 protected $contentgenerated = false;
44 /** @var bool|null */
45 protected $docked = null;
47 /**
48 * Set the initial properties for the block
50 function init() {
51 $this->blockname = get_class($this);
52 $this->title = get_string('pluginname', $this->blockname);
55 /**
56 * All multiple instances of this block
57 * @return bool Returns true
59 function instance_allow_multiple() {
60 return false;
63 /**
64 * The settings block cannot be hidden by default as it is integral to
65 * the navigation of Moodle.
67 * @return false
69 function instance_can_be_hidden() {
70 return false;
73 /**
74 * Set the applicable formats for this block to all
75 * @return array
77 function applicable_formats() {
78 return array('all' => true);
81 /**
82 * Allow the user to configure a block instance
83 * @return bool Returns true
85 function instance_allow_config() {
86 return true;
89 function instance_can_be_docked() {
90 return (parent::instance_can_be_docked() && (empty($this->config->enabledock) || $this->config->enabledock=='yes'));
93 function get_required_javascript() {
94 global $CFG;
95 $arguments = array('id' => $this->instance->id, 'instance' => $this->instance->id, 'candock' => $this->instance_can_be_docked());
96 $this->page->requires->yui_module(array('core_dock', 'moodle-block_navigation-navigation'), 'M.block_navigation.init_add_tree', array($arguments));
97 user_preference_allow_ajax_update('docked_block_instance_'.$this->instance->id, PARAM_INT);
101 * Gets the content for this block by grabbing it from $this->page
103 function get_content() {
104 global $CFG, $OUTPUT;
105 // First check if we have already generated, don't waste cycles
106 if ($this->contentgenerated === true) {
107 return true;
109 // JS for navigation moved to the standard theme, the code will probably have to depend on the actual page structure
110 // $this->page->requires->js('/lib/javascript-navigation.js');
111 block_settings::$navcount++;
113 // Check if this block has been docked
114 if ($this->docked === null) {
115 $this->docked = get_user_preferences('nav_in_tab_panel_settingsnav'.block_settings::$navcount, 0);
118 // Check if there is a param to change the docked state
119 if ($this->docked && optional_param('undock', null, PARAM_INT)==$this->instance->id) {
120 unset_user_preference('nav_in_tab_panel_settingsnav'.block_settings::$navcount, 0);
121 $url = $this->page->url;
122 $url->remove_params(array('undock'));
123 redirect($url);
124 } else if (!$this->docked && optional_param('dock', null, PARAM_INT)==$this->instance->id) {
125 set_user_preferences(array('nav_in_tab_panel_settingsnav'.block_settings::$navcount=>1));
126 $url = $this->page->url;
127 $url->remove_params(array('dock'));
128 redirect($url);
131 $renderer = $this->page->get_renderer('block_settings');
132 $this->content = new stdClass();
133 $this->content->text = $renderer->settings_tree($this->page->settingsnav);
135 // only do search if you have moodle/site:config
136 if (!empty($this->content->text)) {
137 if (has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) ) {
138 $this->content->footer = $renderer->search_form(new moodle_url("$CFG->wwwroot/$CFG->admin/search.php"), optional_param('query', '', PARAM_RAW));
139 } else {
140 $this->content->footer = '';
143 if (!empty($this->config->enabledock) && $this->config->enabledock == 'yes') {
144 user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav'.block_settings::$navcount, PARAM_INT);
148 $this->contentgenerated = true;
149 return true;