Improved handling of Groups.

This commit is contained in:
rkingdon
2004-08-07 14:16:20 +00:00
parent fab7e07e19
commit 1d8d55e7ed
3 changed files with 59 additions and 25 deletions
+13 -4
View File
@@ -187,11 +187,15 @@
$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);
}
@@ -237,10 +241,15 @@
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");
+22 -19
View 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");
}
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;
}
// 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");
}
$gnames["g$groupid"] = $group->name;
} else { // all participants
$gnames["g0"] = get_string("allparticipants");
}
if ($gnames) {
$gnames["spacer"] = "------------";
}
$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;
}
}
+24 -2
View File
@@ -88,7 +88,12 @@
$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) {
@@ -114,8 +119,25 @@
$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>";