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 * 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
28 * The admin bookmarks block class
30 class block_admin_bookmarks
extends block_base
{
33 public $blockname = null;
37 protected $docked = null;
40 * Set the initial properties for the block
43 $this->blockname
= get_class($this);
44 $this->title
= get_string('pluginname', $this->blockname
);
48 * All multiple instances of this block
49 * @return bool Returns false
51 function instance_allow_multiple() {
56 * Set the applicable formats for this block to all
59 function applicable_formats() {
60 if (has_capability('moodle/site:config', context_system
::instance())) {
61 return array('all' => true);
63 return array('site' => true);
68 * Gets the content for this block
70 function get_content() {
74 // First check if we have already generated, don't waste cycles
75 if ($this->content
!== null) {
76 return $this->content
;
79 $this->content
= new stdClass();
81 if (get_user_preferences('admin_bookmarks')) {
82 require_once($CFG->libdir
.'/adminlib.php');
83 $adminroot = admin_get_root(false, false); // settings not required - only pages
85 $bookmarks = explode(',', get_user_preferences('admin_bookmarks'));
86 /// Accessibility: markup as a list.
88 foreach($bookmarks as $bookmark) {
89 $temp = $adminroot->locate($bookmark);
90 if ($temp instanceof admin_settingpage
) {
91 $contenturl = new moodle_url('/admin/settings.php', array('section'=>$bookmark));
92 $contentlink = html_writer
::link($contenturl, $temp->visiblename
);
93 $contents[] = html_writer
::tag('li', $contentlink);
94 } else if ($temp instanceof admin_externalpage
) {
95 $contenturl = new moodle_url($temp->url
);
96 $contentlink = html_writer
::link($contenturl, $temp->visiblename
);
97 $contents[] = html_writer
::tag('li', $contentlink);
98 } else if ($temp instanceof admin_category
) {
99 $contenturl = new moodle_url('/admin/category.php', array('category' => $bookmark));
100 $contentlink = html_writer
::link($contenturl, $temp->visiblename
);
101 $contents[] = html_writer
::tag('li', $contentlink);
104 $this->content
->text
= html_writer
::tag('ol', implode('', $contents), array('class' => 'list'));
106 $bookmarks = array();
109 $this->content
->footer
= '';
110 $this->page
->settingsnav
->initialise();
111 $node = $this->page
->settingsnav
->get('root', navigation_node
::TYPE_SITE_ADMIN
);
112 if (!$node ||
!$node->contains_active_node()) {
113 return $this->content
;
115 $section = $node->find_active_node()->key
;
117 if ($section == 'search' ||
empty($section)){
118 // the search page can't be properly bookmarked at present
119 $this->content
->footer
= '';
120 } else if (in_array($section, $bookmarks)) {
121 $deleteurl = new moodle_url('/blocks/admin_bookmarks/delete.php', array('section'=>$section, 'sesskey'=>sesskey()));
122 $this->content
->footer
= html_writer
::link($deleteurl, get_string('unbookmarkthispage','admin'));
124 $createurl = new moodle_url('/blocks/admin_bookmarks/create.php', array('section'=>$section, 'sesskey'=>sesskey()));
125 $this->content
->footer
= html_writer
::link($createurl, get_string('bookmarkthispage','admin'));
128 return $this->content
;
132 * Returns the role that best describes the admin bookmarks block.
136 public function get_aria_role() {