1 |
efrain |
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 |
namespace tool_cohortroles\form;
|
|
|
18 |
defined('MOODLE_INTERNAL') || die();
|
|
|
19 |
|
|
|
20 |
use moodleform;
|
|
|
21 |
use context_system;
|
|
|
22 |
|
|
|
23 |
require_once($CFG->libdir . '/formslib.php');
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Assign role to cohort form.
|
|
|
27 |
*
|
|
|
28 |
* @package tool_cohortroles
|
|
|
29 |
* @copyright 2015 Damyon Wiese
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class assign_role_cohort extends moodleform {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Form definition.
|
|
|
36 |
*/
|
|
|
37 |
public function definition() {
|
|
|
38 |
global $PAGE;
|
|
|
39 |
|
|
|
40 |
$mform = $this->_form;
|
|
|
41 |
$roles = get_roles_for_contextlevels(CONTEXT_USER);
|
|
|
42 |
|
|
|
43 |
if (empty($roles)) {
|
|
|
44 |
$output = $PAGE->get_renderer('tool_cohortroles');
|
|
|
45 |
$warning = $output->notify_problem(get_string('noassignableroles', 'tool_cohortroles'));
|
|
|
46 |
$mform->addElement('html', $warning);
|
|
|
47 |
return;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
$options = array(
|
|
|
51 |
'ajax' => 'core_user/form_user_selector',
|
|
|
52 |
'multiple' => true
|
|
|
53 |
);
|
|
|
54 |
$mform->addElement('autocomplete', 'userids', get_string('selectusers', 'tool_cohortroles'), array(), $options);
|
|
|
55 |
$mform->addRule('userids', null, 'required');
|
|
|
56 |
|
|
|
57 |
$names = role_get_names();
|
|
|
58 |
$options = array();
|
|
|
59 |
foreach ($roles as $idx => $roleid) {
|
|
|
60 |
$options[$roleid] = $names[$roleid]->localname;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
$mform->addElement('select', 'roleid', get_string('selectrole', 'tool_cohortroles'), $options);
|
|
|
64 |
$mform->addRule('roleid', null, 'required');
|
|
|
65 |
|
|
|
66 |
$context = context_system::instance();
|
|
|
67 |
$options = array(
|
|
|
68 |
'multiple' => true,
|
|
|
69 |
'data-contextid' => $context->id,
|
|
|
70 |
'data-includes' => 'all'
|
|
|
71 |
);
|
|
|
72 |
$mform->addElement('cohort', 'cohortids', get_string('selectcohorts', 'tool_cohortroles'), $options);
|
|
|
73 |
$mform->addRule('cohortids', null, 'required');
|
|
|
74 |
$mform->addElement('submit', 'submit', get_string('assign', 'tool_cohortroles'));
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
}
|