From a12e11c13aa0be6eaeb9f33fb471154cd566d5f3 Mon Sep 17 00:00:00 2001 From: mattc-catalyst Date: Mon, 27 Aug 2007 02:28:35 +0000 Subject: [PATCH] MDL-10888: groupings - mod/chat - update to work with groupings --- mod/chat/gui_basic/index.php | 8 ++++---- mod/chat/gui_header_js/index.php | 4 ++-- mod/chat/gui_header_js/users.php | 6 +++++- mod/chat/gui_sockets/index.php | 6 +++--- mod/chat/lib.php | 17 +++++++++++++---- mod/chat/mod_form.php | 6 +++++- mod/chat/report.php | 11 +++++++---- mod/chat/view.php | 7 ++++--- 8 files changed, 43 insertions(+), 22 deletions(-) diff --git a/mod/chat/gui_basic/index.php b/mod/chat/gui_basic/index.php index 89210c8e60..79509f18cf 100644 --- a/mod/chat/gui_basic/index.php +++ b/mod/chat/gui_basic/index.php @@ -27,9 +27,9 @@ require_capability('mod/chat:chat',$context); /// Check to see if groups are being used here - if ($groupmode = groupmode($course, $cm)) { // Groups are being used - if ($groupid = get_and_set_current_group($course, $groupmode, $groupid)) { - if (!$group = get_record('groups', 'id', $groupid)) { + if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used + if ($groupid = groups_get_activity_group($cm)) { + if (!$group = groups_get_group($groupid, false)) { error("That group (id $groupid) doesn't exist!"); } $groupname = ': '.$group->name; @@ -48,7 +48,7 @@ error('Could not log in to chat room!!'); } - if (!$chatusers = chat_get_users($chat->id, $groupid)) { + if (!$chatusers = chat_get_users($chat->id, $groupid, $cm->groupingid)) { error(get_string('errornousers', 'chat')); } diff --git a/mod/chat/gui_header_js/index.php b/mod/chat/gui_header_js/index.php index 231899521b..f82eb5060b 100644 --- a/mod/chat/gui_header_js/index.php +++ b/mod/chat/gui_header_js/index.php @@ -30,8 +30,8 @@ } /// Check to see if groups are being used here - if ($groupmode = groupmode($course, $cm)) { // Groups are being used - if ($groupid = get_and_set_current_group($course, $groupmode, $groupid)) { + if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used + if ($groupid = groups_get_activity_group($cm)) { if (!$group = groups_get_group($groupid, false)) { error("That group (id $groupid) doesn't exist!"); } diff --git a/mod/chat/gui_header_js/users.php b/mod/chat/gui_header_js/users.php index 9cd107c5af..35956794a9 100644 --- a/mod/chat/gui_header_js/users.php +++ b/mod/chat/gui_header_js/users.php @@ -28,6 +28,10 @@ $courseid = $chatuser->course; + if (!$cm = get_coursemodule_from_instance('chat', $chatuser->chatid, $courseid)) { + error('Course Module ID was incorrect'); + } + if ($beep) { $message->chatid = $chatuser->chatid; $message->userid = $chatuser->userid; @@ -50,7 +54,7 @@ /// Get list of users - if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid)) { + if (!$chatusers = chat_get_users($chatuser->chatid, $chatuser->groupid, $cm->groupingid)) { error(get_string('errornousers', 'chat')); } diff --git a/mod/chat/gui_sockets/index.php b/mod/chat/gui_sockets/index.php index 33ca929dc1..a7953abaea 100644 --- a/mod/chat/gui_sockets/index.php +++ b/mod/chat/gui_sockets/index.php @@ -30,9 +30,9 @@ } /// Check to see if groups are being used here - if ($groupmode = groupmode($course, $cm)) { // Groups are being used - if ($groupid = get_and_set_current_group($course, $groupmode, $groupid)) { - if (! groups_group_exists($groupid)) { + if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used + if ($groupid = groups_get_activity_group($cm)) { + if (!$group = groups_get_group($groupid, false)) { error("That group (id $groupid) doesn't exist!"); } $groupname = ': '.$group->name; diff --git a/mod/chat/lib.php b/mod/chat/lib.php index a923cbc0cb..265d3a710b 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -315,7 +315,7 @@ function chat_refresh_events($courseid = 0) { ////////////////////////////////////////////////////////////////////// /// Functions that require some SQL -function chat_get_users($chatid, $groupid=0) { +function chat_get_users($chatid, $groupid=0, $groupingid=0) { global $CFG; @@ -324,12 +324,21 @@ function chat_get_users($chatid, $groupid=0) { } else { $groupselect = ""; } + + if (!empty($CFG->enablegroupings) && !(empty($groupingid))) { + $groupingjoin = "INNER JOIN {$CFG->prefix}groups_members gm ON u.id = gm.userid + INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = gg.groupid AND gg.groupingid = $groupingid "; + + } else { + $groupingjoin = ''; + } return get_records_sql("SELECT DISTINCT u.id, u.firstname, u.lastname, u.picture, c.lastmessageping, c.firstping - FROM {$CFG->prefix}chat_users c, - {$CFG->prefix}user u + FROM {$CFG->prefix}chat_users c + INNER JOIN {$CFG->prefix}user u ON u.id = c.userid + $groupingjoin WHERE c.chatid = '$chatid' - AND u.id = c.userid $groupselect + $groupselect ORDER BY c.firstping ASC"); } diff --git a/mod/chat/mod_form.php b/mod/chat/mod_form.php index adf195008c..af8a6032e1 100644 --- a/mod/chat/mod_form.php +++ b/mod/chat/mod_form.php @@ -47,7 +47,11 @@ class mod_chat_mod_form extends moodleform_mod { $mform->addElement('selectyesno', 'studentlogs', get_string('studentseereports', 'chat')); - $this->standard_coursemodule_elements(); + $features = new stdClass; + $features->groups = true; + $features->groupings = true; + $features->groupmembersonly = true; + $this->standard_coursemodule_elements($features); $this->add_action_buttons(); } diff --git a/mod/chat/report.php b/mod/chat/report.php index 3fc45643b8..17ca573b63 100644 --- a/mod/chat/report.php +++ b/mod/chat/report.php @@ -50,8 +50,10 @@ '', '', true, '', navmenu($course, $cm)); /// Check to see if groups are being used here - $groupmode = groupmode($course, $cm); - $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id"); + $groupmode = groups_get_activity_groupmode($cm); + $currentgroup = groups_get_activity_group($cm, true); + groups_print_activity_menu($cm, "report.php?id=$cm->id"); + if ($currentgroup) { $groupselect = " AND groupid = '$currentgroup'"; @@ -106,8 +108,9 @@ /// Check to see if groups are being used here - if ($groupmode = groupmode($course, $cm)) { // Groups are being used - $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id"); + if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used + $currentgroup = groups_get_activity_group($cm, true); + groups_print_activity_menu($cm, "report.php?id=$cm->id"); } else { $currentgroup = false; } diff --git a/mod/chat/view.php b/mod/chat/view.php index 99d4d26b5c..8ad9e46a3e 100644 --- a/mod/chat/view.php +++ b/mod/chat/view.php @@ -84,8 +84,9 @@ if (!empty($THEME->customcorners)) print_custom_corners_start(); /// Check to see if groups are being used here - $groupmode = groupmode($course, $cm); - $currentgroup = setup_and_print_groups($course, $groupmode, "view.php?id=$cm->id"); + $groupmode = groups_get_activity_groupmode($cm); + $currentgroup = groups_get_activity_group($cm, true); + groups_print_activity_menu($cm, "view.php?id=$cm->id"); if ($currentgroup) { $groupselect = " AND groupid = '$currentgroup'"; @@ -163,7 +164,7 @@ chat_delete_old_users(); - if ($chatusers = chat_get_users($chat->id, $currentgroup)) { + if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) { $timenow = time(); print_simple_box_start('center'); print_heading($strcurrentusers); -- 2.39.5