]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10383 - deprecated get_groups(), user_group() and ismember()
authorskodak <skodak>
Wed, 15 Aug 2007 20:21:01 +0000 (20:21 +0000)
committerskodak <skodak>
Wed, 15 Aug 2007 20:21:01 +0000 (20:21 +0000)
35 files changed:
admin/upgradeforumread.php
blocks/quiz_results/block_quiz_results.php
blog/index.php
blog/lib.php
calendar/lib.php
course/report/log/lib.php
enrol/manual/enrol.php
grade/edit/tree/grade.php
group/db/dbbasicgrouplib.php
group/index.php
group/lib/basicgrouplib.php
group/lib/legacylib.php
lib/accesslib.php
lib/datalib.php
lib/deprecatedlib.php
lib/grouplib.php [new file with mode: 0644]
mod/assignment/lib.php
mod/choice/lib.php
mod/choice/report.php
mod/data/lib.php
mod/exercise/locallib.php
mod/exercise/submissions.php
mod/forum/discuss.php
mod/forum/lib.php
mod/forum/post.php
mod/hotpot/lib.php
mod/journal/report.php
mod/survey/graph.php
mod/wiki/lib.php
mod/workshop/lib.php
mod/workshop/locallib.php
mod/workshop/view.php
search/documents/chat_document.php
search/documents/data_document.php
user/view.php

