You are here

function notifications_load_subscription in Notifications 5

Same name and namespace in other branches
  1. 6.4 notifications.module \notifications_load_subscription()
  2. 6 notifications.module \notifications_load_subscription()
  3. 6.2 notifications.module \notifications_load_subscription()
  4. 6.3 notifications.module \notifications_load_subscription()

Get an individual subscription.

Parameters

$subs: Either a subscription object or a subscription id (sid).

$refresh: Force cache refresh

Return value

Subscriptions object.

6 calls to notifications_load_subscription()
Notifications_API_Tests::testNotificationsBasicAPI in tests/notifications_api.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_get_subscriptions in ./notifications.module
Get subscriptions that fit a set of conditions.
notifications_page_unsubscribe in ./notifications.admin.inc
Menu callback add subscription
notifications_process_digest_long in ./notifications.cron.inc
Digest multiple events in a single message, long format.
notifications_process_digest_short in ./notifications.cron.inc
Digest multiple events in a single message, short format.

... See full list

File

./notifications.module, line 503
Notifications module

Code

function notifications_load_subscription($subs, $refresh = FALSE) {
  static $cache = array();
  if (is_object($subs)) {
    $sid = $subs->sid;
    $subscription = $subs;
  }
  else {
    $sid = $subs;
  }
  if ($refresh || !array_key_exists($sid, $cache)) {
    if (!isset($subscription)) {
      $subscription = db_fetch_object(db_query("SELECT * FROM {notifications} WHERE sid = %d", $sid));
    }
    if ($subscription) {
      $subscription->fields = array();
      $result = db_query("SELECT * FROM {notifications_fields} WHERE sid = %d", $sid);
      while ($condition = db_fetch_object($result)) {
        $subscription->fields[$condition->field] = $condition->value;
      }
    }
    $cache[$sid] = $subscription;
  }
  return $cache[$sid];
}