Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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  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_view_role_definition_table extends core_role_define_role_table_advanced {
  28      public function __construct($context, $roleid) {
  29          parent::__construct($context, $roleid);
  30          $this->displaypermissions = array(CAP_ALLOW => $this->allpermissions[CAP_ALLOW]);
  31          $this->disabled = 'disabled="disabled" ';
  32      }
  33  
  34      public function save_changes() {
  35          throw new moodle_exception('invalidaccess');
  36      }
  37  
  38      protected function get_name_field($id) {
  39          return role_get_name($this->role);
  40      }
  41  
  42      protected function get_shortname_field($id) {
  43          return $this->role->shortname;
  44      }
  45  
  46      protected function get_description_field($id) {
  47          return role_get_description($this->role);
  48      }
  49  
  50      protected function get_archetype_field($id) {
  51          if (empty($this->role->archetype)) {
  52              return get_string('none');
  53          } else {
  54              return get_string('archetype'.$this->role->archetype, 'core_role');
  55          }
  56      }
  57  
  58      protected function get_allow_role_control($type) {
  59          if ($roles = $this->get_allow_roles_list($type)) {
  60              $roles = role_fix_names($roles, null, ROLENAME_ORIGINAL, true);
  61              return implode(', ', $roles);
  62          } else {
  63              return get_string('none');
  64          }
  65      }
  66  
  67  
  68      protected function print_show_hide_advanced_button() {
  69          // Do nothing.
  70      }
  71  
  72      /**
  73       * Returns HTML risk icons.
  74       *
  75       * @return string
  76       */
  77      protected function get_role_risks_info() {
  78          global $OUTPUT;
  79  
  80          if (empty($this->roleid)) {
  81              return '';
  82          }
  83  
  84          $risks = array();
  85          $allrisks = get_all_risks();
  86          foreach ($this->capabilities as $capability) {
  87              $perm = $this->permissions[$capability->name];
  88              if ($perm != CAP_ALLOW) {
  89                  continue;
  90              }
  91              foreach ($allrisks as $type => $risk) {
  92                  if ($risk & (int)$capability->riskbitmask) {
  93                      $risks[$type] = $risk;
  94                  }
  95              }
  96          }
  97  
  98          $risksurl = new moodle_url(get_docs_url(s(get_string('risks', 'core_role'))));
  99          foreach ($risks as $type => $risk) {
 100              $pixicon = new pix_icon('/i/' . str_replace('risk', 'risk_', $type), get_string($type . 'short', 'admin'));
 101              $risks[$type] = $OUTPUT->action_icon($risksurl, $pixicon, new popup_action('click', $risksurl));
 102          }
 103  
 104          return implode(' ', $risks);
 105      }
 106  
 107      /**
 108       * Returns true if the row should be skipped.
 109       *
 110       * @param string $capability
 111       * @return bool
 112       */
 113      protected function skip_row($capability) {
 114          $perm = $this->permissions[$capability->name];
 115          if ($perm == CAP_INHERIT) {
 116              // Do not print empty rows in role overview, admins need to know quickly what is allowed and prohibited,
 117              // if they want to see the list of all capabilities they can go to edit role page.
 118              return true;
 119          }
 120          parent::skip_row($capability);
 121      }
 122  
 123      protected function add_permission_cells($capability) {
 124          $perm = $this->permissions[$capability->name];
 125          $permname = $this->allpermissions[$perm];
 126          $defaultperm = $this->allpermissions[$this->parentpermissions[$capability->name]];
 127          if ($permname != $defaultperm) {
 128              $default = get_string('defaultx', 'core_role', $this->strperms[$defaultperm]);
 129          } else {
 130              $default = "&#xa0;";
 131          }
 132          return '<td class="' . $permname . '">' . $this->strperms[$permname] . '<span class="note">' .
 133              $default . '</span></td>';
 134  
 135      }
 136  }