Permalink
Browse files

MDL-35775 group import Support for groupings

  • Loading branch information...
1 parent a9962a8 commit df3efbfb2cec6dbe7ab278f5267459a1b5eae752 Michael Aherne committed with micaherne Oct 3, 2012
Showing with 34 additions and 2 deletions.
  1. +30 −2 group/import.php
  2. +2 −0 lang/en/error.php
  3. +2 −0 lang/en/group.php
View
@@ -82,7 +82,8 @@
"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 ($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));
+ }
+
}
}
}
View
@@ -246,6 +246,8 @@
$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!';
View
@@ -71,12 +71,14 @@
$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.';

0 comments on commit df3efbf

Please sign in to comment.