MDL-66999 theme_boost: @extend .table-warning
[moodle.git] / admin / roles / classes / override_permissions_table_advanced.php
CommitLineData
bc7b53fb
PS
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/**
d7797b79 18 * override permissions table.
bc7b53fb
PS
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
25defined('MOODLE_INTERNAL') || die();
26
27class core_role_override_permissions_table_advanced extends core_role_capability_table_with_risks {
28 protected $strnotset;
29 protected $haslockedcapabilities = false;
30
31 /**
d7797b79 32 * Constructor.
bc7b53fb
PS
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;
d7797b79 46 $this->strnotset = get_string('notset', 'core_role');
bc7b53fb 47
d7797b79 48 // Determine which capabilities should be locked.
bc7b53fb
PS
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
e985a29c
JAS
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'])) {
6ac38de8 69 $rowattributes['class'] = "overriddenpermission table-warning";
e985a29c 70 } else {
6ac38de8 71 $rowattributes['class'] .= " overriddenpermission table-warning";
e985a29c
JAS
72 }
73 }
74 return $rowattributes;
75 }
76
bc7b53fb 77 protected function load_parent_permissions() {
d7797b79 78 // Get the capabilities from the parent context, so that can be shown in the interface.
1415127e 79 $parentcontext = $this->context->get_parent_context();
bc7b53fb
PS
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
d7797b79 93 // One cell for each possible permission.
2ff1f051 94 $content = '';
bc7b53fb
PS
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 }
2ff1f051
MG
105 $content .= '<td class="' . $permname . $extraclass . '">';
106 $content .= '<label><input type="radio" name="' . $capability->name .
bc7b53fb
PS
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 }
2ff1f051
MG
117 $content .= '<span class="note">' . $strperm . '</span>';
118 $content .= '</label></td>';
bc7b53fb 119 }
2ff1f051 120 return $content;
bc7b53fb
PS
121 }
122}