MDL-26243 calendar: display correct number of repeated events
[moodle.git] / enrol / cohort / addinstance_form.php
bloba6bcbbc277f5bbbebc991d3a4b41f74cd60d8dc9
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Adds instance form
21 * @package enrol
22 * @subpackage cohort
23 * @copyright 2010 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
29 require_once("$CFG->libdir/formslib.php");
31 class enrol_cohort_addinstance_form extends moodleform {
32 function definition() {
33 global $CFG, $DB;
35 $mform = $this->_form;
36 $course = $this->_customdata;
37 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
39 $enrol = enrol_get_plugin('cohort');
41 $cohorts = array('' => get_string('choosedots'));
42 list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
43 $sql = "SELECT id, name, contextid
44 FROM {cohort}
45 WHERE contextid $sqlparents
46 ORDER BY name ASC";
47 $rs = $DB->get_recordset_sql($sql, $params);
48 foreach ($rs as $c) {
49 $context = get_context_instance_by_id($c->contextid);
50 if (!has_capability('moodle/cohort:view', $context)) {
51 continue;
53 $cohorts[$c->id] = format_string($c->name);
55 $rs->close();
57 $roles = get_assignable_roles($coursecontext);
58 $roles = array_reverse($roles, true); // descending default sortorder
60 $mform->addElement('header','general', get_string('pluginname', 'enrol_cohort'));
62 $mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts);
63 $mform->addRule('cohortid', get_string('required'), 'required', null, 'client');
65 $mform->addElement('select', 'roleid', get_string('role'), $roles);
66 $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
67 $mform->setDefault('roleid', $enrol->get_config('roleid'));
69 $mform->addElement('hidden', 'id', null);
70 $mform->setType('id', PARAM_INT);
72 $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
74 $this->set_data(array('id'=>$course->id));
77 //TODO: validate duplicate role-cohort does not exist