Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * Internal library of functions for module auth_ldap
  19   *
  20   * @package    auth_ldap
  21   * @author     David Balch <david.balch@conted.ox.ac.uk>
  22   * @copyright  2017 The Chancellor Masters and Scholars of the University of Oxford {@link http://www.tall.ox.ac.uk/}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Get a list of system roles assignable by the current or a specified user, including their localised names.
  30   *
  31   * @param integer|object $user A user id or object. By default (null) checks the permissions of the current user.
  32   * @return array $roles, each role as an array with id, shortname, localname, and settingname for the config value.
  33   */
  34  function get_ldap_assignable_role_names($user = null) {
  35      $roles = array();
  36  
  37      if ($assignableroles = get_assignable_roles(context_system::instance(), ROLENAME_SHORT, false, $user)) {
  38          $systemroles = role_fix_names(get_all_roles(), context_system::instance(), ROLENAME_ORIGINAL);
  39          foreach ($assignableroles as $shortname) {
  40              foreach ($systemroles as $systemrole) {
  41                  if ($systemrole->shortname == $shortname) {
  42                      $roles[] = array('id' => $systemrole->id,
  43                                       'shortname' => $shortname,
  44                                       'localname' => $systemrole->localname,
  45                                       'settingname' => $shortname . 'context');
  46                      break;
  47                  }
  48              }
  49          }
  50      }
  51  
  52      return $roles;
  53  }