function redhen_org_group_contact_groups in RedHen CRM 7
Return all redhen_org groups that a given user belongs to.
Parameters
object $account: User object
bool $private: Optionally limit to private groups.
string $bundle: Optionally limit to groups that accept posts of a given bundle.
bool $active: Optionally limit to groups user has active relation with.
Return value
array An array of redhen_orgs keyed by organization id.
3 calls to redhen_org_group_contact_groups()
- RedhenGroupSelectionHandler::getContactGroups in modules/
redhen_org_group/ plugins/ selection/ RedhenGroupSelectionHandler.class.php - Return all redhen_org groups that a given user belongs to.
- redhen_org_group_content_access in modules/
redhen_org_group/ redhen_org_group.module - Access callback for the group content page.
- redhen_org_group_node_grants in modules/
redhen_org_group/ redhen_org_group.module - Implements hook_node_grants().
File
- modules/
redhen_org_group/ redhen_org_group.module, line 214
Code
function redhen_org_group_contact_groups($account, $private = FALSE, $bundle = NULL, $active = TRUE) {
$account_groups = drupal_static(__FUNCTION__ . $account->uid . $private . $bundle . $active, array());
if (!empty($account_groups)) {
return $account_groups;
}
// Get all orgs the given account is connected to.
$group_types = array_keys(redhen_org_group_group_types($private, $bundle));
// There are no group types, so the contact is obviously not in an org group.
if (empty($group_types)) {
return array();
}
if ($contact = redhen_contact_user_contact($account)) {
$relations = redhen_relation_relations($contact, REDHEN_RELATION_AFFILIATION, $active);
foreach ($relations as $relation_id => $orgs) {
foreach ($orgs as $org) {
if (in_array($org->type, $group_types)) {
$account_groups[$org->org_id] = $org;
}
}
}
}
if ($account->uid > 0) {
// If not anonymous, get all groups.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'redhen_org')
->entityCondition('bundle', $group_types, 'IN')
->propertyCondition('redhen_state', REDHEN_STATE_ACTIVE);
if (!user_access('access all redhen org groups', $account)) {
// If user doesn't have permission to all groups, just get authored groups.
$query
->propertyCondition('author_uid', $account->uid);
}
$result = $query
->execute();
if ($result) {
$orgs = redhen_org_load_multiple(array_keys($result['redhen_org']));
foreach ($orgs as $org) {
$account_groups[$org->org_id] = $org;
}
}
}
return $account_groups;
}