lost password?

home
•  xaraya +
•  rails
•  django
•  webdev
•  xamp
•  musings

rss
Tag this page
   

» Blogs that link here
last modified: Feb 19, 2007
(first posted: Feb 07, 2007)
(1664 Reads)
keywords: roles
Permalink

How to query if a user is a member of a group?

Here's a little function I wrote to do it.

Drop this into modules/xarpages/xarcustomapi/ismember.php

<?php

/* ismember
* belongs in roles module
* returns true if user is a member of a group
* args:
* 'uid'        - default: current user OR
* 'uname'      - uname of user, alternative to uid
* 'gid'        - uid of the group OR
* 'group'      - name of group, alternative to gid
*/

function xarpages_customapi_ismember( $args )
{
	extract($args);

$roles = new xarRoles();

// get group object
	if (empty($gid) && empty($group)) return;
	if (empty($gid)) {
		$groupobj = $roles->findRole($group);
	}
	else {
		$groupobj = $roles->getRole($gid);
	}

// user
	if (empty($uid) && empty($uname)) {
		$uid = xarUserGetVar('uid');
	}
	// get user object
	if (empty($uid)) {
		$userobj = $roles->ufindRole($uname);
	}
	else {
		$userobj = $roles->getRole($uid);
	}

// test it
	return $userobj->isAncestor($groupobj);
}

?>
 

There are no comments attached to this item.

Post a new comment

How many days in a week?

Name :