Skip to content

Commit

Permalink
MDL-9167 and MDL-9113 both solved
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Apr 3, 2007
1 parent bfe1e78 commit e4596a4
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 46 deletions.
20 changes: 19 additions & 1 deletion group/db/dbbasicgrouplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ function groups_db_group_matches($courseid, $grp_name, $grp_description) {
return $group;
}

/**
* Determine if a course ID, and group name match a group in the database.
* @return mixed A group-like object with $group->id, or false.
*/
function groups_db_group_name_exists($courseid, $grp_name) {
global $CFG;
$sql = "SELECT g.id, g.name
FROM {$CFG->prefix}groups g
INNER JOIN {$CFG->prefix}groups_courses_groups cg ON g.id = cg.groupid
WHERE g.name = '$grp_name'
AND cg.courseid = '$courseid'";
$records = get_records_sql($sql);
$group = false;
if ($records) {
$group = current($records);
}
return $group;
}

/**
* Determines if a specified user is a member of a specified group
Expand Down Expand Up @@ -517,4 +535,4 @@ function groups_members_where_sql($groupid, $userid_sql=false) {
return $sql;
}

?>
?>
86 changes: 51 additions & 35 deletions group/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,28 @@
$editform->set_data($group);
}

// Process delete action
if ($delete) {
if (groups_delete_group($id)) {
redirect(groups_home_url($course->id, null, $groupingid, false));
} else {
print_error('erroreditgroup', 'group', groups_home_url($course->id));
}
}

$error = null;

if ($editform->is_cancelled()) {
redirect(groups_home_url($courseid, $id, $groupingid, false));
} elseif ($data = $editform->get_data()) {
$success = true;

// preprocess data
if ($delete) {
if ($success = groups_delete_group($id)) {
redirect(groups_home_url($course->id, null, $groupingid, false));
} else {
print_error('erroreditgroup', 'group', groups_home_url($course->id));
}
} elseif (empty($group)) { // New group
if (!$id = groups_create_group($course->id, $data)) {
if (empty($group)) { // New group
// First check if this group name doesn't already exist
if (groups_group_name_exists($courseid, $data->name)) {
$error = get_string('groupnameexists', 'group', $data->name);
$success = false;
} elseif (!$id = groups_create_group($course->id, $data)) {
print_error('erroreditgroup');
} else {
$success = (bool)$id;
Expand All @@ -86,7 +94,11 @@
$success = $success && groups_remove_group_from_grouping($id, $groupingid);
$success = $success && groups_add_group_to_grouping($id, $newgrouping);
} else { // Updating group
if (!groups_update_group($data, $course->id)) {
$group = groups_get_group($data->id);
if (groups_group_name_exists($courseid, $data->name) && $group->name != $data->name) {
$error = get_string('groupnameexists', 'group', $data->name);
$success = false;
} elseif (!groups_update_group($data, $course->id)) {
print_error('groupnotupdated');
}
}
Expand All @@ -101,32 +113,36 @@

if ($success) {
redirect(groups_home_url($course->id, $id, $groupingid, false));
} else {
} elseif (empty($error)) {
print_error('erroreditgroup', 'group', groups_home_url($course->id));
}
} else { // Prepare and output form
$strgroups = get_string('groups');
$strparticipants = get_string('participants');

if ($id) {
$strheading = get_string('editgroupsettings', 'group');
} else {
$strheading = get_string('creategroup', 'group');
}
print_header("$course->shortname: ". $strheading,
$course->fullname,
"<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
"-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
'-> <a href="' .format_string(groups_home_url($courseid, $id, $groupingid, false)) . "\">$strgroups</a>".
"-> $strheading", '', '', true, '', user_login_string($course, $USER));

print_heading($strheading);
echo '<div id="grouppicture">';
if ($id) {
print_group_picture($group, $course->id);
}
echo '</div>';
$editform->display();
print_footer($course);
}
$strgroups = get_string('groups');
$strparticipants = get_string('participants');

if ($id) {
$strheading = get_string('editgroupsettings', 'group');
} else {
$strheading = get_string('creategroup', 'group');
}
print_header("$course->shortname: ". $strheading,
$course->fullname,
"<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
"-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
'-> <a href="' .format_string(groups_home_url($courseid, $id, $groupingid, false)) . "\">$strgroups</a>".
"-> $strheading", '', '', true, '', user_login_string($course, $USER));

print_heading($strheading);

if ($error) {
notify($error);
}

echo '<div id="grouppicture">';
if ($id) {
print_group_picture($group, $course->id);
}
echo '</div>';
$editform->display();
print_footer($course);
?>
18 changes: 10 additions & 8 deletions group/grouping.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@
$editform->set_data($grouping);
}

// preprocess data
if ($delete) {
if (groups_delete_grouping($id)) {
redirect(groups_home_url($course->id));
} else {
print_error('erroreditgrouping', 'group', groups_home_url($course->id));
}
}

if ($editform->is_cancelled()) {
redirect(groups_home_url($courseid, false, $id, false));
} elseif ($data = $editform->get_data()) {
$success = true;

// preprocess data
if ($delete) {
if ($success = groups_delete_grouping($id)) {
redirect(groups_home_url($course->id));
} else {
print_error('erroreditgrouping', 'group', groups_home_url($course->id));
}
} elseif (empty($grouping)) { // New grouping
if (empty($grouping)) { // New grouping
if (!$id = groups_create_grouping($course->id, $data)) {
print_error('erroreditgrouping');
} else {
Expand Down
8 changes: 6 additions & 2 deletions group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
$userid = optional_param('user', false, PARAM_INT);
$action = groups_param_action();


if ($groupid) {
$groupingsforgroup = groups_get_groupings_for_group($groupid);
if ($groupingsforgroup) {
Expand Down Expand Up @@ -176,7 +175,7 @@
$showcreategroupform_disabled = $disabled;
}

if ($groupingid == -1) {
if ($groupingid == -1 && groups_count_groups_in_grouping(GROUP_NOT_IN_GROUPING, $courseid) > 0) {
$printerfriendly_disabled = '';
}

Expand Down Expand Up @@ -212,6 +211,8 @@
//NOTE, only show the pseudo-grouping if it has groups.
$groupingids[] = GROUP_NOT_IN_GROUPING;
}

$sel_groupingid = -1;

if ($groupingids) {
// Put the groupings into a hash and sort them
Expand All @@ -231,7 +232,10 @@
echo "<option value=\"$id\"$select>$name</option>\n";
$count++;
}
} else {
echo '<option>&nbsp;</option>';
}

echo '</select>'."\n";


Expand Down
7 changes: 7 additions & 0 deletions group/lib/basicgrouplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ function groups_group_matches($courseid, $grp_name, $grp_description) {
return groups_db_group_matches($courseid, $grp_name, $grp_description);
}

/**
* Determine if a course ID, and group name match a group in the database.
* @return mixed A group-like object with $group->id, or false.
*/
function groups_group_name_exists($courseid, $grp_name) {
return groups_db_group_name_exists($courseid, $grp_name);
}

/**
* Determines if the user is a member of the given group.
Expand Down
1 change: 1 addition & 0 deletions lang/en_utf8/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
$string['createorphangroup'] = 'Create orphan group';

$string['groupname'] = 'Group name';
$string['groupnameexists'] = 'The group name \'$a\' already exists in this course, please choose another one.';
$string['defaultgroupname'] = 'Group';
$string['groupdescription'] = 'Group description';
$string['enrolmentkey'] = 'Enrolment key';
Expand Down

0 comments on commit e4596a4

Please sign in to comment.