From 7cf77becec7d1013d1076500aede534768534508 Mon Sep 17 00:00:00 2001 From: nfreear Date: Thu, 23 Nov 2006 11:28:22 +0000 Subject: [PATCH] Fixes for interface change, groups_add_member, remove_member - lib and simpletest/test_groupinglib (Bug MDL-7380 "groups".) --- group/lib/automaticgroupinglib.php | 3 +- group/lib/legacylib.php | 51 ++++++++++++++++----------- group/simpletest/test_groupinglib.php | 8 ++--- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/group/lib/automaticgroupinglib.php b/group/lib/automaticgroupinglib.php index 7158436680..f648b8be28 100644 --- a/group/lib/automaticgroupinglib.php +++ b/group/lib/automaticgroupinglib.php @@ -109,7 +109,7 @@ function groups_create_automatic_grouping($courseid, $nostudentspergroup, } else { if ($userids) { foreach($userids as $userid) { - $usersadded = groups_add_member($userid, $groupid); + $usersadded = groups_add_member($groupid, $userid); // If unsuccessful just carry on I guess } } @@ -247,4 +247,5 @@ function groups_last_element_in_set($totalnoelements, $setsize, $nosets, return $lastelement; } + ?> \ No newline at end of file diff --git a/group/lib/legacylib.php b/group/lib/legacylib.php index cb3a0358c0..89b5092080 100644 --- a/group/lib/legacylib.php +++ b/group/lib/legacylib.php @@ -1,6 +1,16 @@ id, $courseid); return $groupids[0]; } @@ -197,16 +208,14 @@ function mygroupid($courseid) { function groupmode($course, $cm=null) { if ($cm and !$course->groupingid) { - return groups_has_groups_setup_for_instance($coursemodule); + //TODO: was $coursemodule + return groups_has_groups_setup_for_instance($cm); } else { return groups_has_groups_setup($course->id); } } - - - /** * Sets the current group in the session variable * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups. @@ -270,7 +279,8 @@ function get_current_group($courseid, $full = false) { * @return int|false Returns the current group id or false if error. */ function get_and_set_current_group($course, $groupmode, $groupid=-1) { - groups_has_permission($userid, $groupingid, $courseid, $groupid, $permissiontype); + //TODO: ?? groups_has_permission($userid, $groupingid, $courseid, $groupid, $permissiontype); + // Sets to the specified group, provided the current user has view permission if (!$groupmode) { // Groups don't even apply return false; @@ -287,28 +297,29 @@ function get_and_set_current_group($course, $groupmode, $groupid=-1) { if (isteacheredit($course->id)) { // Sets current default group $currentgroupid = set_current_group($course->id, $group->id); - } else if ($groupmode == VISIBLEGROUPS) { + } elseif ($groupmode == VISIBLEGROUPS) { // All groups are visible //if (ismember($group->id)){ - $currentgroupid = set_current_group($course->id, $group->id);//set this since he might post + $currentgroupid = set_current_group($course->id, $group->id); //set this since he might post /*)}else { $currentgroupid = $group->id;*/ - } else if ($groupmode == SEPARATEGROUPS) { // student in separate groups switching - if (ismember($group->id)){//check if is a member + } elseif ($groupmode == SEPARATEGROUPS) { // student in separate groups switching + if (ismember($group->id)) { //check if is a member $currentgroupid = set_current_group($course->id, $group->id); //might need to set_current_group? } else { - echo ($group->id); + echo($group->id); notify('you do not belong to this group!',error); } } } - } else { // When groupid = 0 it means show ALL groups - //this is changed, non editting teacher needs access to group 0 as well, for viewing work in visible groups (need to set current group for multiple pages) + } else { // When groupid = 0 it means show ALL groups + // this is changed, non editting teacher needs access to group 0 as well, + // for viewing work in visible groups (need to set current group for multiple pages) if (isteacheredit($course->id) OR (isteacher($course->id) AND ($groupmode == VISIBLEGROUPS))) { // Sets current default group $currentgroupid = set_current_group($course->id, 0); - } else if ($groupmode == VISIBLEGROUPS) { // All groups are visible + } elseif ($groupmode == VISIBLEGROUPS) { // All groups are visible $currentgroupid = 0; } } @@ -355,7 +366,6 @@ function setup_and_print_groups($course, $groupmode, $urlroot) { } - function oldgroups_print_user_group_info($currentgroup, $isseparategroups, $courseid) { global $CFG; if ($currentgroup and (!$isseparategroups or isteacheredit($courseid))) { /// Display info about the group @@ -377,4 +387,5 @@ function oldgroups_print_user_group_info($currentgroup, $isseparategroups, $cour } } } -?> + +?> \ No newline at end of file diff --git a/group/simpletest/test_groupinglib.php b/group/simpletest/test_groupinglib.php index 636e5a9d12..56ce99f765 100644 --- a/group/simpletest/test_groupinglib.php +++ b/group/simpletest/test_groupinglib.php @@ -21,8 +21,8 @@ class groupinglib_test extends UnitTestCase { var $groupingid = 0; function __construct() { - parent::UnitTestCase(); - //$this->setUpOnce(); + parent::UnitTestCase(); + //$this->setUpOnce(); } function __destruct() { //$this->tearDownOnce(); @@ -44,13 +44,13 @@ class groupinglib_test extends UnitTestCase { $this->groupid = groups_create_group($this->courseid); $groupinfo = groups_set_default_group_settings(); $bok = groups_set_group_settings($this->groupid, $groupinfo); - $bok = groups_add_member($this->userid, $this->groupid); + $bok = groups_add_member($this->groupid, $this->userid); } function tearDown() { parent::tearDown(); - $bok = groups_remove_member($this->userid, $this->groupid); + $bok = groups_remove_member($this->groupid, $this->userid); $bok = groups_delete_group($this->groupid); } -- 2.39.5