You are here

function notifications_object_user_subscriptions in Notifications 6.4

Get list of possible and existing subscriptions for user/object

Parameters

$type: Subscription type to get options: 'user', 'node'

$object: The object to subscribe. It may be $node or $user

$account: User account to get options/subscriptions for

Return value

Array of subscription options The enabled ones will have a 'subscriptions' element loaded

3 calls to notifications_object_user_subscriptions()
notifications_object_page_subscriptions in includes/object.inc
Build subscriptions for current user to an array of objects
notifications_object_subscribe_links in includes/object.inc
Build subscribe / unsubscribe options for object
notifications_ui_object_subscriptions in notifications_ui/notifications_ui.module
Get list of possible and existing subscriptions for user/object

File

includes/object.inc, line 137
Notifications object and fields

Code

function notifications_object_user_subscriptions($type, $object, $account = NULL) {
  $cache =& messaging_static(__FUNCTION__);
  $account = $account ? $account : $GLOBALS['user'];
  $object = notifications_object_load($type, $object);

  // Get allowed subscription options for this account to this object
  $subscribe_options = notifications_object_subscribe_options($type, $object, $account);
  $allowed_options = array();
  foreach ($subscribe_options as $option) {

    // So far this is not a subscription but a subscription template
    $subscription = notifications_build_subscription($option);
    $type_key = $subscription
      ->serialize_type();

    // If we have this type cached we don't search more
    if (!isset($cache[$account->uid][$type_key])) {
      if (notifications_user_allowed_subscription($account, $subscription)) {
        $subscription
          ->set_account($account);

        // If anonymous user we don't search more because we cannot find by uid
        if ($account->uid) {
          $find = notifications_get_subscriptions(array(
            'uid' => $account->uid,
            'type' => $subscription->type,
          ), $subscription
            ->get_conditions());

          // Allowed subscription type, we store the subscription or the template
          if ($find) {
            $usersubs = current($find);
            $usersubs->name = $subscription->name;
            $subscription = $usersubs;
          }
        }
        $cache[$account->uid][$type_key] = $subscription;
      }
      else {

        // Not allowed subscription type for this user
        $cache[$account->uid][$type_key] = FALSE;
      }
    }
    if ($cache[$account->uid][$type_key]) {
      $allowed_options[] = $cache[$account->uid][$type_key];
    }
  }
  return $allowed_options;
}