]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9167 and MDL-9113 both solved
authornicolasconnault <nicolasconnault>
Tue, 3 Apr 2007 06:41:58 +0000 (06:41 +0000)
committernicolasconnault <nicolasconnault>
Tue, 3 Apr 2007 06:41:58 +0000 (06:41 +0000)
group/db/dbbasicgrouplib.php
group/edit.php
group/grouping.php
group/index.php
group/lib/basicgrouplib.php
lang/en_utf8/group.php

index 67dc17ac71b318814c70ca818e73eda2ba69aeb4..c8ffb1e4f3206e5539829d158c48f1168be4b7bb 100644 (file)
@@ -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
@@ -517,4 +535,4 @@ function groups_members_where_sql($groupid, $userid_sql=false) {
     return $sql;
 }
 
-?>
\ No newline at end of file
+?>
index 6c4c5da70e7a1fd68d77ca044b0814560592afa8..cacbb5bf78e2ef66f1ed19cdb5bd3a561d68db22 100755 (executable)
@@ -60,20 +60,28 @@ if (!empty($group)) {
     $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;
@@ -86,7 +94,11 @@ if ($editform->is_cancelled()) {
         $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');
         }
     }
@@ -101,32 +113,36 @@ if ($editform->is_cancelled()) {
 
     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);
 ?>
index fd00673b7a6b9cfdde761236e5f44c636081eb48..4bdcd8bb632197b7462ebbd773869bcb802e6028 100644 (file)
@@ -46,19 +46,21 @@ if (!empty($grouping)) {
     $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 {
index 8918f30cf72e3cf6cf5aff3c046b6424f6169733..58a5d76e87bbbbedc64abc786e319c2056792532 100644 (file)
@@ -27,7 +27,6 @@ $groupid    = optional_param('group', false, PARAM_INT);
 $userid     = optional_param('user', false, PARAM_INT);
 $action = groups_param_action();
 
-
 if ($groupid) {
     $groupingsforgroup = groups_get_groupings_for_group($groupid);
     if ($groupingsforgroup) {
@@ -176,7 +175,7 @@ if ($success) {
         $showcreategroupform_disabled = $disabled;
     }
     
-    if ($groupingid == -1) {
+    if ($groupingid == -1 && groups_count_groups_in_grouping(GROUP_NOT_IN_GROUPING, $courseid) > 0) {
         $printerfriendly_disabled = '';
     }
 
@@ -212,6 +211,8 @@ if ($success) {
         //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
@@ -231,7 +232,10 @@ if ($success) {
             echo "<option value=\"$id\"$select>$name</option>\n";
             $count++;
         }
+    } else {
+        echo '<option>&nbsp;</option>';
     }
+
     echo '</select>'."\n";
 
     
index 1bbd4085f6a88216b65c4fa21b5a6bf32f3eda92..d9874eb3e376a2978833478aebec173ead8ca1f1 100644 (file)
@@ -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.
index d7e8da033f8da0fc4415b033052fa5647e1771d3..db4dd1d3acf6b00133b413a1fbe69b881391500b 100644 (file)
@@ -70,6 +70,7 @@ $string['creategroup'] = 'Create group';
 $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';