[ 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 * Library code used by the roles administration interfaces. 19 * 20 * @package core_role 21 * @copyright 2009 Petr Skoda {@link http://skodak.org} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 /** 28 * Subclass of core_role_capability_table_base for use on the Permissions page. 29 */ 30 class core_role_permissions_table extends core_role_capability_table_base { 31 protected $contextname; 32 protected $allowoverrides; 33 protected $allowsafeoverrides; 34 protected $overridableroles; 35 protected $roles; 36 protected $icons = array(); 37 38 /** 39 * Constructor. 40 * @param context $context the context this table relates to. 41 * @param string $contextname $context->get_context_name() - to save recomputing. 42 * @param array $allowoverrides 43 * @param array $allowsafeoverrides 44 * @param array $overridableroles 45 */ 46 public function __construct($context, $contextname, $allowoverrides, $allowsafeoverrides, $overridableroles) { 47 parent::__construct($context, 'permissions'); 48 $this->contextname = $contextname; 49 $this->allowoverrides = $allowoverrides; 50 $this->allowsafeoverrides = $allowsafeoverrides; 51 $this->overridableroles = $overridableroles; 52 53 $roles = get_all_roles($context); 54 $this->roles = role_fix_names(array_reverse($roles, true), $context, ROLENAME_ALIAS, true); 55 56 } 57 58 protected function add_header_cells() { 59 echo '<th>' . get_string('risks', 'core_role') . '</th>'; 60 echo '<th>' . get_string('neededroles', 'core_role') . '</th>'; 61 echo '<th>' . get_string('prohibitedroles', 'core_role') . '</th>'; 62 } 63 64 protected function num_extra_columns() { 65 return 3; 66 } 67 68 protected function add_row_cells($capability) { 69 global $OUTPUT, $PAGE; 70 $renderer = $PAGE->get_renderer('core'); 71 $adminurl = new moodle_url("/admin/"); 72 73 $context = $this->context; 74 $contextid = $this->context->id; 75 $allowoverrides = $this->allowoverrides; 76 $allowsafeoverrides = $this->allowsafeoverrides; 77 $overridableroles = $this->overridableroles; 78 $roles = $this->roles; 79 80 list($needed, $forbidden) = get_roles_with_cap_in_context($context, $capability->name); 81 $neededroles = array(); 82 $forbiddenroles = array(); 83 $allowable = $overridableroles; 84 $forbitable = $overridableroles; 85 foreach ($neededroles as $id => $unused) { 86 unset($allowable[$id]); 87 } 88 foreach ($forbidden as $id => $unused) { 89 unset($allowable[$id]); 90 unset($forbitable[$id]); 91 } 92 93 foreach ($roles as $id => $name) { 94 if (isset($needed[$id])) { 95 $templatecontext = array("rolename" => $name, "roleid" => $id, "action" => "prevent", "spanclass" => "allowed", 96 "linkclass" => "preventlink", "adminurl" => $adminurl->out(), "imageurl" => ""); 97 if (isset($overridableroles[$id]) and ($allowoverrides or ($allowsafeoverrides and is_safe_capability($capability)))) { 98 $templatecontext['imageurl'] = $renderer->pix_url('t/delete'); 99 } 100 $neededroles[$id] = $renderer->render_from_template('core/permissionmanager_role', $templatecontext); 101 } 102 } 103 $neededroles = implode(' ', $neededroles); 104 foreach ($roles as $id => $name) { 105 if (isset($forbidden[$id]) and ($allowoverrides or ($allowsafeoverrides and is_safe_capability($capability)))) { 106 $templatecontext = array("rolename" => $name, "roleid" => $id, "action" => "unprohibit", 107 "spanclass" => "forbidden", "linkclass" => "unprohibitlink", "adminurl" => $adminurl->out(), 108 "imageurl" => ""); 109 if (isset($overridableroles[$id]) and prohibit_is_removable($id, $context, $capability->name)) { 110 $templatecontext['imageurl'] = $renderer->pix_url('t/delete'); 111 } 112 $forbiddenroles[$id] = $renderer->render_from_template('core/permissionmanager_role', $templatecontext); 113 } 114 } 115 $forbiddenroles = implode(' ', $forbiddenroles); 116 117 if ($allowable and ($allowoverrides or ($allowsafeoverrides and is_safe_capability($capability)))) { 118 $allowurl = new moodle_url($PAGE->url, array('contextid' => $contextid, 119 'capability' => $capability->name, 'allow' => 1)); 120 $allowicon = $OUTPUT->action_icon($allowurl, new pix_icon('t/add', get_string('allow', 'core_role')), null, 121 array('class' => 'allowlink', 'data-action' => 'allow')); 122 $neededroles .= html_writer::div($allowicon, 'allowmore'); 123 } 124 125 if ($forbitable and ($allowoverrides or ($allowsafeoverrides and is_safe_capability($capability)))) { 126 $prohibiturl = new moodle_url($PAGE->url, array('contextid' => $contextid, 127 'capability' => $capability->name, 'prohibit' => 1)); 128 $prohibiticon = $OUTPUT->action_icon($prohibiturl, new pix_icon('t/add', get_string('prohibit', 'core_role')), null, 129 array('class' => 'prohibitlink', 'data-action' => 'prohibit')); 130 $forbiddenroles .= html_writer::div($prohibiticon, 'prohibitmore'); 131 } 132 133 $risks = $this->get_risks($capability); 134 135 $contents = html_writer::tag('td', $risks, array('class' => 'risks')); 136 $contents .= html_writer::tag('td', $neededroles, array('class' => 'allowedroles')); 137 $contents .= html_writer::tag('td', $forbiddenroles, array('class' => 'forbiddenroles')); 138 return $contents; 139 } 140 141 protected function get_risks($capability) { 142 global $OUTPUT; 143 144 $allrisks = get_all_risks(); 145 $risksurl = new moodle_url(get_docs_url(s(get_string('risks', 'core_role')))); 146 147 $return = ''; 148 149 foreach ($allrisks as $type => $risk) { 150 if ($risk & (int)$capability->riskbitmask) { 151 if (!isset($this->icons[$type])) { 152 $pixicon = new pix_icon('/i/' . str_replace('risk', 'risk_', $type), get_string($type . 'short', 'admin')); 153 $this->icons[$type] = $OUTPUT->action_icon($risksurl, $pixicon, new popup_action('click', $risksurl)); 154 } 155 $return .= $this->icons[$type]; 156 } 157 } 158 159 return $return; 160 } 161 162 /** 163 * Add additional attributes to row 164 * 165 * @param stdClass $capability capability that this table row relates to. 166 * @return array key value pairs of attribute names and values. 167 */ 168 protected function get_row_attributes($capability) { 169 return array( 170 'data-id' => $capability->id, 171 'data-name' => $capability->name, 172 'data-humanname' => get_capability_string($capability->name), 173 ); 174 } 175 }
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 |