You are here

function og_get_subscriptions in Organic groups 6

Same name and namespace in other branches
  1. 5.8 og.module \og_get_subscriptions()
  2. 5 og.module \og_get_subscriptions()
  3. 5.2 og.module \og_get_subscriptions()
  4. 5.3 og.module \og_get_subscriptions()
  5. 5.7 og.module \og_get_subscriptions()
  6. 6.2 og.module \og_get_subscriptions()

Load all memberships for a given user.

Since a user's memberships are loaded into $user object, this function is only occasionally useful to get group memberships for users other than the current user. Even then, it often makes sense to call user_load() instead of this function.

Return value

array

9 calls to og_get_subscriptions()
OgSubscribe::testWebUserSubscribeOg in tests/og.subscribe.test
Test a web user subscribing and unsubscribing a group.
og_access_alter_nongroup_form in modules/og_access/og_access.module
og_access_node_grants in modules/og_access/og_access.module
Implementation of hook_node_grants().
og_confirm_unsubscribe_submit in ./og.module
Confirm og unsubscription submit handler
og_form_add_og_audience in ./og.module
Helper method to add OG audience fields to a given form. This is lives in a separate function from og_form_alter() so it can be shared by other OG contrib modules.

... See full list

File

./og.module, line 1120

Code

function og_get_subscriptions($uid, $min_is_active = 1, $reset = FALSE) {
  static $subscriptions = array();
  if ($reset) {
    unset($subscriptions[$uid]);
  }
  if (!isset($subscriptions[$uid][$min_is_active])) {
    list($types, $in) = og_get_sql_args();
    array_unshift($types, $min_is_active);
    array_unshift($types, $uid);
    $sql = "SELECT n.title, n.type, n.status, ou.* FROM {og_uid} ou INNER JOIN {node} n ON ou.nid = n.nid WHERE ou.uid = %d AND ou.is_active >= %d AND n.type {$in} ORDER BY n.title";
    $result = db_query($sql, $types);
    while ($row = db_fetch_array($result)) {
      $subscriptions[$uid][$min_is_active][$row['nid']] = $row;
    }
    if (!isset($subscriptions[$uid][$min_is_active])) {
      $subscriptions[$uid][$min_is_active] = array();
    }
  }
  return $subscriptions[$uid][$min_is_active];
}