Skip to content

Commit

Permalink
it is now possible to hide parts of admin tree - not used yet, but it…
Browse files Browse the repository at this point in the history
… will be soon used for those hidden unsupported scripts in admin/ directory
  • Loading branch information
skodak committed Sep 24, 2006
1 parent 7253d30 commit a8a66c9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 24 deletions.
38 changes: 19 additions & 19 deletions blocks/admin_tree/block_admin_tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ function create_item($visiblename,$link,$icon) {
function build_tree (&$content) {
global $CFG;
if (is_a($content, 'admin_settingpage')) {
if ($content->check_access()) {
if ($content->check_access() and !$content->is_hidden()) {
$this->create_item($content->visiblename,$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=' . $content->name,$CFG->wwwroot .'/blocks/admin_tree/item.gif');
}
} else if (is_a($content, 'admin_externalpage')) {
if ($content->check_access()) {
if ($content->check_access() and !$content->is_hidden()) {
$this->create_item($content->visiblename, $content->url, $CFG->wwwroot . '/blocks/admin_tree/item.gif');
}
} else if (is_a($content, 'admin_category')) {
if ($content->check_access()) {
if ($content->check_access() and !$content->is_hidden()) {

// check if the category we're currently printing is a parent category for the current page; if it is, we
// make a note (in the javascript) that it has to be expanded after the page has loaded
if ($this->pathtosection[count($this->pathtosection) - 1] == $content->name) {
Expand All @@ -75,11 +75,11 @@ function build_tree (&$content) {
}

$this->open_folder($content->visiblename);

unset($entries);

$entries = array_keys($content->children);

foreach ($entries as $entry) {
$this->build_tree($content->children[$entry]);
}
Expand All @@ -92,7 +92,7 @@ function build_tree (&$content) {
function get_content() {

global $CFG, $ADMIN;

require_once($CFG->libdir.'/adminlib.php');
$adminroot = admin_get_root();

Expand All @@ -107,17 +107,17 @@ function get_content() {

// we need to do this instead of $this->build_tree($adminroot) because the top-level folder
// is redundant (and ideally ignored). (the top-level folder is "administration".)

unset($entries);

$entries = array_keys($adminroot->children);
asort($entries);

asort($entries);

foreach ($entries as $entry) {
$this->build_tree($adminroot->children[$entry]);
}

if ($this->tempcontent !== '') {
$this->content = new stdClass;
$this->content->text = '<script type="text/javascript">' . "\n\n";
Expand All @@ -131,7 +131,7 @@ function get_content() {
$this->content->text .= ' }' . "\n";
$this->content->text .= ' return null;' . "\n";
$this->content->text .= '}' . "\n";

$this->content->text .= 'function toggle(spanid) {' . "\n";
$this->content->text .= ' if (getspan(spanid).innerHTML == "") {' . "\n";
$this->content->text .= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n";
Expand All @@ -155,13 +155,13 @@ function get_content() {
$this->content->text .= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_tree/open.gif\" border=\"0\" alt=\"[open folder]\" />";' . "\n";
$this->content->text .= '}' . "\n";

$this->content->text .= 'function expandall() {' . "\n";
$this->content->text .= ' for (i = 1; i <= vh_numspans; i++) {' . "\n";
$this->content->text .= ' expand("vh_span" + String(i));' . "\n";
$this->content->text .= ' }' . "\n";
$this->content->text .= '}' . "\n";

$this->content->text .= 'function collapseall() {' . "\n";
$this->content->text .= ' for (i = vh_numspans; i > 0; i--) {' . "\n";
$this->content->text .= ' collapse("vh_span" + String(i));' . "\n";
Expand All @@ -170,9 +170,9 @@ function get_content() {

$this->content->text .= '</script>' . "\n";
$this->content->text .= '<div align="left">' . "\n";

$this->content->text .= $this->tempcontent;

$this->content->text .= '</div>' . "\n";
$this->content->text .= '<script type="text/javascript">' . "\n";
$this->content->text .= 'collapseall();' . "\n";
Expand Down
65 changes: 60 additions & 5 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ function &locate($name) {
* Removes named part_of_admin_tree.
*
* @param string $name The internal name of the part_of_admin_tree we want to remove.
* @return boolean success.
* @return bool success.
*/
function prune($name) {
trigger_error('Admin class does not implement method <strong>prune()</strong>', E_USER_WARNING);
Expand All @@ -765,6 +765,16 @@ function check_access() {
return;
}

/**
* Mostly usefull for removing of some parts of the tree in admin tree block.
*
* @return True is hidden from normal list view
*/
function is_hidden() {
trigger_error('Admin class does not implement method <strong>is_hidden()</strong>', E_USER_WARNING);
return;
}

/**
* Determines the path to $name in the admin tree.
*
Expand Down Expand Up @@ -847,6 +857,11 @@ class admin_category extends parentable_part_of_admin_tree {
*/
var $visiblename;

/**
* @var bool Should this category be hidden in admin tree block?
*/
var $hidden;

// constructor for an empty admin category
// $name is the internal name of the category. it MUST be unique in the entire hierarchy
// $visiblename is the displayed name of the category. use a get_string for this
Expand All @@ -856,12 +871,14 @@ class admin_category extends parentable_part_of_admin_tree {
*
* @param string $name The internal name for this category. Must be unique amongst ALL part_of_admin_tree objects
* @param string $visiblename The displayed named for this category. Usually obtained through get_string()
* @param bool $hidden hide category in admin tree block
* @return mixed Returns the new object.
*/
function admin_category($name, $visiblename) {
function admin_category($name, $visiblename, $hidden = false) {
$this->children = array();
$this->name = $name;
$this->visiblename = $visiblename;
$this->hidden = $hidden;
}

/**
Expand Down Expand Up @@ -914,7 +931,7 @@ function &locate($name) {
* Removes part_of_admin_tree object with internal name $name.
*
* @param string $name The internal name of the object we want to remove.
* @return boolean success
* @return bool success
*/
function prune($name) {

Expand Down Expand Up @@ -994,6 +1011,14 @@ function check_access() {

}

/**
* Is this category hidden in admin tree block?
*
* @return bool True if hidden
*/
function is_hidden() {
return $this->hidden;
}
}

/**
Expand Down Expand Up @@ -1026,6 +1051,11 @@ class admin_externalpage extends part_of_admin_tree {
*/
var $req_capability;

/**
* @var bool hidden in admin tree block.
*/
var $hidden;

/**
* Constructor for adding an external page into the admin tree.
*
Expand All @@ -1034,7 +1064,7 @@ class admin_externalpage extends part_of_admin_tree {
* @param string $url The external URL that we should link to when someone requests this external page.
* @param mixed $req_capability The role capability/permission a user must have to access this external page. Defaults to 'moodle/site:config'.
*/
function admin_externalpage($name, $visiblename, $url, $req_capability = 'moodle/site:config') {
function admin_externalpage($name, $visiblename, $url, $req_capability = 'moodle/site:config', $hidden=false) {
$this->name = $name;
$this->visiblename = $visiblename;
$this->url = $url;
Expand All @@ -1043,6 +1073,7 @@ function admin_externalpage($name, $visiblename, $url, $req_capability = 'moodle
} else {
$this->req_capability = array($req_capability);
}
$this->hidden = $hidden;
}

/**
Expand Down Expand Up @@ -1096,6 +1127,15 @@ function check_access() {
return false;
}

/**
* Is this external page hidden in admin tree block?
*
* @return bool True if hidden
*/
function is_hidden() {
return $this->hidden;
}

}

/**
Expand Down Expand Up @@ -1125,6 +1165,11 @@ class admin_settingpage extends part_of_admin_tree {
*/
var $req_capability;

/**
* @var bool hidden in admin tree block.
*/
var $hidden;

// see admin_category
function path($name, $path = array()) {
if ($name == $this->name) {
Expand All @@ -1146,7 +1191,7 @@ function prune($name) {
}

// see admin_externalpage
function admin_settingpage($name, $visiblename, $req_capability = 'moodle/site:config') {
function admin_settingpage($name, $visiblename, $req_capability = 'moodle/site:config', $hidden=false) {
global $CFG;
$this->settings = new stdClass();
$this->name = $name;
Expand All @@ -1156,6 +1201,7 @@ function admin_settingpage($name, $visiblename, $req_capability = 'moodle/site:c
} else {
$this->req_capability = array($req_capability);
}
$this->hidden = false;
}

// not the same as add for admin_category. adds an admin_setting to this admin_settingpage. settings appear (on the settingpage) in the order in which they're added
Expand Down Expand Up @@ -1211,6 +1257,15 @@ function write_settings($data) {
return $return;
}

/**
* Is this settigns page hidden in admin tree block?
*
* @return bool True if hidden
*/
function is_hidden() {
return $this->hidden;
}

}


Expand Down

0 comments on commit a8a66c9

Please sign in to comment.