[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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. 13 // 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/>. 16 17 /** 18 * Capability tool renderer. 19 * 20 * @package tool_capability 21 * @copyright 2013 Sam Hemelryk 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 /** 26 * The primary renderer for the capability tool. 27 * 28 * @copyright 2013 Sam Hemelryk 29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 30 */ 31 class tool_capability_renderer extends plugin_renderer_base { 32 33 /** 34 * Returns an array of permission strings. 35 * 36 * @return lang_string[] 37 */ 38 protected function get_permission_strings() { 39 static $strpermissions; 40 if (!$strpermissions) { 41 $strpermissions = array( 42 CAP_INHERIT => new lang_string('inherit', 'role'), 43 CAP_ALLOW => new lang_string('allow', 'role'), 44 CAP_PREVENT => new lang_string('prevent', 'role'), 45 CAP_PROHIBIT => new lang_string('prohibit', 'role') 46 ); 47 } 48 return $strpermissions; 49 } 50 51 /** 52 * Returns an array of permission CSS classes. 53 * 54 * @return string[] 55 */ 56 protected function get_permission_classes() { 57 static $permissionclasses; 58 if (!$permissionclasses) { 59 $permissionclasses = array( 60 CAP_INHERIT => 'inherit', 61 CAP_ALLOW => 'allow', 62 CAP_PREVENT => 'prevent', 63 CAP_PROHIBIT => 'prohibit', 64 ); 65 } 66 return $permissionclasses; 67 } 68 69 /** 70 * Produces a table to visually compare roles and capabilities. 71 * 72 * @param array $capabilities An array of capabilities to show comparison for. 73 * @param int $contextid The context we are displaying for. 74 * @param array $roles An array of roles to show comparison for. 75 * @return string 76 */ 77 public function capability_comparison_table(array $capabilities, $contextid, array $roles) { 78 79 $strpermissions = $this->get_permission_strings(); 80 $permissionclasses = $this->get_permission_classes(); 81 82 if ($contextid === context_system::instance()->id) { 83 $strpermissions[CAP_INHERIT] = new lang_string('notset', 'role'); 84 } 85 86 $table = new html_table(); 87 $table->attributes['class'] = 'comparisontable'; 88 $table->head = array(' '); 89 foreach ($roles as $role) { 90 $url = new moodle_url('/admin/roles/define.php', array('action' => 'view', 'roleid' => $role->id)); 91 $table->head[] = html_writer::div(html_writer::link($url, $role->localname)); 92 } 93 $table->data = array(); 94 95 foreach ($capabilities as $capability) { 96 $contexts = tool_capability_calculate_role_data($capability, $roles); 97 $captitle = new html_table_cell(get_capability_string($capability) . html_writer::span($capability)); 98 $captitle->header = true; 99 100 $row = new html_table_row(array($captitle)); 101 102 foreach ($roles as $role) { 103 if (isset($contexts[$contextid]->rolecapabilities[$role->id])) { 104 $permission = $contexts[$contextid]->rolecapabilities[$role->id]; 105 } else { 106 $permission = CAP_INHERIT; 107 } 108 $cell = new html_table_cell($strpermissions[$permission]); 109 $cell->attributes['class'] = $permissionclasses[$permission]; 110 $row->cells[] = $cell; 111 } 112 113 $table->data[] = $row; 114 } 115 116 // Start the list item, and print the context name as a link to the place to make changes. 117 if ($contextid == context_system::instance()->id) { 118 $url = new moodle_url('/admin/roles/manage.php'); 119 $title = get_string('changeroles', 'tool_capability'); 120 } else { 121 $url = new moodle_url('/admin/roles/override.php', array('contextid' => $contextid)); 122 $title = get_string('changeoverrides', 'tool_capability'); 123 } 124 $context = context::instance_by_id($contextid); 125 $html = $this->output->heading(html_writer::link($url, $context->get_context_name(), array('title' => $title)), 3); 126 $html .= html_writer::table($table); 127 // If there are any child contexts, print them recursively. 128 if (!empty($contexts[$contextid]->children)) { 129 foreach ($contexts[$contextid]->children as $childcontextid) { 130 $html .= $this->capability_comparison_table($capabilities, $childcontextid, $roles, true); 131 } 132 } 133 return $html; 134 } 135 136 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |