Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/cohort/addinstance_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once("$CFG->libdir/formslib.php");
00030 
00031 class enrol_cohort_addinstance_form extends moodleform {
00032     function definition() {
00033         global $CFG, $DB;
00034 
00035         $mform  = $this->_form;
00036         $course = $this->_customdata;
00037         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00038 
00039         $enrol = enrol_get_plugin('cohort');
00040 
00041         $cohorts = array('' => get_string('choosedots'));
00042         list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
00043         $sql = "SELECT id, name, contextid
00044                   FROM {cohort}
00045                  WHERE contextid $sqlparents
00046               ORDER BY name ASC";
00047         $rs = $DB->get_recordset_sql($sql, $params);
00048         foreach ($rs as $c) {
00049             $context = get_context_instance_by_id($c->contextid);
00050             if (!has_capability('moodle/cohort:view', $context)) {
00051                 continue;
00052             }
00053             $cohorts[$c->id] = format_string($c->name);
00054         }
00055         $rs->close();
00056 
00057         $roles = get_assignable_roles($coursecontext);
00058         $roles = array_reverse($roles, true); // descending default sortorder
00059 
00060         $mform->addElement('header','general', get_string('pluginname', 'enrol_cohort'));
00061 
00062         $mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts);
00063         $mform->addRule('cohortid', get_string('required'), 'required', null, 'client');
00064 
00065         $mform->addElement('select', 'roleid', get_string('role'), $roles);
00066         $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
00067         $mform->setDefault('roleid', $enrol->get_config('roleid'));
00068 
00069         $mform->addElement('hidden', 'id', null);
00070         $mform->setType('id', PARAM_INT);
00071 
00072         $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
00073 
00074         $this->set_data(array('id'=>$course->id));
00075     }
00076 
00077     //TODO: validate duplicate role-cohort does not exist
00078 }
 All Data Structures Namespaces Files Functions Variables Enumerations