source: moodle/trunk/fuentes/admin/roles/classes/override_permissions_table_advanced.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 5 years ago

Ported code to xenial

File size: 4.1 KB
Line 
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
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    /**
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    protected function load_parent_permissions() {
60        // Get the capabilities from the parent context, so that can be shown in the interface.
61        $parentcontext = $this->context->get_parent_context();
62        $this->parentpermissions = role_context_capabilities($this->roleid, $parentcontext);
63    }
64
65    public function has_locked_capabilities() {
66        return $this->haslockedcapabilities;
67    }
68
69    protected function add_permission_cells($capability) {
70        $disabled = '';
71        if ($capability->locked || $this->parentpermissions[$capability->name] == CAP_PROHIBIT) {
72            $disabled = ' disabled="disabled"';
73        }
74
75        // One cell for each possible permission.
76        foreach ($this->displaypermissions as $perm => $permname) {
77            $strperm = $this->strperms[$permname];
78            $extraclass = '';
79            if ($perm != CAP_INHERIT && $perm == $this->parentpermissions[$capability->name]) {
80                $extraclass = ' capcurrent';
81            }
82            $checked = '';
83            if ($this->permissions[$capability->name] == $perm) {
84                $checked = 'checked="checked" ';
85            }
86            echo '<td class="' . $permname . $extraclass . '">';
87            echo '<label><input type="radio" name="' . $capability->name .
88                '" value="' . $perm . '" ' . $checked . $disabled . '/> ';
89            if ($perm == CAP_INHERIT) {
90                $inherited = $this->parentpermissions[$capability->name];
91                if ($inherited == CAP_INHERIT) {
92                    $inherited = $this->strnotset;
93                } else {
94                    $inherited = $this->strperms[$this->allpermissions[$inherited]];
95                }
96                $strperm .= ' (' . $inherited . ')';
97            }
98            echo '<span class="note">' . $strperm . '</span>';
99            echo '</label></td>';
100        }
101    }
102}
Note: See TracBrowser for help on using the repository browser.