MDL-27628 enrol_meta: Set options to exclude existing courses, and the current course
authorDamyon Wiese <damyon@moodle.com>
Thu, 10 Mar 2016 02:37:33 +0000 (10:37 +0800)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 10 Mar 2016 12:17:10 +0000 (13:17 +0100)
When adding a new meta enrolment, you should not be able to select the current course,
or any courses with an existing meta link.

enrol/meta/lib.php

index 4695835..e563b60 100644 (file)
@@ -323,11 +323,17 @@ class enrol_meta_plugin extends enrol_plugin {
         global $DB;
 
         $groups = $this->get_group_options($coursecontext);
+        $existing = $DB->get_records('enrol', array('enrol' => 'meta', 'courseid' => $coursecontext->instanceid), '', 'customint1, id');
+
+        $excludelist = array($coursecontext->instanceid);
+        foreach ($existing as $existinginstance) {
+            $excludelist[] = $existinginstance->customint1;
+        }
 
         $options = array(
             'requiredcapabilities' => array('enrol/meta:selectaslinked'),
             'multiple' => true,
-            'excludecourseid' => $coursecontext->instanceid
+            'exclude' => $excludelist
         );
         $mform->addElement('course', 'customint1', get_string('linkedcourse', 'enrol_meta'), $options);
         $mform->addRule('customint1', get_string('required'), 'required', null, 'client');