[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/roles/classes/ -> override_permissions_table_advanced.php (source)

   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      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          $content = '';
  77          foreach ($this->displaypermissions as $perm => $permname) {
  78              $strperm = $this->strperms[$permname];
  79              $extraclass = '';
  80              if ($perm != CAP_INHERIT && $perm == $this->parentpermissions[$capability->name]) {
  81                  $extraclass = ' capcurrent';
  82              }
  83              $checked = '';
  84              if ($this->permissions[$capability->name] == $perm) {
  85                  $checked = 'checked="checked" ';
  86              }
  87              $content .= '<td class="' . $permname . $extraclass . '">';
  88              $content .= '<label><input type="radio" name="' . $capability->name .
  89                  '" value="' . $perm . '" ' . $checked . $disabled . '/> ';
  90              if ($perm == CAP_INHERIT) {
  91                  $inherited = $this->parentpermissions[$capability->name];
  92                  if ($inherited == CAP_INHERIT) {
  93                      $inherited = $this->strnotset;
  94                  } else {
  95                      $inherited = $this->strperms[$this->allpermissions[$inherited]];
  96                  }
  97                  $strperm .= ' (' . $inherited . ')';
  98              }
  99              $content .= '<span class="note">' . $strperm . '</span>';
 100              $content .= '</label></td>';
 101          }
 102          return $content;
 103      }
 104  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1