function simple_access_group_select in Simple Access 7.2
Same name and namespace in other branches
- 8.3 simple_access.module \simple_access_group_select()
- 5.2 simple_access.module \simple_access_group_select()
- 5 simple_access.module \simple_access_group_select()
- 6.2 simple_access.module \simple_access_group_select()
Return groups for which user is a member.
5 calls to simple_access_group_select()
- simple_access_form in ./
simple_access.module - Simple Access form.
- simple_access_group_grant_form in ./
simple_access.module - Configure grant group permissions.
- simple_access_group_revoke_form in ./
simple_access.module - Configure revoke group permissions.
- simple_access_profile_form in ./
simple_access.admin.inc - Simple Access profile form.
- _simple_access_filter_access in ./
simple_access.module - Filter the access records for the current user.
File
- ./
simple_access.module, line 677 - This module allows administrators to make nodes viewable by specific 'access groups'. Each access group can contain any number of roles. If a node is not assigned to any access groups, it will remain viewable by all users.
Code
function simple_access_group_select() {
$groups =& drupal_static(__FUNCTION__);
if (empty($groups)) {
global $user;
$default_access = user_access('administer nodes') || variable_get('simple_access_showgroups', FALSE);
$groups = array();
$result = db_select('simple_access_groups', 'g')
->fields('g', array(
'gid',
'name',
))
->orderBy('weight')
->orderBy('name')
->execute();
while ($group = $result
->fetchAssoc(PDO::FETCH_ASSOC)) {
$groups[$group['gid']] = $group;
$groups[$group['gid']]['access'] = $default_access;
}
if (!$default_access) {
// Return just groups for which user is a member.
$roles = array_keys($user->roles);
$query = db_select('simple_access_groups', 'g')
->fields('g', array(
'gid',
))
->condition('rid', $roles, 'IN')
->groupBy('gid');
$query
->innerJoin('simple_access_roles', 'r', 'g.gid = r.gid');
$result = $query
->execute();
while ($group = $result
->fetchAssoc(PDO::FETCH_ASSOC)) {
$groups[$group['gid']]['access'] = TRUE;
}
}
}
return $groups;
}