diff --git a/group/import.php b/group/import.php index 36a11b995e6..2ab756b7411 100644 --- a/group/import.php +++ b/group/import.php @@ -82,7 +82,8 @@ if ($mform_post->is_cancelled()) { "idnumber" => 1, "groupidnumber" => 1, "description" => 1, - "enrolmentkey" => 1); + "enrolmentkey" => 1, + "groupingname" => 1); // --- get header (field names) --- $header = explode($csv_delimiter, array_shift($rawlines)); @@ -187,10 +188,37 @@ if ($mform_post->is_cancelled()) { } if ($groupid = groups_get_group_by_name($newgroup->courseid, $groupname)) { echo $OUTPUT->notification("$groupname :".get_string('groupexistforcourse', 'error', $groupname)); - } else if (groups_create_group($newgroup)) { + } else if ($groupid = groups_create_group($newgroup)) { echo $OUTPUT->notification(get_string('groupaddedsuccesfully', 'group', $groupname), 'notifysuccess'); } else { echo $OUTPUT->notification(get_string('groupnotaddederror', 'error', $groupname)); + continue; + } + + // Add group to grouping + if (isset($newgroup->groupingname)) { + $groupingname = $newgroup->groupingname; + if (! $groupingid = groups_get_grouping_by_name($newgroup->courseid, $groupingname)) { + $data = new stdClass(); + $data->courseid = $newgroup->courseid; + $data->name = $groupingname; + if ($groupingid = groups_create_grouping($data)) { + echo $OUTPUT->notification(get_string('groupingaddedsuccesfully', 'group', $groupname), 'notifysuccess'); + } else { + echo $OUTPUT->notification(get_string('groupingnotaddederror', 'error', $groupname)); + continue; + } + } + + // if we have reached here we definitely have a groupingid + $a = array('groupname' => $groupname, 'groupingname' => $groupingname); + try { + groups_assign_grouping($groupingid, $groupid); + echo $OUTPUT->notification(get_string('groupaddedtogroupingsuccesfully', 'group', $a), 'notifysuccess'); + } catch (Exception $e) { + echo $OUTPUT->notification(get_string('groupnotaddedtogroupingerror', 'error', $a)); + } + } } } diff --git a/lang/en/error.php b/lang/en/error.php index fc6a59eb2af..0b951cda874 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -246,6 +246,8 @@ $string['groupexistforcoursewithidnumber'] = '{$a->problemgroup}: Group "{$a->na $string['grouphasidnumber'] = 'Group "{$a}" has an idnumber and may have been automatically created by an external system. You do not have permission to remove this group.'; $string['groupinghasidnumber'] = 'Grouping "{$a}" has an idnumber and may have been automatically created by an external system. You do not have permission to remove this grouping.'; $string['groupnotaddederror'] = 'Group "{$a}" not added'; +$string['groupnotaddedtogroupingerror'] = 'Group "{$a->groupname}" not added to grouping "{$a->groupingname}"'; +$string['groupingnotaddederror'] = 'Grouping "{$a}" not added'; $string['groupunknown'] = 'Group {$a} not associated to specified course'; $string['groupusernotmember'] = 'User is not member of this group.'; $string['guestnocomment'] = 'Guests are not allowed to post comments!'; diff --git a/lang/en/group.php b/lang/en/group.php index 807a806eb4d..3aabdfc2c36 100644 --- a/lang/en/group.php +++ b/lang/en/group.php @@ -71,12 +71,14 @@ $string['existingmembers'] = 'Existing members: {$a}'; $string['filtergroups'] = 'Filter groups by:'; $string['group'] = 'Group'; $string['groupaddedsuccesfully'] = 'Group {$a} added successfully'; +$string['groupaddedtogroupingsuccesfully'] = 'Group {$a->groupname} added to grouping {$a->groupingname} successfully'; $string['groupby'] = 'Specify'; $string['groupdescription'] = 'Group description'; $string['groupinfo'] = 'Info about selected group'; $string['groupinfomembers'] = 'Info about selected members'; $string['groupinfopeople'] = 'Info about selected people'; $string['grouping'] = 'Grouping'; +$string['groupingaddedsuccesfully'] = 'Grouping {$a} added successfully'; $string['grouping_help'] = 'A grouping is a collection of groups within a course. If a grouping is selected, students assigned to groups within the grouping will be able to work together.'; $string['groupingsection'] = 'Grouping access'; $string['groupingsection_help'] = 'A grouping is a collection of groups within a course. If a grouping is selected here, only students assigned to groups within this grouping will have access to the section.';