index 840e04b66ab3d313d9f0b497dd4f00660626dbd5..c8db682c7803603164c8964a41d3df0d21960699 100644 (file)
@@ -82,7 +82,7 @@
                     /// If its a group discussion, make sure the user is in the group.
                     if ($discussion->groupid) {
                         if (!isset($groups[$discussion->groupid][$user->id])) {
-                            $groups[$discussion->groupid][$user->id] = ismember($discussion->groupid, $user->id);
+                            $groups[$discussion->groupid][$user->id] = groups_is_member($discussion->groupid, $user->id);
                         }
                     }
                     if (!$discussion->groupid || !empty($groups[$discussion->groupid][$user->id])) {
index f0e8aaff75fb804d91acee11a228032e67a28fff..d3f968a77758cef60d0f5d47294d6efc32d9a2c6 100644 (file)
@@ -112,7 +112,7 @@ class block_quiz_results extends block_base {
         switch($groupmode) {
             case VISIBLEGROUPS:
             // Display group-mode results
-            $groups = get_groups($courseid);
+            $groups = groups_get_all_groups($courseid);
 
             if(empty($groups)) {
                 // No groups exist, sorry
@@ -262,7 +262,7 @@ class block_quiz_results extends block_base {
                 return $this->content;
             }
 
-            $mygroups = get_groups($courseid, $USER->id);
+            $mygroups = groups_get_all_groups($courseid, $USER->id);
             if(empty($mygroups)) {
                 // Not member of a group, show nothing
                 return $this->content;
index aeea0c71dfa32ccdff8d5714093f455334acae43..946e8b7a24f488b29bfd48b55ec250b8b49feb87 100755 (executable)
@@ -100,7 +100,7 @@ switch ($filtertype) {
         }
         if (groupmode($course) == SEPARATEGROUPS
           and !has_capability('moodle/site:accessallgroups', $coursecontext)) {
-            if (!ismember($filterselect)) {
+            if (!groups_is_member($filterselect)) {
                 error ('You are not a member of this course group');
             }
         }
index 53494cba161f42f5f35f9a9831ed16247e3acad1..3c4859d387b4b6a52f32d7874b64333ff8297dad 100755 (executable)
                       or groupmode($courseid) != SEPARATEGROUPS) {
                         return true;
                     } else {
-                        if ($usergroups = user_group($courseid, $targetuserid)) {
+                        if ($usergroups = groups_get_all_groups($courseid, $targetuserid)) {
                             foreach ($usergroups as $usergroup) {
-                                if (ismember($usergroup->id)) {
+                                if (groups_is_member($usergroup->id)) {
                                     return true;
                                 }
                             }
index b94e021a7db4ca6bfa0a9092b58e946dde52a554..6a839cf45880d18c74d336565802811d720adcc1 100644 (file)
@@ -1557,7 +1557,7 @@ function calendar_get_allowed_types(&$allowed) {
         $allowed->courses = array($course->id => 1);
 
         if($course->groupmode != NOGROUPS || !$course->groupmodeforce) {
-            $allowed->groups = get_groups($SESSION->cal_course_referer);
+            $allowed->groups = (boolean)groups_get_all_groups($SESSION->cal_course_referer);
         }
     }
 }
index 132de869679f2bff18d5233a16b195b6517a1312..942eca7e45bab4003a7f36627906f3cc7ad8583f 100644 (file)
@@ -233,7 +233,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select
     }
 
     if ($showgroups) {
-        if ($cgroups = get_groups($course->id)) {
+        if ($cgroups = groups_get_all_groups($course->id)) {
             foreach ($cgroups as $cgroup) {
                 $groups[$cgroup->id] = $cgroup->name;
             }
@@ -448,7 +448,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
     }
 
     if ($showgroups) {
-        if ($cgroups = get_groups($course->id)) {
+        if ($cgroups = groups_get_all_groups($course->id)) {
             foreach ($cgroups as $cgroup) {
                 $groups[$cgroup->id] = $cgroup->name;
             }
index f708faf11fddd8756d0a26c7242a07d6995acdb6..7a31408d4c33e60e48da4a48e8f07c1a1c9aa3ca 100644 (file)
@@ -179,7 +179,7 @@ function check_entry($form, $course) {
 */
 function check_group_entry ($courseid, $password) {
     $ingroup = false;
-    if (($groups = get_groups($courseid)) !== false) {
+    if (($groups = groups_get_all_groups($courseid))) {
         foreach ($groups as $group) {
             if ( !empty($group->enrolmentkey) and ($password == $group->enrolmentkey) ) {
                 $ingroup = $group->id;
index 701fb63e306ffef0f310de7623d936c0b0489f01..93b1410ea7d50598bbaf0fa93353f42283fb710d 100644 (file)
@@ -52,7 +52,7 @@ if (!$grade_item = grade_item::fetch(array('id'=>$itemid, 'courseid'=>$courseid)
 
 // now verify grading user has access to all groups or is member of the same group when separate groups used in course
 if (groupmode($COURSE) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
-    if ($groups = user_group($COURSE->id, $userid)) {
+    if ($groups = groups_get_all_groups($COURSE->id, $userid)) {
         $ok = false;
         foreach ($groups as $group) {
             if (groups_is_member($group->id, $USER->id)) {
index 986ed64bd8a03e4d4ee6e04c093497c5f9ccede2..40e3e9ad0b62b97c68aab7fe11edb8b1daf84a34 100644 (file)
@@ -9,9 +9,6 @@
  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  * @package groups
  */
-require_once($CFG->libdir.'/datalib.php');
-require_once($CFG->dirroot.'/group/lib.php');
-
 
 /*******************************************************************************
  * Utility functions
@@ -140,30 +137,6 @@ function groups_db_get_group_settings($groupid, $courseid=false, $alldata=false)
 
 }
 
-/**
- * Given two users, determines if there exists a group to which they both belong
- * @param int $userid1 The id of the first user
- * @param int $userid2 The id of the second user
- * @return boolean True if the users are in a common group, false otherwise or 
- * if an error occurred. 
- */
-function groups_db_users_in_common_group($userid1, $userid2) {
-    global $CFG;
-    $havecommongroup = false;
-    $sql = "SELECT gm1.groupid, 1 FROM {$CFG->prefix}groups_members gm1 " .
-        "INNER JOIN {$CFG->prefix}groups_members gm2 " .
-        "ON gm1.groupid = gm2.groupid" .
-        "WHERE gm1.userid = '$userid1' AND gm2.userid = '$userid2'";
-    $commongroups = get_record_sql($sql);
-    if ($commongroups) {
-        $havecommongroup = true;
-    }
-
-    return $havecommongroup;           
-}
-
-
-
 /******************************************************************************* 
    Membership functions  
  ******************************************************************************/
@@ -185,64 +158,6 @@ function groups_db_group_exists($groupid) {
     return $exists;
 }
 
-
-/**
- * Determine if a course ID, group name and description match a group in the database.
- *   For backup/restorelib.php
- * @return mixed A group-like object with $group->id, or false.
- */
-function groups_db_group_matches($courseid, $grp_name, $grp_description) {
-//$gro_db->id; $gro_db = get_record("groups","courseid",$restore->course_id,"name",$gro->name,"description",$gro->description);    
-    global $CFG;
-    $sql = "SELECT g.id, g.name, g.description
-        FROM {$CFG->prefix}groups g
-        WHERE g.name = '$grp_name'
-        AND g.description = '$grp_description'
-        AND g.courseid = '$courseid'";
-    $records = get_records_sql($sql);
-    $group = false;
-    if ($records) {
-        $group = array_shift($records);
-    } 
-    return $group;
-}
-
-/**
- * Determine if a course ID, and group name match a group in the database.
- * @return mixed A group-like object with $group->id, or false.
- */
-function groups_db_group_name_exists($courseid, $grp_name) {
-    global $CFG;
-    $sql = "SELECT g.id, g.name
-        FROM {$CFG->prefix}groups g
-        WHERE g.name = '$grp_name'
-        AND g.courseid = '$courseid'";
-    $records = get_records_sql($sql);
-    $group = false;
-    if ($records) {
-        $group = current($records);
-    } 
-    return $group;
-}
-
-/**
- * Determines if a specified user is a member of a specified group
- * @param int $groupid The group about which the request has been made
- * @param int $userid The user about which the request has been made
- * @return boolean True if the user is a member of the group, false otherwise
- */
-function groups_db_is_member($groupid, $userid) {
-    if (!$groupid or !$userid) {
-        $ismember = false;
-    } else {
-        $ismember = record_exists($table = 'groups_members', 'groupid', 
-                                  $groupid, 'userid', $userid);
-    }
-    
-    return $ismember;
-}
-
-
 /**
  * Determines if a specified group is a group for a specified course
  * @param int $groupid The group about which the request has been made
@@ -399,54 +314,6 @@ function groups_db_remove_member($groupid, $userid) {
 }
 
 
-/** 
- * Delete a specified group, first removing members and links with courses and groupings. 
- * @param int $groupid The group to delete
- * @return boolean True if deletion was successful, false otherwise
- */
-function groups_db_delete_group($groupid) {
-    if (!$groupid) {
-        $success = false;
-    } else {
-        $success = true;
-        // Get a list of users for the group and remove them all.
-
-        $userids = groups_db_get_members($groupid);
-        if ($userids != false) {
-            foreach($userids as $userid) {
-                $userdeleted = groups_db_remove_member($userid, $groupid);
-                if (!$userdeleted) {
-                    $success = false;
-                }
-            }
-        }
-
-        // Remove any links with groupings to which the group belongs.
-        //TODO: dbgroupinglib also seems to delete these links - duplication?
-        $groupingids = groups_get_groupings_for_group($groupid); 
-        if ($groupingids != false) {
-            foreach($groupingids as $groupingid) {
-                $groupremoved = groups_remove_group_from_grouping($groupid, 
-                    $groupingid);
-                if(!$groupremoved) {
-                    $success = false; 
-                }
-            }
-        }
-        
-        // Delete the group itself
-        $results = delete_records($table = 'groups', $field1 = 'id', 
-            $value1 = $groupid);
-        // delete_records returns an array of the results from the sql call, 
-        // not a boolean, so we have to set our return variable
-        if ($results == false) {
-            $success = false;
-        }
-    }
-
-    return $success;
-}
-
 /**
  * Internal function to set the time a group was modified.
  */
@@ -455,49 +322,4 @@ function groups_db_set_group_modified($groupid) {
 }
 
 
-/******************************************************************************
- * Groups SQL clauses for modules and core.
- */
-
-/**
- * Returns the table in which group members are stored, with a prefix 'gm'.
- * @return SQL string.
- */
-function groups_members_from_sql() {
-    global $CFG;
-    return " {$CFG->prefix}groups_members gm ";
-}
-
-/**
- * Returns a join testing user.id against member's user ID.
- * Relies on 'user' table being included as 'user u'.
- * Used in Quiz module reports.
- * @param group ID, optional to include a test for this in the SQL.
- * @return SQL string.
- */
-function groups_members_join_sql($groupid=false) {    
-    $sql = ' JOIN '.groups_members_from_sql().' ON u.id = gm.userid ';
-    if ($groupid) {
-        $sql = "AND gm.groupid = '$groupid' ";
-    }
-    return $sql;
-    //return ' INNER JOIN '.$CFG->prefix.'role_assignments ra ON u.id=ra.userid'.
-    //       ' INNER JOIN '.$CFG->prefix.'context c ON ra.contextid=c.id AND c.contextlevel='.CONTEXT_GROUP.' AND c.instanceid='.$groupid;
-}
-
-/**
- * Returns SQL for a WHERE clause testing the group ID.
- * Optionally test the member's ID against another table's user ID column. 
- * @param groupid
- * @param userid_sql Optional user ID column selector, example "mdl_user.id", or false.
- * @return SQL string.
- */
-function groups_members_where_sql($groupid, $userid_sql=false) {
-    $sql = " gm.groupid = '$groupid' ";
-    if ($userid_sql) {
-        $sql .= "AND $userid_sql = gm.userid ";
-    }
-    return $sql;
-}
-
 ?>
index 72f71aacd3df355258da6f8e5a8011fea374994b..ab86fc3bd0e9f251cf824525ac36d3d959d77f8b 100644 (file)
@@ -129,8 +129,8 @@ if (!$course = groups_get_course_info($courseid)) {
     echo '<select name="group" id="groups" size="15" class="select" onchange="membersCombo.refreshMembers(this.options[this.selectedIndex].value);"'."\n";
     echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n";
 
-    if ($groups_records = get_groups($courseid)) {
-        $groupids = groups_groups_to_groupids($groups_records, $courseid);
+    if ($groups = groups_get_all_groups($courseid)) {
+        $groupids = array_keys($groups);
     } else {
         $groupids = false;
     }
@@ -216,5 +216,37 @@ if (!$course = groups_get_course_info($courseid)) {
 
     print_footer($course);
 
+/**
+ * Returns the first button action with the given prefix, taken from
+ * POST or GET, otherwise returns false.
+ * See /lib/moodlelib.php function optional_param.
+ * @param $prefix 'act_' as in 'action'.
+ * @return string The action without the prefix, or false if no action found.
+ */
+function groups_param_action($prefix = 'act_') {
+    $action = false;
+//($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/
+
+    if ($_POST) {
+        $form_vars = $_POST;
+    }
+    elseif ($_GET) {
+        $form_vars = $_GET; 
+    }
+    if ($form_vars) {
+        foreach ($form_vars as $key => $value) {
+            if (preg_match("/$prefix(.+)/", $key, $matches)) {
+                $action = $matches[1];
+                break;
+            }
+        }
+    }
+    if ($action && !preg_match('/^\w+$/', $action)) {
+        $action = false;
+        error('Action had wrong type.');
+    }
+    ///if (debugging()) echo 'Debug: '.$action;
+    return $action;
+}
 
 ?>
\ No newline at end of file
index 625939f09cb2823934f516fd636062f39c90fbd3..f18a42471a6e3d42992a74d9a7accbd976d55701 100644 (file)
@@ -27,18 +27,6 @@ require_once($CFG->dirroot.'/group/db/dbbasicgrouplib.php');
     List functions  
  *****************************/
 
-/**
- * Gets a list of the group IDs for a specified course.
- * @param int $courseid The id of the course.
- * @return array | false Returns an array of the group IDs or false if no records
- * or an error occurred.
- */
-function groups_get_groups($courseid) {
-    $groupids = groups_db_get_groups($courseid);
-    return $groupids;
-}
-
-
 /**
  * Returns the ids of the users in the specified group.
  * @param int $groupid The groupid to get the users for
@@ -149,90 +137,6 @@ function groups_get_group_name($groupid) {
     return false;
 }
 
-/**
- * Gets the users for a course who are not in a specified group
- * @param int $groupid The id of the group
- * @param string searchtext similar to searchtext in role assign, search
- * @return array An array of the userids of the non-group members,  or false if 
- * an error occurred.  
- * This function was changed to get_users_by_capability style
- * mostly because of the searchtext requirement
- */
-function groups_get_users_not_in_group($courseid, $groupid, $searchtext='') {
-    
-    global $CFG;
-
-    $context = get_context_instance(CONTEXT_COURSE, $courseid);
-
-    if ($searchtext !== '') {   // Search for a subset of remaining users
-        $LIKE      = sql_ilike();
-        $FULLNAME  = sql_fullname();
-        $wheresearch = " AND u.id IN (SELECT id FROM {$CFG->prefix}user WHERE $FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%' )";
-    } else {
-        $wheresearch = ''; 
-    }
-    
-    $capability = 'moodle/course:view';
-    $doanything = false;
-
-    // find all possible "student" roles
-    if ($possibleroles = get_roles_with_capability($capability, CAP_ALLOW, $context)) {
-        if (!$doanything) {
-            if (!$sitecontext = get_context_instance(CONTEXT_SYSTEM)) {
-                return false;    // Something is seriously wrong
-            }
-            $doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
-        }
-
-        $validroleids = array();
-        foreach ($possibleroles as $possiblerole) {
-            if (!$doanything) {
-                if (isset($doanythingroles[$possiblerole->id])) {  // We don't want these included
-                    continue;
-                }
-            }
-            if ($caps = role_context_capabilities($possiblerole->id, $context, $capability)) { // resolved list
-                if (isset($caps[$capability]) && $caps[$capability] > 0) { // resolved capability > 0
-                    $validroleids[] = $possiblerole->id;
-                }
-            }
-        }
-        if (empty($validroleids)) {
-            return false;
-        }
-        $roleids =  '('.implode(',', $validroleids).')';
-    } else {
-        return false;  // No need to continue, since no roles have this capability set
-    }
-
-/// Construct the main SQL
-    $select = " SELECT u.id, u.firstname, u.lastname";
-    $from   = " FROM {$CFG->prefix}user u
-                INNER JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id
-                INNER JOIN {$CFG->prefix}role r ON r.id = ra.roleid";
-    $where  = " WHERE ra.contextid ".get_related_contexts_string($context)."
-                  AND u.deleted = 0
-                  AND ra.roleid in $roleids
-                  AND u.id NOT IN (SELECT userid 
-                                   FROM {$CFG->prefix}groups_members 
-                                   WHERE groupid = $groupid)
-                  $wheresearch";
-
-    return get_records_sql($select.$from.$where);;
-}
-
-/**
- * Given two users, determines if there exists a group to which they both belong
- * @param int $userid1 The id of the first user
- * @param int $userid2 The id of the second user
- * @return boolean True if the users are in a common group, false otherwise or 
- * if an error occurred. 
- */
-function groups_users_in_common_group($userid1, $userid2) {
-    return groups_db_users_in_common_group($userid1, $userid2); 
-}
-
-
 /*****************************
    Membership functions 
  *****************************/
@@ -248,43 +152,6 @@ function groups_group_exists($groupid) {
     return groups_db_group_exists($groupid);
 }
 
-
-/**
- * Determine if a course ID, group name and description match a group in the database.
- *   For backup/restorelib.php
- * @return mixed A group-like object with $group->id, or false.
- */
-function groups_group_matches($courseid, $grp_name, $grp_description) {
-    return groups_db_group_matches($courseid, $grp_name, $grp_description);
-}
-
-/**
- * Determine if a course ID, and group name match a group in the database.
- * @return mixed A group-like object with $group->id, or false.
- */
-function groups_group_name_exists($courseid, $grp_name) {
-    return groups_db_group_name_exists($courseid, $grp_name);
-}
-
-/**
- * Determines if the user is a member of the given group.
- *
- * @uses $USER If $userid is null, use the global object.
- * @param int $groupid The group to check for membership.
- * @param int $userid The user to check against the group.
- * @return boolean True if the user is a member, false otherwise.
- */
-function groups_is_member($groupid, $userid = null) { 
-    if (! $userid) {
-        global $USER;
-        $userid = $USER->id;
-    }
-    $ismember = groups_db_is_member($groupid, $userid);
-    
-    return $ismember;
-}
-
-
 /**
  * Determines if a specified group is a group for a specified course
  * @param int $groupid The group about which the request has been made
@@ -424,19 +291,6 @@ function groups_restore_member($member) {
  *****************************/
 
 
-/**
- * Delete a group best effort, first removing members and links with courses and groupings. 
- * @param int $groupid The group to delete
- * @return boolean True if deletion was successful, false otherwise
- * See comment above on web service autoupdating. 
- */
-function groups_delete_group($groupid) {
-    $groupdeleted = groups_db_delete_group($groupid);
-
-    return $groupdeleted;
-}
-
-
 /**
  * Deletes the link between the specified user and group.
  * @param int $groupid The group to delete the user from
index db5dc02c66e19348eb3637f32a3ba02a74df4634..79b2ca81520d91ed0e93d6624bb495c720219ee6 100644 (file)
 
 
 
-
-/**
- * Returns an array of group objects that the user is a member of
- * in the given course.  If userid isn't specified, then return a
- * list of all groups in the course.
- *
- * @uses $CFG
- * @param int $courseid The id of the course in question.
- * @param int $userid The id of the user in question as found in the 'user' 
- * table 'id' field.
- * @return object
- */
-function get_groups($courseid, $userid=0) {
-    if ($userid) {
-        $groupids = groups_get_groups_for_user($userid, $courseid);
-    } else {
-        $groupids = array_keys(groups_get_all_groups($courseid));
-    }
-
-    return groups_groupids_to_groups($groupids, $courseid, $alldata=true);
-}
-
-
-/**
- * Returns the user's group in a particular course
- *
- * @uses $CFG
- * @param int $courseid The course in question.
- * @param int $userid The id of the user as found in the 'user' table.
- * @param int $groupid The id of the group the user is in.
- * @return object
- */
-function user_group($courseid, $userid) {
-    $groupids = groups_get_groups_for_user($userid, $courseid);
-    return groups_groupids_to_groups($groupids);
-}
-
-
-/**
- * Determines if the user is a member of the given group.
- * TODO: replace all calls with 'groups_is_member'.
- *
- * @param int $groupid The group to check for membership.
- * @param int $userid The user to check against the group.
- * @return boolean True if the user is a member, false otherwise.
- */
-function ismember($groupid, $userid = null) {
-    return groups_is_member($groupid, $userid);
-}
-
 /**
  * Returns an array of user objects
  *
@@ -140,13 +90,6 @@ function groupmode($course, $cm=null) {
         return $cm->groupmode;
     }
     return $course->groupmode;
-    
-    /*if ($cm and !$course->groupingid) {
-        //TODO: was $coursemodule
-        return groups_has_groups_setup_for_instance($cm);
-    } else {
-        return groups_has_groups_setup($course->id);
-    }*/
 }
 
 
@@ -243,12 +186,12 @@ function get_and_set_current_group($course, $groupmode, $groupid=-1) {
 
             } elseif ($groupmode == VISIBLEGROUPS) {
                   // All groups are visible
-                //if (ismember($group->id)){
+                //if (groups_is_member($group->id)){
                     $currentgroupid = set_current_group($course->id, $groupid); //set this since he might post
                 /*)}else {
                     $currentgroupid = $group->id;*/
             } elseif ($groupmode == SEPARATEGROUPS) { // student in separate groups switching
-                if (ismember($groupid)) { //check if is a member
+                if (groups_is_member($groupid)) { //check if is a member
                     $currentgroupid = set_current_group($course->id, $groupid); //might need to set_current_group?
                 }
                 else {
@@ -304,7 +247,7 @@ function setup_and_print_groups($course, $groupmode, $urlroot) {
         //this can mean that either, this guy has no group
         //or, this guy just came from a visible all forum, and he left when he set his current group to 0 (show all)
 
-        if ($usergroups = user_group($course->id, $USER->id)){
+        if ($usergroups = groups_get_all_groups($course->id, $USER->id)){
             //for the second situation, we need to perform the trick and get him a group.
             $first = reset($usergroups);
             $currentgroup = get_and_set_current_group($course, $groupmode, $first->id);
@@ -319,7 +262,7 @@ function setup_and_print_groups($course, $groupmode, $urlroot) {
 
     if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/site:accessallgroups', $context))) {
 
-        if ($groups = get_groups($course->id)) {
+        if ($groups = groups_get_all_groups($course->id)) {
 
             echo '<div class="groupselector">';
             print_group_menu($groups, $groupmode, $currentgroup, $urlroot, 1);
@@ -328,7 +271,7 @@ function setup_and_print_groups($course, $groupmode, $urlroot) {
 
     } else if ($groupmode == SEPARATEGROUPS and has_capability('moodle/course:view', $context)) {
         //get all the groups this guy is in in this course
-        if ($usergroups = user_group($course->id, $USER->id)){
+        if ($usergroups = groups_get_all_groups($course->id, $USER->id)){
             echo '<div class="groupselector">';
             //print them in the menu
             print_group_menu($usergroups, $groupmode, $currentgroup, $urlroot, 0);
index dded2a34d932307395efcddffb8a401dc4d75485..5dfb3071eafcb335c5c5ca03fd98f711f598b309 100755 (executable)
@@ -2348,7 +2348,7 @@ function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0, $enrol=NU
                     // this may be slow, but this is the proper way of doing it
                     if (!has_capability('moodle/course:view', $context, $ra->userid)) {
                         // remove from groups
-                        if ($groups = get_groups($context->instanceid, $ra->userid)) {
+                        if ($groups = groups_get_all_groups($context->instanceid)) {
                             foreach ($groups as $group) {
                                 delete_records('groups_members', 'groupid', $group->id, 'userid', $ra->userid);
                             }
@@ -3193,7 +3193,7 @@ function get_child_contexts($context) {
                 }
             }
             // Find all module instances for the course.
-            if ($modules = get_records('course_modules', 'course', $context->instanceid)) {
+            if ($modules = get_records('course_modules', 'course', $context->instanceid, '', 'id')) {
                 foreach ($modules as $module) {
                     if ($child = get_context_instance(CONTEXT_MODULE, $module->id)) {
                         array_push($children, $child->id);
@@ -3201,9 +3201,9 @@ function get_child_contexts($context) {
                 }
             }
             // Find all group instances for the course.
-            if ($groupids = groups_get_groups($context->instanceid)) {
-                foreach ($groupids as $groupid) {
-                    if ($child = get_context_instance(CONTEXT_GROUP, $groupid)) {
+            if ($groups = get_records('groups', 'courseid', $context->instanceid, '', 'id')) {
+                foreach ($groups as $group) {
+                    if ($child = get_context_instance(CONTEXT_GROUP, $group->id)) {
                         array_push($children, $child->id);
                     }
                 }
@@ -3232,7 +3232,7 @@ function get_child_contexts($context) {
 
             foreach ($categories as $catid) {
                 // Find all courses for the category.
-                if ($courses = get_records('course', 'category', $catid)) {
+                if ($courses = get_records('course', 'category', $catid, '', 'id')) {
                     foreach ($courses as $course) {
                         if ($courseci = get_context_instance(CONTEXT_COURSE, $course->id)) {
                             array_push($children, $courseci->id);
index 1d8f8eaaef341d62ab8d79246e51a4bfb97391e1..48f405c53eeb1295a072827b5c6826e53fc4c130 100644 (file)
@@ -376,93 +376,6 @@ function get_users_not_fully_set_up($cutofftime=2000000000) {
                              AND (lastname = '' OR firstname = '' OR email = '')");
 }
 
-
-/** TODO: functions now in /group/lib/legacylib.php (3)
-get_groups
-get_group_users
-user_group
-
- * Returns an array of group objects that the user is a member of
- * in the given course.  If userid isn't specified, then return a
- * list of all groups in the course.
- *
- * @uses $CFG
- * @param int $courseid The id of the course in question.
- * @param int $userid The id of the user in question as found in the 'user' table 'id' field.
- * @return object
- *
-function get_groups($courseid, $userid=0) {
-    global $CFG;
-
-    if ($userid) {
-        $dbselect = ', '. $CFG->prefix .'groups_members m';
-        $userselect = 'AND m.groupid = g.id AND m.userid = \''. $userid .'\'';
-    } else {
-        $dbselect = '';
-        $userselect = '';
-    }
-
-    return get_records_sql("SELECT g.*
-                              FROM {$CFG->prefix}groups g $dbselect
-                             WHERE g.courseid = '$courseid' $userselect ");
-}
-
-
-/**
- * Returns an array of user objects that belong to a given group
- *
- * @uses $CFG
- * @param int $groupid The group in question.
- * @param string $sort ?
- * @param string $exceptions ?
- * @return object
- *
-function get_group_users($groupid, $sort='u.lastaccess DESC', $exceptions='', $fields='u.*') {
-    global $CFG;
-    if (!empty($exceptions)) {
-        $except = ' AND u.id NOT IN ('. $exceptions .') ';
-    } else {
-        $except = '';
-    }
-    // in postgres, you can't have things in sort that aren't in the select, so...
-    $extrafield = str_replace('ASC','',$sort);
-    $extrafield = str_replace('DESC','',$extrafield);
-    $extrafield = trim($extrafield);
-    if (!empty($extrafield)) {
-        $extrafield = ','.$extrafield;
-    }
-    return get_records_sql("SELECT $fields $extrafield
-                              FROM {$CFG->prefix}user u,
-                                   {$CFG->prefix}groups_members m
-                             WHERE m.groupid = '$groupid'
-                               AND m.userid = u.id $except
-                          ORDER BY $sort");
-}
-
-/**
- * Returns the user's group in a particular course
- *
- * @uses $CFG
- * @param int $courseid The course in question.
- * @param int $userid The id of the user as found in the 'user' table.
- * @param int $groupid The id of the group the user is in.
- * @return object
- *
-function user_group($courseid, $userid) {
-    global $CFG;
-
-    return get_records_sql("SELECT g.*
-                             FROM {$CFG->prefix}groups g,
-                                  {$CFG->prefix}groups_members m
-                             WHERE g.courseid = '$courseid'
-                               AND g.id = m.groupid
-                               AND m.userid = '$userid'
-                               ORDER BY name ASC");
-}
-*/
-
-
-
 /// OTHER SITE AND COURSE FUNCTIONS /////////////////////////////////////////////
 
 
index 2cf14dde30d5d4f4492edff223d0b189518fce85..e153f7f1b2f3f21e3a06ca549afee7087a0bb369 100644 (file)
@@ -834,7 +834,7 @@ function get_group_teachers($courseid, $groupid) {
             if ($teacher->editall) {             // These can access anything
                 continue;
             }
-            if (($teacher->authority > 0) and ismember($groupid, $teacher->id)) {  // Specific group teachers
+            if (($teacher->authority > 0) and groups_is_member($groupid, $teacher->id)) {  // Specific group teachers
                 continue;
             }
             unset($teachers[$key]);
@@ -1104,4 +1104,44 @@ function groups_members_where_sql($groupid, $userid_sql=false) {
 }
 
 
+/**
+ * Returns an array of group objects that the user is a member of
+ * in the given course.  If userid isn't specified, then return a
+ * list of all groups in the course.
+ *
+ * @uses $CFG
+ * @param int $courseid The id of the course in question.
+ * @param int $userid The id of the user in question as found in the 'user' table 'id' field.
+ * @return object
+ */
+function get_groups($courseid, $userid=0) {
+    return groups_get_all_groups($courseid, $userid);
+}
+
+/**
+ * Returns the user's groups in a particular course
+ * note: this function originally returned only one group
+ *
+ * @uses $CFG
+ * @param int $courseid The course in question.
+ * @param int $userid The id of the user as found in the 'user' table.
+ * @param int $groupid The id of the group the user is in.
+ * @return aray of groups
+ */
+function user_group($courseid, $userid) {
+    return groups_get_all_groups($courseid, $userid);
+}
+
+
+/**
+ * Determines if the user is a member of the given group.
+ *
+ * @param int $groupid The group to check for membership.
+ * @param int $userid The user to check against the group.
+ * @return boolean True if the user is a member, false otherwise.
+ */
+function ismember($groupid, $userid = null) {
+    return groups_is_member($groupid, $userid);
+}
+
 ?>
diff --git a/lib/grouplib.php b/lib/grouplib.php
new file mode 100644 (file)
index 0000000..8d53694
--- /dev/null
@@ -0,0 +1,76 @@
+<?php  //$Id$
+
+// folowing files will be removed soon
+require_once($CFG->dirroot.'/group/lib/basicgrouplib.php');
+require_once($CFG->dirroot.'/group/lib/groupinglib.php');
+require_once($CFG->dirroot.'/group/lib/utillib.php');
+require_once($CFG->dirroot.'/group/lib/legacylib.php');
+
+/**
+ * Returns the groupid of a group with the name specified for the course.
+ * Group names should be unique in course
+ * @param int $courseid The id of the course
+ * @param string $name name of group (without magic quotes)
+ * @return int $groupid
+ */
+function groups_get_group_by_name($courseid, $name) {
+    if (!$group = get_record('groups', 'courseid', $courseid, 'name', addslashes($name))) {
+        return false;
+    }
+
+    return $group->id;
+}
+
+/**
+ * Get the group object
+ * @param groupid ID of the group.
+ * @return group object
+ */
+function groups_get_group($groupid) {
+    return get_record('groups', 'id', $groupid);
+}
+
+/**
+ * Gets array of all groups in a specified course.
+ * @param int $courseid The id of the course.
+ * @param int $userid optional user id, returns only groups of the user.
+ * @return array | false Returns an array of the group IDs or false if no records
+ * or an error occurred.
+ */
+function groups_get_all_groups($courseid, $userid=0) {
+    global $CFG;
+
+    if (empty($userdi)) {
+        return get_records('groups', 'courseid', $courseid, 'name ASC');
+
+    } else {
+        return get_records_sql("SELECT g.*
+                                 FROM {$CFG->prefix}groups g,
+                                      {$CFG->prefix}groups_members m
+                                 WHERE g.courseid = '$courseid'
+                                   AND g.id = m.groupid
+                                   AND m.userid = '$userid'
+                                   ORDER BY name ASC");
+    }
+}
+
+/**
+ * Determines if the user is a member of the given group.
+ *
+ * @uses $USER If $userid is null, use the global object.
+ * @param int $groupid The group to check for membership.
+ * @param int $userid The user to check against the group.
+ * @return boolean True if the user is a member, false otherwise.
+ */
+function groups_is_member($groupid, $userid=null) {
+    global $USER;
+
+    if (!$userid) {
+        $userid = $USER->id;
+    }
+
+    return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid);
+}
+
+
+?>
index e4b7c631867d48f8ae847ceab8bac2c1d8dd56b1..be84dafb2e93639b2e9908c2571e7efcbb4de449 100644 (file)
@@ -1513,7 +1513,7 @@ class assignment_base {
 
         $graders = array();
         if (groupmode($this->course, $this->cm) == SEPARATEGROUPS) {   // Separate groups are being used
-            if ($groups = user_group($this->course->id, $user->id)) {  // Try to find all groups
+            if ($groups = groups_get_all_groups($this->course->id, $user->id)) {  // Try to find all groups
                 foreach ($groups as $group) {
                     foreach ($potgraders as $t) {
                         if ($t->id == $user->id) {
@@ -1530,7 +1530,7 @@ class assignment_base {
                     if ($t->id == $user->id) {
                         continue; // do not send self
                     }
-                    if (!user_group($this->course->id, $t->id)) { //ugly hack
+                    if (!groups_get_all_groups($this->course->id, $t->id)) { //ugly hack
                         $graders[$t->id] = $t;
                     }
                 }
@@ -2349,7 +2349,7 @@ function assignment_get_recent_mod_activity(&$activities, &$index, $sincetime, $
       return;
 
     foreach ($assignments as $assignment) {
-        if (empty($groupid) || ismember($groupid, $assignment->userid)) {
+        if (empty($groupid) || groups_is_member($groupid, $assignment->userid)) {
 
           $tmpactivity = new Object;
 
index ee922a23702e397d9fdca07c1438174e48ba2d20..1598e8527adb067d849ab6164ffad66dc529998c 100644 (file)
@@ -290,7 +290,7 @@ function choice_show_reportlink($choice, $courseid, $cmid, $groupmode) {
         $responsecount = 0;
         foreach ($allanswers as $aa) {
             if ($groupmode and $currentgroup) {
-                if (ismember($currentgroup, $aa->userid)) {
+                if (groups_is_member($currentgroup, $aa->userid)) {
                     $responsecount++;
                 }
             } else {
@@ -335,7 +335,7 @@ function choice_show_results($choice, $course, $cm, $forcepublish='') {
         foreach ($allresponses as $aa) {
             //TODO: rewrite with SQL
             if ($groupmode and $currentgroup) {
-                if (ismember($currentgroup, $aa->userid)) {
+                if (groups_is_member($currentgroup, $aa->userid)) {
                     $answers[$aa->userid] = $aa;
                 }
             } else {
index fc00007a7d71d8dcd16cd085047d4ea09a990942..57f89652e672ca15ae2e4d4aca5b2aebd8cc7a20 100644 (file)
                         $studentid=(!empty($user->idnumber) ? $user->idnumber : " ");
                         $myxls->write_string($row,2,$studentid);
                         $ug2 = '';
-                        if ($usergrps = user_group($course->id, $user->id)) {
+                        if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
                             foreach ($usergrps as $ug) {
                                 $ug2 = $ug2. $ug->name;
                             }
                         $studentid=(!empty($user->idnumber) ? $user->idnumber : " ");
                         $myxls->write_string($row,2,$studentid);
                         $ug2 = '';
-                        if ($usergrps = user_group($course->id, $user->id)) {
+                        if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
                             foreach ($usergrps as $ug) {
                                 $ug2 = $ug2. $ug->name;
                             }
                 }              
                 echo "\t". $studentid."\t";
                 $ug2 = '';
-                if ($usergrps = user_group($course->id, $user->id)) {
+                if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
                     foreach ($usergrps as $ug) {
                         $ug2 = $ug2. $ug->name;
                     }
index 43a208ce1d45ef0750a87812eff1c2fc512bb08a..62f36cd47ec77cf09a4dbf2ef1efda658c23afcb 100755 (executable)
@@ -1395,7 +1395,7 @@ function data_print_comment($data, $comment, $page=0) {
     echo '</div></td></tr>';
 
     echo '<tr><td class="left side">';
-    if ($groups = user_group($data->course, $comment->userid)) {
+    if ($groups = groups_get_all_groups($data->course, $comment->userid)) {
         print_group_picture($groups, $data->course, false, false, true);
     } else {
         echo '&nbsp;';
@@ -1735,7 +1735,7 @@ function data_user_can_add_entry($data, $currentgroup, $groupmode) {
     }
 
     if ($currentgroup) {
-        return ismember($currentgroup);
+        return groups_is_member($currentgroup);
     } else {
         //else it might be group 0 in visible mode
         if ($groupmode == VISIBLEGROUPS){
index 62f96cca47a152c20500799d019230c101932289..b607c74904774bd3ff4adba9db4160ca9009ccce 100644 (file)
@@ -794,7 +794,7 @@ function exercise_list_submissions_for_admin($exercise) {
             // check group membership, if necessary
             if ($groupid) {
                 // check user's group
-                if (!ismember($groupid, $user->id)) {
+                if (!groups_is_member($groupid, $user->id)) {
                     continue; // skip this user
                 }
             }
@@ -890,7 +890,7 @@ function exercise_list_submissions_for_admin($exercise) {
             // check group membership, if necessary
             if ($groupid) {
                 // check user's group
-                if (!ismember($groupid, $user->id)) {
+                if (!groups_is_member($groupid, $user->id)) {
                     continue; // skip this user
                 }
             }
index 529b7907aaf4b53a603919b6b067206af63c1d3f..eb9430965dcdb100bb037b070740e678a14ae98d 100644 (file)
             // check group membership, if necessary
             if ($groupid) {
                 // check user's group
-                if (!ismember($groupid, $user->id)) {
+                if (!groups_is_member($groupid, $user->id)) {
                     continue; // skip this user
                 }
             }
index c7ac29ef7e092e712c30df7efb9fdc0d96e8d77b..72eb295ed1e1077e7c335016eb788a3cfbb13b24 100644 (file)
          
         if ($groupmode && !has_capability('moodle/site:accessallgroups', $modcontext)) {   
             // Groups must be kept separate
-            //change this to ismember
+            //change this to groups_is_member
             $mygroupid = mygroupid($course->id); //only useful if 0, otherwise it's an array now
             if ($groupmode == SEPARATEGROUPS) {
                 require_login();
 
-                if ((empty($mygroupid) and $discussion->groupid == -1) || (ismember($discussion->groupid) || $mygroupid == $discussion->groupid)) {
+                if ((empty($mygroupid) and $discussion->groupid == -1) || (groups_is_member($discussion->groupid) || $mygroupid == $discussion->groupid)) {
                     // $canreply = true;
                 } elseif ($discussion->groupid == -1) {
                     $canreply = false;
 
             } else if ($groupmode == VISIBLEGROUPS) {
                 $canreply = ( (empty($mygroupid) && $discussion->groupid == -1) ||
-                    (ismember($discussion->groupid) || $mygroupid == $discussion->groupid) );
+                    (groups_is_member($discussion->groupid) || $mygroupid == $discussion->groupid) );
             }
         }
     } else { // allow guests to see the link
index 5f9dec26a5bf10faca03247d4b87a39650f77c14..2bff3c127e66fa358fa971e7afb324263c807a9b 100644 (file)
@@ -396,7 +396,7 @@ function forum_cron() {
                         continue;                           // Be safe and don't send it to anyone
                     }
 
-                    if (!ismember($discussion->groupid) and !has_capability('moodle/site:accessallgroups', $modcontext)) {
+                    if (!groups_is_member($discussion->groupid) and !has_capability('moodle/site:accessallgroups', $modcontext)) {
                         // do not send posts from other groups when in SEPARATEGROUPS or VISIBLEGROUPS
                         continue;
                     }
@@ -1377,7 +1377,7 @@ function forum_get_readable_forums($userid, $courseid=0) {
 
         if ($forums = get_records_sql($selectforums)) {
 
-            $group = user_group($course->id, $userid);
+            $group = groups_get_all_groups($course->id, $userid);
 
             foreach ($forums as $forum) {
                 $forumcontext = get_context_instance(CONTEXT_MODULE, $forum->cmid);
@@ -2036,7 +2036,7 @@ function forum_make_mail_post(&$post, $user, $touser, $course,
     $output .= '</td></tr>';
 
     $output .= '<tr><td class="left side" valign="top">';
-    if ($group = user_group($course->id, $user->id)) {
+    if ($group = groups_get_all_groups($course->id, $user->id)) {
         $output .= print_group_picture($group, $course->id, false, true, true);
     } else {
         $output .= '&nbsp;';
@@ -2211,7 +2211,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
     echo '</div></td></tr>';
 
     echo '<tr><td class="left side">';
-    if ($group = user_group($courseid, $post->userid)) {
+    if ($group = groups_get_all_groups($courseid, $post->userid)) {
         print_group_picture($group, $courseid, false, false, true);
     } else {
         echo '&nbsp;';
@@ -3341,7 +3341,7 @@ function forum_user_can_post_discussion($forum, $currentgroup=-1, $groupmode=-1,
     }
 
     if ($currentgroup) {
-        return ismember($currentgroup);
+        return groups_is_member($currentgroup);
     } else {
         //else it might be group 0 in visible mode
         if ($groupmode == VISIBLEGROUPS){
@@ -3406,7 +3406,7 @@ function forum_user_can_view_post($post, $course, $cm, $forum, $discussion, $use
     if ($discussion->groupid > 0) {
         $groupmode = groupmode($course, $cm);
         if ($groupmode == SEPARATEGROUPS) {
-            return ismember($discussion->groupid) || has_capability('moodle/site:accessallgroups', $modcontext);
+            return groups_is_member($discussion->groupid) || has_capability('moodle/site:accessallgroups', $modcontext);
         }
     }
     return true;
@@ -3560,7 +3560,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis
         echo '</div>';
         echo '</form>';
         echo "</div>\n";
-    } else if (!isguestuser() and isloggedin() and $forum->type != 'news' and $groupmode == SEPARATEGROUPS and !ismember($currentgroup)) {
+    } else if (!isguestuser() and isloggedin() and $forum->type != 'news' and $groupmode == SEPARATEGROUPS and !groups_is_member($currentgroup)) {
         notify(get_string('cannotadddiscussion', 'forum'));
     }
 
index 47f357cc8048e25ccede63550257ac9e32d29829..4c361c5bbbdc04b8ec63666cb84eec78c202fe31 100644 (file)
             if (groupmode($course, $cm)) {   // Make sure user can post here
                 $mygroupid = mygroupid($course->id);
                 if (!((empty($mygroupid) and $discussion->groupid == -1)
-                        || (ismember($discussion->groupid)/*$mygroupid == $discussion->groupid*/)
+                        || (groups_is_member($discussion->groupid)/*$mygroupid == $discussion->groupid*/)
                         || has_capability('moodle/site:accessallgroups', $modcontext, NULL, false) )) {
                     print_error('nopostdiscussion', 'forum');
                 }
index 058565103e8c97a0dab0e8dea54ad8e88ec7ecc5..c22d6e934b9fb5d504e7e654b71a8578013d02cf 100644 (file)
@@ -1032,7 +1032,7 @@ function hotpot_get_recent_mod_activity(&$activities, &$index, $sincetime, $cour
 
     if (!empty($records)) {
         foreach ($records as $record) {
-            if (empty($groupid) || ismember($groupid, $record->userid)) {
+            if (empty($groupid) || groups_is_member($groupid, $record->userid)) {
 
                 unset($activity);
 
index f2dff499b201835fb07bd24ccc9eab92e6d68928..a7a27eabbb9f623f586d7b662ea470fe5ab9983a 100644 (file)
         $grades = make_grades_menu($journal->assessed);
         $teachers = get_course_teachers($course->id);
 
-        $allowedtograde = ($groupmode != VISIBLEGROUPS or isteacheredit($course->id) or ismember($currentgroup));
+        $allowedtograde = ($groupmode != VISIBLEGROUPS or isteacheredit($course->id) or groups_is_member($currentgroup));
 
         if ($allowedtograde) {
             echo '<form action="report.php" method="post">';
         if ($usersdone = journal_get_users_done($journal)) {
             foreach ($usersdone as $user) {
                 if ($currentgroup) {
-                    if (!ismember($currentgroup, $user->id)) {    /// Yes, it's inefficient, but this module will die
+                    if (!groups_is_member($currentgroup, $user->id)) {    /// Yes, it's inefficient, but this module will die
                         continue;
                     }
                 }
index 5edc80ad23642074c56f6b7ffe8fcdb474159c7b..0f1d6e5d4b99edbbb616e08a1b1d87520abdd070 100644 (file)
@@ -26,7 +26,7 @@
     if (!has_capability('mod/survey:readresponses', $context)) {
         if ($type != "student.png" or $sid != $USER->id ) {
             error("Sorry, you aren't allowed to see this.");
-        } else if ($groupmode and !ismember($group)) {
+        } else if ($groupmode and !groups_is_member($group)) {
             error("Sorry, you aren't allowed to see this.");
         }
     }
index 251970565252fd449cd9004cfff77bfd84217774..e8b12e2d294c88ec5987d1a1b56b641bbba27677 100644 (file)
@@ -403,7 +403,7 @@ function wiki_get_default_entry(&$wiki, &$course, $userid=0, $groupid=0) {
             $groupid=$mygroupids[0];
         } else {
             // Whatever groups are in the course, pick one
-            $coursegroups = get_groups($course->id);
+            $coursegroups = groups_get_all_groups($course->id);
             if(!$coursegroups || count($coursegroups)==0) {
                 error("Can't access wiki in group mode when no groups are configured for the course");
             }
@@ -459,7 +459,7 @@ function wiki_get_entry(&$wiki, &$course, $userid=0, $groupid=0) {
                     $groupid=$mygroupids[0];
                 } else {
                     // Whatever groups are in the course, pick one
-                    $coursegroups = get_groups($course->id);
+                    $coursegroups = groups_get_all_groups($course->id);
                     if(!$coursegroups || count($coursegroups)==0) {
                         error("Can't access wiki in group mode when no groups are configured for the course");
                     }
@@ -635,7 +635,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
                 $wiki_entries = get_records_sql($sql);
                 $wiki_entries=is_array($wiki_entries)?$wiki_entries:array();
                 foreach ($wiki_entries as $wiki_entry) {
-                    if (($viewall === true) or ismember($viewall, $wiki_entry->userid)) {
+                    if (($viewall === true) or groups_is_member($viewall, $wiki_entry->userid)) {
                         $key = 'view.php?id='.$id.'&userid='.$wiki_entry->userid.'&page='.$wiki_entry->pagename;
                         $wikis[$key] = fullname($wiki_entry).':'.$wiki_entry->pagename;
                         if ($currentid == $wiki_entry->id) {
@@ -657,7 +657,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
         $wiki_entries = wiki_get_entries($wiki, 'group');
 
         if ($groupmode and ($isteacheredit or ($isteacher and !$mygroupid))) {
-            if ($groups = get_groups($course->id)) {
+            if ($groups = groups_get_all_groups($course->id)) {
                 $defpagename = empty($wiki->pagename) ? get_string('wikidefaultpagename', 'wiki') : $wiki->pagename;
                 foreach ($groups as $group) {
 
@@ -676,7 +676,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
         }
         //if a studnet with multiple groups in SPG
         else if ($groupmode == SEPARATEGROUPS){
-            if ($groups = get_groups($course->id, $user->id)){
+            if ($groups = groups_get_all_groups($course->id, $user->id)){
 
                 $defpagename = empty($wiki->pagename) ? get_string('wikidefaultpagename', 'wiki') : $wiki->pagename;
                 foreach ($groups as $group) {
@@ -717,7 +717,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
             /// If the user is an editing teacher, or a non-editing teacher not assigned to a group, show all
             /// teacher wikis, regardless of creation.
             if ($groupmode and ($isteacheredit or ($isteacher and !$mygroupid))) {
-                if ($groups = get_groups($course->id)) {
+                if ($groups = groups_get_all_groups($course->id)) {
                     $defpagename = empty($wiki->pagename) ? get_string('wikidefaultpagename', 'wiki') : $wiki->pagename;
 
                     foreach ($groups as $group) {
@@ -876,7 +876,7 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) {
 ///     create any student wiki in their group.
         else {
             return ((($userid == $user->id) and wiki_is_student($wiki, $user->id)) or wiki_is_teacheredit($wiki) or
-                    (wiki_is_teacher($wiki) and (!$groupmode or $mygroupid == 0 or (ismember($mygroupid, $userid)))));
+                    (wiki_is_teacher($wiki) and (!$groupmode or $mygroupid == 0 or (groups_is_member($mygroupid, $userid)))));
         }
         break;
 
@@ -944,14 +944,14 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) {
         case 'student':
             $can_edit = (($user->id == $wiki_entry->userid) or
                          ($groupmode and wiki_is_teacher($wiki, $user->id) and
-                          ismember($mygroupid, $wiki_entry->userid)));
+                          groups_is_member($mygroupid, $wiki_entry->userid)));
             break;
 
         case 'group':
             /// If there is a groupmode, determine the user's group status.
             if ($groupmode) {
                 /// If the user is a member of the wiki group, they can edit the wiki.
-                $can_edit = ismember($wiki_entry->groupid, $user->id);
+                $can_edit = groups_is_member($wiki_entry->groupid, $user->id);
             }
             /// If mode is 'nogroups', then all participants can edit the wiki.
             else {
@@ -963,7 +963,7 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) {
             /// If there is a groupmode, determine the user's group status.
             if ($groupmode) {
                 /// If the user is a member of the wiki group, they can edit the wiki.
-                $can_edit = (wiki_is_teacher($wiki, $user->id) and ismember($wiki_entry->groupid, $user->id));
+                $can_edit = (wiki_is_teacher($wiki, $user->id) and groups_is_member($wiki_entry->groupid, $user->id));
             }
             else {
                 $can_edit = wiki_is_teacher($wiki, $user->id);
@@ -993,7 +993,7 @@ function wiki_user_can_access_student_wiki(&$wiki, $userid, &$course) {
     ///     - they are a non-editing teacher and group mode is NOGROUPS.
     ///     - they are an administrator (mostly for site-level wikis).
     if (($userid and ($USER->id == $userid)) or ($groupmode == VISIBLEGROUPS) or
-        (($groupmode == SEPARATEGROUPS) and ismember($usersgroup, $userid)) or
+        (($groupmode == SEPARATEGROUPS) and groups_is_member($usersgroup, $userid)) or
         (wiki_is_teacheredit($wiki, $USER->id)) or
         (wiki_is_teacher($wiki, $USER->id) and (!$usersgroup or $groupmode == NOGROUPS))) {
         $can_access = true;
index 69d42f4be7d175bb6f88b3cbad199d7e3677786a..2670ff6d799022a54b7387888fd081c98d56f239 100644 (file)
@@ -1141,7 +1141,7 @@ function workshop_get_recent_mod_activity(&$activities, &$index, $sincetime, $co
 
     foreach ($posts as $post) {
 
-        if (empty($groupid) || ismember($groupid, $post->userid)) {
+        if (empty($groupid) || groups_is_member($groupid, $post->userid)) {
 
             $tmpactivity = new Object;
 
index 39f7ebec1135d06bb6f2547c56a3dca43fc59c0a..acc3c7cdab2a550e0c4493e8391c468de6823a4c 100644 (file)
@@ -332,7 +332,7 @@ function workshop_count_student_submissions_for_assessment($workshop, $user) {
             // check group membership, if necessary
             if ($groupid) {
                 // check user's group
-                if (!ismember($groupid, $submission->userid)) {
+                if (!groups_is_member($groupid, $submission->userid)) {
                     continue; // skip this user
                 }
             }
@@ -1217,7 +1217,7 @@ function workshop_list_student_submissions($workshop, $user) {
                 // check group membership, if necessary
                 if ($groupid) {
                     // check user's group
-                    if (!ismember($groupid, $submission->userid)) {
+                    if (!groups_is_member($groupid, $submission->userid)) {
                         continue; // skip this submission
                   }
                 }
@@ -1393,7 +1393,7 @@ function workshop_list_submissions_for_admin($workshop, $order) {
             // check group membership, if necessary
             if ($groupid) {
                 // check user's group
-                if (!ismember($groupid, $user->id)) {
+                if (!groups_is_member($groupid, $user->id)) {
                     continue; // skip this user
                 }
             }
@@ -1502,7 +1502,7 @@ function workshop_list_submissions_for_admin($workshop, $order) {
             // check group membership, if necessary
             if ($groupid) {
                 // check user's group
-                if (!ismember($groupid, $user->id)) {
+                if (!groups_is_member($groupid, $user->id)) {
                     continue; // skip this user
                 }
             }
@@ -1737,7 +1737,7 @@ function workshop_list_unassessed_student_submissions($workshop, $user) {
             // check group membership, if necessary
             if ($groupid) {
                 // check user's group
-                if (!ismember($groupid, $submission->userid)) {
+                if (!groups_is_member($groupid, $submission->userid)) {
                     continue; // skip this user
                 }
             }
@@ -2805,7 +2805,7 @@ function workshop_print_league_table($workshop) {
         foreach ($submissions as $submission) {
             if ($groupid) {
                 // check submission's group
-                if (!ismember($groupid, $submission->userid)) {
+                if (!groups_is_member($groupid, $submission->userid)) {
                     continue; // skip this submission
                 }
             }
index fa31516b6fdc93255a7b44468bbc0be201cae1aa..843fdce58f3557570476a09f57ac61474ed96df5 100644 (file)
         foreach ($users as $user) {
             // skip if student not in group
             if ($currentgroup) {
-                if (!ismember($currentgroup, $user->id)) {
+                if (!groups_is_member($currentgroup, $user->id)) {
                     continue;
                 }
             }
index f3196d7da02a1edf972d328e0c2fc2576fe9b032..6492c2c8952f6de36501d14b535bd38ae03e9426 100644 (file)
@@ -249,7 +249,7 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
     //group consistency check : checks the following situations about groups
     // trap if user is not same group and groups are separated
     $current_group = get_current_group($course->id);
-    if ((groupmode($course) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $module_context)) return false;
+    if ((groupmode($course) == SEPARATEGROUPS) && !groups_is_member($group_id) && !has_capability('moodle/site:accessallgroups', $module_context)) return false;
 
     //ownership check : checks the following situations about user
     // trap if user is not owner and has cannot see other's entries
index afb52901fef9470e758b5fdf96fc52e8a056d035..c8995279c919592abbe87500c7be099bc790377c 100644 (file)
@@ -336,7 +336,7 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
     //group consistency check : checks the following situations about groups
     // trap if user is not same group and groups are separated
     $current_group = get_current_group($course->id);
-    if ((groupmode($course) == SEPARATEGROUPS) && !ismember($group_id) && !has_capability('moodle/site:accessallgroups', $module_context)) return false;
+    if ((groupmode($course) == SEPARATEGROUPS) && !groups_is_member($group_id) && !has_capability('moodle/site:accessallgroups', $module_context)) return false;
 
     //ownership check : checks the following situations about user
     // trap if user is not owner and has cannot see other's entries
index 9b3610f733c9dca7acf705470b4f7b51e6b9c341..a9dfe031c1257c293d84afe36cf823f6ae7716df 100644 (file)
             /*TODO: $gtrue = false;
             if ($mygroups = mygroupid($course->id)){
                 foreach ($mygroups as $group){
-                    if (ismember($group, $user->id)){
+                    if (groups_is_member($group, $user->id)){
                         $gtrue = true;
                     }
                 }
     $isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
                              !has_capability('moodle/site:accessallgroups', $coursecontext));
     if (!$isseparategroups){
-        if ($usergroups = user_group($course->id, $user->id)){
+        if ($usergroups = groups_get_all_groups($course->id, $user->id)){
             $groupstr = '';
             foreach ($usergroups as $group){
                 $groupstr .= ' <a href="'.$CFG->wwwroot.'/user/index.php?id='.$course->id.'&amp;group='.$group->id.'">'.$group->name.'</a>,';