Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 * Existing admin user selector. 19 * 20 * @package core_role 21 * @copyright 2010 Petr Skoda {@link http://skodak.org} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 require_once($CFG->dirroot.'/user/selector/lib.php'); 28 29 class core_role_admins_existing_selector extends user_selector_base { 30 /** 31 * Create instance. 32 * 33 * @param string $name control name 34 * @param array $options should have two elements with keys groupid and courseid. 35 */ 36 public function __construct($name = null, $options = array()) { 37 if (is_null($name)) { 38 $name = 'removeselect'; 39 } 40 $options['multiselect'] = false; 41 parent::__construct($name, $options); 42 } 43 44 public function find_users($search) { 45 global $DB, $CFG; 46 list($wherecondition, $params) = $this->search_sql($search, ''); 47 48 $fields = 'SELECT ' . $this->required_fields_sql(''); 49 50 if ($wherecondition) { 51 $wherecondition = "$wherecondition AND id IN ($CFG->siteadmins)"; 52 } else { 53 $wherecondition = "id IN ($CFG->siteadmins)"; 54 } 55 $sql = " FROM {user} 56 WHERE $wherecondition"; 57 58 list($sort, $sortparams) = users_order_by_sql('', $search, $this->accesscontext); 59 $params = array_merge($params, $sortparams); 60 $order = ' ORDER BY ' . $sort; 61 62 $availableusers = $DB->get_records_sql($fields . $sql . $order, $params); 63 64 if (empty($availableusers)) { 65 return array(); 66 } 67 68 $mainadmin = array(); 69 $mainadminuser = get_admin(); 70 if ($mainadminuser && isset($availableusers[$mainadminuser->id])) { 71 $mainadmin = array($mainadminuser->id => $availableusers[$mainadminuser->id]); 72 unset($availableusers[$mainadminuser->id]); 73 } 74 75 $result = array(); 76 if ($mainadmin) { 77 $result[get_string('mainadmin', 'core_role')] = $mainadmin; 78 } 79 80 if ($availableusers) { 81 if ($search) { 82 $groupname = get_string('extusersmatching', 'core_role', $search); 83 } else { 84 $groupname = get_string('extusers', 'core_role'); 85 } 86 $result[$groupname] = $availableusers; 87 } 88 89 return $result; 90 } 91 92 protected function get_options() { 93 global $CFG; 94 $options = parent::get_options(); 95 $options['file'] = $CFG->admin . '/roles/lib.php'; 96 return $options; 97 } 98 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body