MDL-35775 group import Support for groupings
authorMichael Aherne <Michael Aherne>
Wed, 3 Oct 2012 15:28:20 +0000 (16:28 +0100)
committerMichael Aherne <michael.aherne@strath.ac.uk>
Wed, 21 Nov 2012 11:04:48 +0000 (11:04 +0000)
group/import.php
lang/en/error.php
lang/en/group.php

index 36a11b9..2ab756b 100644 (file)
@@ -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));
+                        }
+
                     }
                 }
             }
index 543a49f..8afca40 100644 (file)
@@ -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!';
index 807a806..3aabdfc 100644 (file)
@@ -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.';