From 89f8f22656298a1cd76112910c31da134c683e67 Mon Sep 17 00:00:00 2001 From: Mannes Brak Date: Thu, 17 Apr 2014 07:19:03 -0700 Subject: [PATCH] Cohort-sync with ability to make group on making enrolment --- enrol/cohort/edit.php | 13 +++++++++++++ enrol/cohort/edit_form.php | 2 +- enrol/cohort/version.php | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/enrol/cohort/edit.php b/enrol/cohort/edit.php index 050bdff..deaa291 100755 --- a/enrol/cohort/edit.php +++ b/enrol/cohort/edit.php @@ -77,12 +77,25 @@ if ($mform->is_cancelled()) { redirect($returnurl); } else if ($data = $mform->get_data()) { + if ($data->customint2 == -1) { + $groupid = groups_get_group_by_name($course->id, $data->name); + if($groupid) $data->customint2 = $groupid; + else { + //create group + $group = new stdClass(); + $group->courseid = $course->id; + $group->name = $data->name; + $data->customint2 = groups_create_group($group); + } + } + if ($data->id) { // NOTE: no cohort changes here!!! if ($data->roleid != $instance->roleid) { // The sync script can only add roles, for perf reasons it does not modify them. role_unassign_all(array('contextid'=>$context->id, 'roleid'=>$instance->roleid, 'component'=>'enrol_cohort', 'itemid'=>$instance->id)); } + $instance->name = $data->name; $instance->status = $data->status; $instance->roleid = $data->roleid; diff --git a/enrol/cohort/edit_form.php b/enrol/cohort/edit_form.php index 7f3011f..7ee0578 100755 --- a/enrol/cohort/edit_form.php +++ b/enrol/cohort/edit_form.php @@ -39,7 +39,7 @@ class enrol_cohort_edit_form extends moodleform { $enrol = enrol_get_plugin('cohort'); - $groups = array(0 => get_string('none')); + $groups = array(-1 => get_string('creategroup', 'core_group'), 0 => get_string('none')); foreach (groups_get_all_groups($course->id) as $group) { $groups[$group->id] = format_string($group->name, true, array('context'=>$coursecontext)); } diff --git a/enrol/cohort/version.php b/enrol/cohort/version.php index ae79e70..91d6da3 100755 --- a/enrol/cohort/version.php +++ b/enrol/cohort/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2013110500; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2013110501; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2013110500; // Requires this Moodle version $plugin->component = 'enrol_cohort'; // Full name of the plugin (used for diagnostics) $plugin->cron = 60*60; // run cron every hour by default, it is not out-of-sync often -- 1.7.9.5