MDL-21781 added support for autocreation of groups from cohorts
[moodle.git] / group / autogroup_form.php
index c159ac0..078e481 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 require_once($CFG->dirroot.'/lib/formslib.php');
+require_once($CFG->dirroot.'/cohort/lib.php');
 
 /// get url variables
 class autogroup_form extends moodleform {
@@ -22,6 +23,16 @@ class autogroup_form extends moodleform {
             $mform->setDefault('roleid', $CFG->defaultcourseroleid);
         }
 
+        $options = cohort_get_visible_list($COURSE);
+        if ($options) {
+            $options = array(0=>get_string('anycohort', 'cohort')) + $options;
+            $mform->addElement('select', 'cohortid', get_string('selectfromcohort', 'cohort'), $options);
+        } else {
+            $mform->addElement('hidden','cohortid');
+            $mform->setType('cohortid', PARAM_INT);
+            $mform->setDefault('cohortid', '0');
+        }
+
         $options = array('groups' => get_string('numgroups', 'group'),
                          'members' => get_string('nummembers', 'group'));
         $mform->addElement('select', 'groupby', get_string('groupby', 'group'), $options);
@@ -91,7 +102,7 @@ class autogroup_form extends moodleform {
         $errors = parent::validation($data, $files);
 
         if ($data['allocateby'] != 'no') {
-            if (!$users = groups_get_potential_members($data['courseid'], $data['roleid'])) {
+            if (!$users = groups_get_potential_members($data['courseid'], $data['roleid'], $data['cohortid'])) {
                 $errors['roleid'] = get_string('nousersinrole', 'group');
             }