Merge branch 'MDL-51177-master' of git://github.com/andrewnicols/moodle
[moodle.git] / admin / roles / lib.php
blobb7c17dabb1111d5e2dafec498e2a1d60fd6712ec
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.
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/>.
17 /**
18 * Library code used by the roles administration interfaces.
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
25 defined('MOODLE_INTERNAL') || die();
27 /**
28 * Get the potential assignees selector for a given context.
30 * If this context is a course context, or inside a course context (module or
31 * some blocks) then return a core_role_potential_assignees_below_course object. Otherwise
32 * return a core_role_potential_assignees_course_and_above.
34 * @param context $context a context.
35 * @param string $name passed to user selector constructor.
36 * @param array $options to user selector constructor.
37 * @return user_selector_base an appropriate user selector.
39 function core_role_get_potential_user_selector(context $context, $name, $options) {
40 $blockinsidecourse = false;
41 if ($context->contextlevel == CONTEXT_BLOCK) {
42 $parentcontext = $context->get_parent_context();
43 $blockinsidecourse = in_array($parentcontext->contextlevel, array(CONTEXT_MODULE, CONTEXT_COURSE));
46 if (($context->contextlevel == CONTEXT_MODULE || $blockinsidecourse) &&
47 !is_inside_frontpage($context)) {
48 $potentialuserselector = new core_role_potential_assignees_below_course('addselect', $options);
49 } else {
50 $potentialuserselector = new core_role_potential_assignees_course_and_above('addselect', $options);
53 return $potentialuserselector;