You are here

public static function GroupMembership::getByActiveStatus in Group 7

Get all active memberships for a user.

Parameters

int $uid: The uid of the user to retrieve memberships for.

bool $active: (optional) Whether to return active or inactive memberships. Defaults to TRUE.

Return value

array An array of GroupMembership objects.

2 calls to GroupMembership::getByActiveStatus()
gnode_node_grants in modules/gnode/gnode.node_access.inc
Implements hook_node_grants().
group_user_page in pages/group.user.inc
Generate the group info page for a given user.

File

classes/group_membership.inc, line 189
Defines the Entity API class for group memberships.

Class

GroupMembership
Main class for group memberships.

Code

public static function getByActiveStatus($uid, $active = TRUE) {

  // Gather all statuses that match $active.
  foreach (group_membership_status_info() as $status => $info) {
    if ($info['active'] === $active) {
      $statuses[] = $status;
    }
  }

  // Only query the database if there are statuses to search for.
  if (!empty($statuses)) {
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'group_membership');
    $query
      ->propertyCondition('uid', $uid);
    $query
      ->propertyCondition('status', $statuses, 'IN');
    $result = $query
      ->execute();
    if (isset($result['group_membership'])) {
      return group_membership_load_multiple(array_keys($result['group_membership']));
    }
  }
  return array();
}