3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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
24 * @copyright 2009 Sam Hemelryk
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 * The settings navigation tree block class
31 * Used to produce the settings navigation block new to Moodle 2.0
34 * @copyright 2009 Sam Hemelryk
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class block_settings_navigation_tree extends block_tree {
40 public static $navcount;
41 public $blockname = null;
43 protected $contentgenerated = false;
45 protected $docked = null;
48 * Set the initial properties for the block
51 $this->blockname = get_class($this);
52 $this->title = get_string('blockname', $this->blockname);
53 $this->version = 2009082800;
57 * All multiple instances of this block
58 * @return bool Returns true
60 function instance_allow_multiple() {
65 * Set the applicable formats for this block to all
68 function applicable_formats() {
69 return array('all' => true);
73 * Allow the user to configure a block instance
74 * @return bool Returns true
76 function instance_allow_config() {
80 function get_required_javascript() {
82 $this->_initialise_dock();
83 $this->page->requires->js_module(array('name'=>'core_dock', 'fullpath'=>'/blocks/dock.js', 'requires'=>array('base', 'cookie', 'dom', 'io', 'node', 'event-custom', 'event-mouseenter', 'yui2-container')));
84 $module = array('name'=>'block_navigation', 'fullpath'=>'/blocks/global_navigation_tree/navigation.js', 'requires'=>array('core_dock', 'io', 'node', 'dom', 'event-custom', 'json-parse'));
85 $arguments = array($this->instance->id, array('instance'=>$this->instance->id, 'candock'=>$this->instance_can_be_docked()));
86 $this->page->requires->js_init_call('M.block_navigation.init_add_tree', $arguments, false, $module);
87 user_preference_allow_ajax_update('docked_block_instance_'.$this->instance->id, PARAM_INT);
91 * Gets the content for this block by grabbing it from $this->page
93 function get_content() {
95 // First check if we have already generated, don't waste cycles
96 if ($this->contentgenerated === true) {
99 $this->page->requires->yui2_lib('dom');
100 // JS for navigation moved to the standard theme, the code will probably have to depend on the actual page structure
101 // $this->page->requires->js('/lib/javascript-navigation.js');
102 block_settings_navigation_tree::$navcount++;
104 // Check if this block has been docked
105 if ($this->docked === null) {
106 $this->docked = get_user_preferences('nav_in_tab_panel_settingsnav'.block_settings_navigation_tree::$navcount, 0);
109 // Check if there is a param to change the docked state
110 if ($this->docked && optional_param('undock', null, PARAM_INT)==$this->instance->id) {
111 unset_user_preference('nav_in_tab_panel_settingsnav'.block_settings_navigation_tree::$navcount, 0);
112 $url = $this->page->url;
113 $url->remove_params(array('undock'));
115 } else if (!$this->docked && optional_param('dock', null, PARAM_INT)==$this->instance->id) {
116 set_user_preferences(array('nav_in_tab_panel_settingsnav'.block_settings_navigation_tree::$navcount=>1));
117 $url = $this->page->url;
118 $url->remove_params(array('dock'));
122 if (!$this->page->settingsnav->contains_active_node() && !$this->page->navigation->contains_active_node()) {
123 if (!$this->page->settingsnav->reiterate_active_nodes()) {
124 $this->page->settingsnav->reiterate_active_nodes(URL_MATCH_BASE);
128 // Grab the children from settings nav, we have more than one root node
129 // and we dont want to show the site node
130 $this->content->items = $this->page->settingsnav->children;
131 // only do search if you have moodle/site:config
132 if (count($this->content->items)>0) {
133 if (has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) ) {
134 $value = optional_param('query', '', PARAM_RAW);
135 $target = new moodle_url("$CFG->wwwroot/$CFG->admin/search.php");
136 $form = '<form class="adminsearchform" method="get" action="'.$target.'">';
137 $form .= '<div><label for="adminsearchquery" class="accesshide">'.s(get_string('searchinsettings', 'admin')).'</label>';
138 $form .= '<input id="adminsearchquery" type="text" name="query" value="'.s($value).'"/>';
139 $form .= '<input type="submit" value="'.s(get_string('search')).'" />';
140 $form .= '</div></form>';
141 $this->content->footer = $form;
143 $this->content->footer = '';
146 $reloadlink = new moodle_url($this->page->url, array('regenerate'=>'navigation'));
147 $this->content->footer .= $OUTPUT->action_icon($reloadlink, new pix_icon('t/reload', get_string('reload')), null, array('class'=>'customcommand'));
149 if (!empty($this->config->enablesidebarpopout) && $this->config->enablesidebarpopout == 'yes') {
150 user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav'.block_settings_navigation_tree::$navcount, PARAM_INT);
154 $this->contentgenerated = true;
158 function html_attributes() {
159 $attributes = parent::html_attributes();
160 if (!empty($this->config->enablehoverexpansion) && $this->config->enablehoverexpansion == 'yes') {
161 $attributes['class'] .= ' block_js_expansion';