Merge branch 'MDL-36754-master' of git://github.com/andrewnicols/moodle
[moodle.git] / blocks / admin_bookmarks / block_admin_bookmarks.php
blobc1dfa35405416be4caedb9543eb039a9ab075911
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.
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/>.
17 /**
18 * Admin Bookmarks Block page.
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
27 /**
28 * The admin bookmarks block class
30 class block_admin_bookmarks extends block_base {
32 /** @var string */
33 public $blockname = null;
35 /** @var bool */
36 protected $contentgenerated = false;
38 /** @var bool|null */
39 protected $docked = null;
41 /**
42 * Set the initial properties for the block
44 function init() {
45 $this->blockname = get_class($this);
46 $this->title = get_string('pluginname', $this->blockname);
49 /**
50 * All multiple instances of this block
51 * @return bool Returns false
53 function instance_allow_multiple() {
54 return false;
57 /**
58 * Set the applicable formats for this block to all
59 * @return array
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);
69 /**
70 * Gets the content for this block
72 function get_content() {
74 global $CFG;
76 // First check if we have already generated, don't waste cycles
77 if ($this->contentgenerated === true) {
78 return $this->content;
80 $this->content = new stdClass();
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
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);
101 $this->content->text = html_writer::tag('ol', implode('', $contents), array('class' => 'list'));
102 } else {
103 $bookmarks = array();
106 $this->content->footer = '';
107 $this->page->settingsnav->initialise();
108 $node = $this->page->settingsnav->get('root', navigation_node::TYPE_SITE_ADMIN);
109 if (!$node || !$node->contains_active_node()) {
110 return $this->content;
112 $section = $node->find_active_node()->key;
114 if ($section == 'search' || empty($section)){
115 // the search page can't be properly bookmarked at present
116 $this->content->footer = '';
117 } else if (in_array($section, $bookmarks)) {
118 $deleteurl = new moodle_url('/blocks/admin_bookmarks/delete.php', array('section'=>$section, 'sesskey'=>sesskey()));
119 $this->content->footer = html_writer::link($deleteurl, get_string('unbookmarkthispage','admin'));
120 } else {
121 $createurl = new moodle_url('/blocks/admin_bookmarks/create.php', array('section'=>$section, 'sesskey'=>sesskey()));
122 $this->content->footer = html_writer::link($createurl, get_string('bookmarkthispage','admin'));
125 return $this->content;
129 * Returns the role that best describes the admin bookmarks block.
131 * @return string
133 public function get_aria_role() {
134 return 'navigation';