Skip to content

Commit

Permalink
MDL-35775 group import Support for groupings
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Aherne authored and micaherne committed Nov 21, 2012
1 parent a9962a8 commit df3efbf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
32 changes: 30 additions & 2 deletions group/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
}

}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!';
Expand Down
2 changes: 2 additions & 0 deletions lang/en/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down

0 comments on commit df3efbf

Please sign in to comment.