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