]> git.mjollnir.org Git - moodle.git/commitdiff
Dialogues can be started with groups of students.
authorrkingdon <rkingdon>
Mon, 28 Jun 2004 19:41:24 +0000 (19:41 +0000)
committerrkingdon <rkingdon>
Mon, 28 Jun 2004 19:41:24 +0000 (19:41 +0000)
mod/dialogue/dialogues.php
mod/dialogue/locallib.php
mod/dialogue/view.php

index 2af6ac9b8ef9287be4813daa5ba0fa271439327e..d699895879b5d593d7a90f7db53641ac3d08816f 100644 (file)
        /****************** open conversation ************************************/
        elseif ($action == 'openconversation' ) {
 
-               if ($_POST['recipientid'] == 0) {
+               if (empty($_POST['recipientid'])) {
                        redirect("view.php?id=$cm->id", get_string("nopersonchosen", "dialogue"));
         } else {
-            $stripped_text = strip_tags(trim($_POST['firstentry']));
-            if (!$stripped_text) {
-                           redirect("view.php?id=$cm->id", get_string("notextentered", "dialogue"));
+            $recipientid = $_POST['recipientid'];
+            if (substr($recipientid, 0, 1) == 'g') { // it's a group
+                $groupid = intval(substr($recipientid, 1));
+                $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 {
+                $recipients[$recipientid] = get_record("user", "id", $recipientid);
             }
-                       $conversation->dialogueid = $dialogue->id;
-                       $conversation->userid = $USER->id;
-                       $conversation->recipientid = $_POST['recipientid'];
-                       $conversation->lastid = $USER->id; // this USER is adding an entry too
-                       $conversation->timemodified = time();
-            $conversation->subject = $_POST['subject']; // may be blank
-                       if (!$conversation->id = insert_record("dialogue_conversations", $conversation)) {
-                               error("Open dialogue: Could not insert dialogue record!");
-                       }
-                       add_to_log($course->id, "dialogue", "open", "view.php?id=$cm->id", "$dialogue->id");
-        
-            // now add the entry
-                       $entry->dialogueid = $dialogue->id;
-                       $entry->conversationid = $conversation->id;
-                       $entry->userid = $USER->id;
-                       $entry->timecreated = time(); 
-                       // reverse the dialogue default value
-                       $entry->mailed = !$dialogue->maildefault;
-                       $entry->text = $_POST['firstentry'];
-                       if (!$entry->id = insert_record("dialogue_entries", $entry)) {
-                               error("Insert Entries: Could not insert dialogue record!");
-                       }
-                       add_to_log($course->id, "dialogue", "add entry", "view.php?id=$cm->id", "$entry->id");
-                       
-            if (!$user =  get_record("user", "id", $conversation->recipientid)) {
-                               error("Open dialogue: user record not found");
+            if ($recipients) {
+                $n = 0;
+                foreach ($recipients as $recipient) { 
+                    if ($recipient->id == $USER->id) { // teacher could be member of a group
+                        continue;
+                    }
+                    $stripped_text = strip_tags(trim($_POST['firstentry']));
+                    if (!$stripped_text) {
+                        redirect("view.php?id=$cm->id", get_string("notextentered", "dialogue"));
+                    }
+                    unset($conversation);
+                    $conversation->dialogueid = $dialogue->id;
+                    $conversation->userid = $USER->id;
+                    $conversation->recipientid = $recipient->id;
+                    $conversation->lastid = $USER->id; // this USER is adding an entry too
+                    $conversation->timemodified = time();
+                    $conversation->subject = $_POST['subject']; // may be blank
+                    if (!$conversation->id = insert_record("dialogue_conversations", $conversation)) {
+                        error("Open dialogue: Could not insert dialogue record!");
+                    }
+                    add_to_log($course->id, "dialogue", "open", "view.php?id=$cm->id", "$dialogue->id");
+
+                    // now add the entry
+                    unset($entry);
+                    $entry->dialogueid = $dialogue->id;
+                    $entry->conversationid = $conversation->id;
+                    $entry->userid = $USER->id;
+                    $entry->timecreated = time(); 
+                    // reverse the dialogue default value
+                    $entry->mailed = !$dialogue->maildefault;
+                    $entry->text = $_POST['firstentry'];
+                    if (!$entry->id = insert_record("dialogue_entries", $entry)) {
+                        error("Insert Entries: Could not insert dialogue record!");
+                    }
+                    add_to_log($course->id, "dialogue", "add entry", "view.php?id=$cm->id", "$entry->id");
+                    $n++;
+                }
+                print_heading(get_string("numberofentriesadded", "dialogue", $n));
+            } else {
+                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");
+                }
+                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");
+                }
+                redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue", fullname($user) ));
             }
-                       redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue", fullname($user) ));
                }
        }
        
index 56d3fdb7dc95dd8396afe11a7ac525cb3134b6ba..834401f149cbbb4a7130c835d7a05e95f6ce6653 100644 (file)
@@ -133,7 +133,28 @@ global $USER;
     if (! $course = get_record("course", "id", $dialogue->course)) {
         error("Course is misconfigured");
     }
-     // get the students on this course (default sort order)...
+    // 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");
+            }
+            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"] = "------------";
+        }
+    }
+    // get the students on this course (default sort order)...
        if ($users = get_course_students($course->id)) {
                foreach ($users as $otheruser) {
                        // ...exclude self and...
@@ -148,11 +169,18 @@ global $USER;
                        }
                }
        }
+    if (isset($gnames)) {
+        $list = $gnames;
+    }
     if (isset($names)) {
         natcasesort($names);
-        return $names;
+        if (isset($list)) {
+            $list += $names;
+        } else {
+            $list = $names;
+        }
     }
-    return;
+    return $list;
 }
 
 
index 9cf1c65585667286891bd9f91f4ec1fb10032a45..37d677cb19df49137e2423dee3d02b407caf17f1 100644 (file)
                     echo "<td align=\"right\"><b>".get_string("openadialoguewith", "dialogue").
                         " : </b></td>\n";
                                echo "<td>";
+                    
                     choose_from_menu($names, "recipientid");
                     echo "</td></tr>\n";
                     echo "<tr><td align=\"right\"><b>".get_string("subject", "dialogue")." : </b></td>\n";