]> git.mjollnir.org Git - moodle.git/commitdiff
Improved handling of Groups.
authorrkingdon <rkingdon>
Sat, 7 Aug 2004 14:16:20 +0000 (14:16 +0000)
committerrkingdon <rkingdon>
Sat, 7 Aug 2004 14:16:20 +0000 (14:16 +0000)
mod/dialogue/dialogues.php
mod/dialogue/locallib.php
mod/dialogue/view.php

index d699895879b5d593d7a90f7db53641ac3d08816f..1cf37314400281fd9124adfbe33c0723ab9013d9 100644 (file)
             $recipientid = $_POST['recipientid'];
             if (substr($recipientid, 0, 1) == 'g') { // it's a group
                 $groupid = intval(substr($recipientid, 1));
-                $recipients = get_records_sql("SELECT u.*
+                if ($groupid) { // it's a real group
+                    $recipients = get_records_sql("SELECT u.*
                                 FROM {$CFG->prefix}user u,
                                      {$CFG->prefix}groups_members g
                                 WHERE g.groupid = $groupid and
                                       u.id = g.userid");
+                } else { // it's all participants
+                    $recipients = get_course_students($course->id);
+                }
             } else {
                 $recipients[$recipientid] = get_record("user", "id", $recipientid);
             }
                 redirect("view.php?id=$cm->id", get_string("noavailablepeople", "dialogue"));
             }
             if (isset($groupid)) {
-                if (!$group = get_record("groups", "id", $groupid)) {
-                    error("Dialogue open conversation: Group not found");
+                if ($groupid) { // a real group
+                    if (!$group = get_record("groups", "id", $groupid)) {
+                        error("Dialogue open conversation: Group not found");
+                    }
+                    redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue", $group->name));
+                } else { // all participants
+                    redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue", 
+                                get_string("allparticipants")));
                 }
-                redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue", $group->name));
             } else {
                 if (!$user =  get_record("user", "id", $conversation->recipientid)) {
                     error("Open dialogue: user record not found");
index 834401f149cbbb4a7130c835d7a05e95f6ce6653..5a632aa585a9001de43a12fa8598aea2550a3e06 100644 (file)
@@ -133,32 +133,31 @@ global $USER;
     if (! $course = get_record("course", "id", $dialogue->course)) {
         error("Course is misconfigured");
     }
-    // add groups before list of students if it's the teacher
-    if (isteacher($course->id) and (groupmode($course) != NOGROUPS)) {
-        // get all the groups if the groups are visible
-        if (groupmode($course) == VISIBLEGROUPS) {
-            if (!$groups = get_records("groups", "courseid", $course->id)) {
-                error("Dialogue get available students: no groups found");
+    // add current group before list of students if it's the teacher
+    if (isteacher($course->id) and groupmode($course)) {
+        // show teacher their current group
+        $groupid = get_current_group($course->id);
+        if ($groupid) {
+            if (!$group = get_record("groups", "id", $groupid)) {
+                error("Dialogue get available students: group not found");
             }
-            foreach ($groups as $group) {
-                $gnames["g{$group->id}"] = $group->name;
-            }
-        } else { // show teacher their group(s)
-            if($groups = get_groups($course->id, $USER->id)) {
-                foreach($groups as $group) {
-                    $gnames["g{$group->id}"] = $group->name;
-                }
-            }
-        }
-        if ($gnames) {
-            $gnames["spacer"] = "------------";
+            $gnames["g$groupid"] = $group->name;
+        } else { // all participants
+            $gnames["g0"] = get_string("allparticipants");
         }
+        $gnames["spacer"] = "------------";
     }
     // get the students on this course (default sort order)...
        if ($users = get_course_students($course->id)) {
                foreach ($users as $otheruser) {
                        // ...exclude self and...
                        if ($USER->id != $otheruser->id) {
+                // if teacher and groups then exclude students not in the current group
+                if (isteacher($course->id) and groupmode($course) and $groupid) {
+                    if (!ismember($groupid, $otheruser->id)) {
+                        continue;
+                    }
+                }
                                // ...any already in any open conversations unless multiple conversations allowed
                                if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", 
                         "dialogueid = $dialogue->id AND 
@@ -180,7 +179,11 @@ global $USER;
             $list = $names;
         }
     }
-    return $list;
+    if (isset($list)) {
+        return $list;
+    } else {
+        return;
+    }
 }
 
 
index 37d677cb19df49137e2423dee3d02b407caf17f1..1956dcce6570e772b891504a685ff52f51412ffd 100644 (file)
                 $pane =1;
             }
         }
-        
+        // override pane setting if teacher has changed group
+        if (isset($_GET['group'])) {
+            $pane = 0;
+        }
+         
         // set up tab table
         $tabs->names[0] = get_string("pane0", "dialogue");
         if ($countneedingrepliesself == 1) {
         $tabs->highlight = $pane;
         dialogue_print_tabbed_heading($tabs);
         echo "<br/><center>\n";
+        
+       
                switch ($pane) {
-            case 0: 
+            case 0:
+                if (isteacher($course->id)) {
+                    /// Check to see if groups are being used in this dialogue
+                    /// and if so, set $currentgroup to reflect the current group
+                    $changegroup = isset($_GET['group']) ? $_GET['group'] : -1;  // Group change requested?
+                    $groupmode = groupmode($course, $cm);   // Groups are being used?
+                    $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
+
+                    /// Allow the teacher to change groups (for this session)
+                    if ($groupmode) {
+                        if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
+                            print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id");
+                        }
+                    }
+                }
+
                 if ($names = dialogue_get_available_users($dialogue)) {
                                print_simple_box_start("center");
                                echo "<center>";