MDL-10383 - deprecated get_groups(), user_group() and ismember()
This commit is contained in:
@@ -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])) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -452,9 +452,9 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+34
-2
@@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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
|
||||
|
||||
+5
-62
@@ -16,56 +16,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
+6
-6
@@ -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);
|
||||
|
||||
@@ -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 /////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
+41
-1
@@ -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);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
$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;
|
||||
}
|
||||
@@ -190,7 +190,7 @@
|
||||
$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;
|
||||
}
|
||||
@@ -243,7 +243,7 @@
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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 ' ';
|
||||
@@ -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){
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,12 +157,12 @@
|
||||
|
||||
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;
|
||||
@@ -174,7 +174,7 @@
|
||||
|
||||
} 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
|
||||
|
||||
+7
-7
@@ -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 .= ' ';
|
||||
@@ -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 ' ';
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@
|
||||
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');
|
||||
}
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
$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">';
|
||||
@@ -120,7 +120,7 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-2
@@ -110,7 +110,7 @@
|
||||
/*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;
|
||||
}
|
||||
}
|
||||
@@ -368,7 +368,7 @@
|
||||
$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.'&group='.$group->id.'">'.$group->name.'</a>,';
|
||||
|
||||
Reference in New Issue
Block a user