See Release Notes
Long Term Support Release
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 * override permissions table. 19 * 20 * @package core_role 21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 class core_role_override_permissions_table_advanced extends core_role_capability_table_with_risks { 28 protected $strnotset; 29 protected $haslockedcapabilities = false; 30 31 /** 32 * Constructor. 33 * 34 * This method loads loads all the information about the current state of 35 * the overrides, then updates that based on any submitted data. It also 36 * works out which capabilities should be locked for this user. 37 * 38 * @param object $context the context this table relates to. 39 * @param integer $roleid the role being overridden. 40 * @param boolean $safeoverridesonly If true, the user is only allowed to override 41 * capabilities with no risks. 42 */ 43 public function __construct($context, $roleid, $safeoverridesonly) { 44 parent::__construct($context, 'overriderolestable', $roleid); 45 $this->displaypermissions = $this->allpermissions; 46 $this->strnotset = get_string('notset', 'core_role'); 47 48 // Determine which capabilities should be locked. 49 if ($safeoverridesonly) { 50 foreach ($this->capabilities as $capid => $cap) { 51 if (!is_safe_capability($cap)) { 52 $this->capabilities[$capid]->locked = true; 53 $this->haslockedcapabilities = true; 54 } 55 } 56 } 57 } 58 59 /** 60 * This method adds an additional class to a row if capability is other than inherited. 61 * 62 * @param stdClass $capability 63 * @return array 64 */ 65 protected function get_row_attributes($capability) { 66 $rowattributes = parent::get_row_attributes($capability); 67 if ($this->permissions[$capability->name] !== 0) { 68 if (empty($rowattributes['class'])) { 69 $rowattributes['class'] = "overriddenpermission table-warning"; 70 } else { 71 $rowattributes['class'] .= " overriddenpermission table-warning"; 72 } 73 } 74 return $rowattributes; 75 } 76 77 protected function load_parent_permissions() { 78 // Get the capabilities from the parent context, so that can be shown in the interface. 79 $parentcontext = $this->context->get_parent_context(); 80 $this->parentpermissions = role_context_capabilities($this->roleid, $parentcontext); 81 } 82 83 public function has_locked_capabilities() { 84 return $this->haslockedcapabilities; 85 } 86 87 protected function add_permission_cells($capability) { 88 $disabled = ''; 89 if ($capability->locked || $this->parentpermissions[$capability->name] == CAP_PROHIBIT) { 90 $disabled = ' disabled="disabled"'; 91 } 92 93 // One cell for each possible permission. 94 $content = ''; 95 foreach ($this->displaypermissions as $perm => $permname) { 96 $strperm = $this->strperms[$permname]; 97 $extraclass = ''; 98 if ($perm != CAP_INHERIT && $perm == $this->parentpermissions[$capability->name]) { 99 $extraclass = ' capcurrent'; 100 } 101 $checked = ''; 102 if ($this->permissions[$capability->name] == $perm) { 103 $checked = 'checked="checked" '; 104 } 105 $content .= '<td class="' . $permname . $extraclass . '">'; 106 $content .= '<label><input type="radio" name="' . $capability->name . 107 '" value="' . $perm . '" ' . $checked . $disabled . '/> '; 108 if ($perm == CAP_INHERIT) { 109 $inherited = $this->parentpermissions[$capability->name]; 110 if ($inherited == CAP_INHERIT) { 111 $inherited = $this->strnotset; 112 } else { 113 $inherited = $this->strperms[$this->allpermissions[$inherited]]; 114 } 115 $strperm .= ' (' . $inherited . ')'; 116 } 117 $content .= '<span class="note">' . $strperm . '</span>'; 118 $content .= '</label></td>'; 119 } 120 return $content; 121 } 122 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body