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;
36 protected $contentgenerated = false;
39 protected $docked = null;
42 * Set the initial properties for the block
45 $this->blockname
= get_class($this);
46 $this->title
= get_string('pluginname', $this->blockname
);
50 * All multiple instances of this block
51 * @return bool Returns false
53 function instance_allow_multiple() {
58 * Set the applicable formats for this block to all
61 function applicable_formats() {
62 if (has_capability('moodle/site:config', context_system
::instance())) {
63 return array('all' => true);
65 return array('site' => true);
70 * Gets the content for this block
72 function get_content() {
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.
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);
99 } else if ($temp instanceof admin_category
) {
100 $contenturl = new moodle_url('/admin/category.php', array('category' => $bookmark));
101 $contentlink = html_writer
::link($contenturl, $temp->visiblename
);
102 $contents[] = html_writer
::tag('li', $contentlink);
105 $this->content
->text
= html_writer
::tag('ol', implode('', $contents), array('class' => 'list'));
107 $bookmarks = array();
110 $this->content
->footer
= '';
111 $this->page
->settingsnav
->initialise();
112 $node = $this->page
->settingsnav
->get('root', navigation_node
::TYPE_SITE_ADMIN
);
113 if (!$node ||
!$node->contains_active_node()) {
114 return $this->content
;
116 $section = $node->find_active_node()->key
;
118 if ($section == 'search' ||
empty($section)){
119 // the search page can't be properly bookmarked at present
120 $this->content
->footer
= '';
121 } else if (in_array($section, $bookmarks)) {
122 $deleteurl = new moodle_url('/blocks/admin_bookmarks/delete.php', array('section'=>$section, 'sesskey'=>sesskey()));
123 $this->content
->footer
= html_writer
::link($deleteurl, get_string('unbookmarkthispage','admin'));
125 $createurl = new moodle_url('/blocks/admin_bookmarks/create.php', array('section'=>$section, 'sesskey'=>sesskey()));
126 $this->content
->footer
= html_writer
::link($createurl, get_string('bookmarkthispage','admin'));
129 return $this->content
;
133 * Returns the role that best describes the admin bookmarks block.
137 public function get_aria_role() {