2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
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
22 * @package block_settings
23 * @copyright 2009 Sam Hemelryk
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * The settings navigation tree block class
30 * Used to produce the settings navigation block new to Moodle 2.0
32 * @package block_settings
33 * @copyright 2009 Sam Hemelryk
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class block_settings
extends block_base
{
39 public static $navcount;
40 public $blockname = null;
42 protected $contentgenerated = false;
44 protected $docked = null;
47 * Set the initial properties for the block
50 $this->blockname
= get_class($this);
51 $this->title
= get_string('pluginname', $this->blockname
);
55 * All multiple instances of this block
56 * @return bool Returns true
58 function instance_allow_multiple() {
63 * The settings block cannot be hidden by default as it is integral to
64 * the navigation of Moodle.
68 function instance_can_be_hidden() {
73 * Set the applicable formats for this block to all
76 function applicable_formats() {
77 return array('all' => true);
81 * Allow the user to configure a block instance
82 * @return bool Returns true
84 function instance_allow_config() {
88 function instance_can_be_docked() {
89 return (parent
::instance_can_be_docked() && (empty($this->config
->enabledock
) ||
$this->config
->enabledock
=='yes'));
92 function get_required_javascript() {
93 $adminnode = $this->page
->settingsnav
->find('siteadministration', navigation_node
::TYPE_SITE_ADMIN
);
94 parent
::get_required_javascript();
96 'instanceid' => $this->instance
->id
,
97 'adminnodeid' => $adminnode ?
$adminnode->id
: null
99 $this->page
->requires
->js_call_amd('block_settings/settingsblock', 'init', $arguments);
103 * Gets the content for this block by grabbing it from $this->page
105 function get_content() {
106 global $CFG, $OUTPUT;
107 // First check if we have already generated, don't waste cycles
108 if ($this->contentgenerated
=== true) {
111 // JS for navigation moved to the standard theme, the code will probably have to depend on the actual page structure
112 // $this->page->requires->js('/lib/javascript-navigation.js');
113 block_settings
::$navcount++
;
115 // Check if this block has been docked
116 if ($this->docked
=== null) {
117 $this->docked
= get_user_preferences('nav_in_tab_panel_settingsnav'.block_settings
::$navcount, 0);
120 // Check if there is a param to change the docked state
121 if ($this->docked
&& optional_param('undock', null, PARAM_INT
)==$this->instance
->id
) {
122 unset_user_preference('nav_in_tab_panel_settingsnav'.block_settings
::$navcount, 0);
123 $url = $this->page
->url
;
124 $url->remove_params(array('undock'));
126 } else if (!$this->docked
&& optional_param('dock', null, PARAM_INT
)==$this->instance
->id
) {
127 set_user_preferences(array('nav_in_tab_panel_settingsnav'.block_settings
::$navcount=>1));
128 $url = $this->page
->url
;
129 $url->remove_params(array('dock'));
133 $renderer = $this->page
->get_renderer('block_settings');
134 $this->content
= new stdClass();
135 $this->content
->text
= $renderer->settings_tree($this->page
->settingsnav
);
137 // only do search if you have moodle/site:config
138 if (!empty($this->content
->text
)) {
139 if (has_capability('moodle/site:config',context_system
::instance()) ) {
140 $this->content
->footer
= $renderer->search_form(new moodle_url("$CFG->wwwroot/$CFG->admin/search.php"), optional_param('query', '', PARAM_RAW
));
142 $this->content
->footer
= '';
146 $this->contentgenerated
= true;
151 * Returns the role that best describes the settings block.
153 * @return string 'navigation'
155 public function get_aria_role() {
160 * Return the plugin config settings for external functions.
162 * @return stdClass the configs for both the block instance and plugin
165 public function get_config_for_external() {
166 // Return all settings for all users since it is safe (no private keys, etc..).
167 $configs = !empty($this->config
) ?
$this->config
: new stdClass();
170 'instance' => $configs,
171 'plugin' => new stdClass(),