Permalink
Browse files

Dialogues can be started with groups of students.

  • Loading branch information...
rkingdon
rkingdon committed Jun 28, 2004
1 parent 4a6cfa3 commit 16b56e5ef81954dc8074a90b9ab6ba0ee61dfe70
Showing with 94 additions and 34 deletions.
  1. +62 −31 mod/dialogue/dialogues.php
  2. +31 −3 mod/dialogue/locallib.php
  3. +1 −0 mod/dialogue/view.php
View
@@ -181,41 +181,72 @@
/****************** 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) ));
}
}
View
@@ -133,7 +133,28 @@ function dialogue_get_available_students($dialogue) {
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 @@ function dialogue_get_available_students($dialogue) {
}
}
}
+ if (isset($gnames)) {
+ $list = $gnames;
+ }
if (isset($names)) {
natcasesort($names);
- return $names;
+ if (isset($list)) {
+ $list += $names;
+ } else {
+ $list = $names;
+ }
}
- return;
+ return $list;
}
View
@@ -126,6 +126,7 @@
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";

0 comments on commit 16b56e5

Please sign in to comment.