function gnode_group_node_create_gids in Group 7
Retrieve all group ids a user can create a node of a given type in.
Parameters
string $type: The node type the user is attempting to create.
object $account: (optional) The account of the user.
Return value
array An array of group ids (gids).
1 call to gnode_group_node_create_gids()
- gnode_form_node_form_alter in modules/
gnode/ gnode.module - Implements hook_form_BASE_FORM_ID_alter().
File
- modules/
gnode/ gnode.module, line 87 - Contains Group's implementation of the Node module hooks and forms.
Code
function gnode_group_node_create_gids($type, $account = NULL) {
global $user;
if (!isset($account)) {
$account = $user;
}
// Determine whether the account could be 'anonymous' or 'outsider'.
$account_exists = (bool) $account->uid;
// If the user can bypass group access, return all group ids.
if (user_access('bypass group access', $account)) {
return db_select('groups', 'g')
->fields('g')
->execute()
->fetchCol();
}
// Otherwise, start gathering group ids.
$gids = array();
// Check for all group types if a non-member can create nodes of the given
// node type in them.
foreach (group_types() as $group_type) {
// Retrieve the permissions to check for creation rights.
$check_permissions = $account_exists ? $group_type->outsider_permissions : $group_type->anonymous_permissions;
$has_access = in_array('administer group', $check_permissions);
$has_access = $has_access || in_array("create {$type} node", $check_permissions);
// If the group type allows access to non-members, we add all of the groups
// the user is not a member of. This would be all groups in case we are
// checking for an anonymous user.
if ($has_access) {
$gids = array_merge($gids, group_non_member_gids($account->uid, $group_type->name));
}
}
// Add all of the user's groups in which he has creation rights.
foreach (group_load_by_member($account->uid) as $group) {
$has_access = group_access('administer group', $group, $account);
$has_access = $has_access || group_access("create {$type} node", $group, $account);
if ($has_access) {
$gids[] = $group->gid;
}
}
$gids = array_unique($gids);
sort($gids);
return $gids;
}