You are here

function notifications_user_get_subscriptions in Notifications 6.2

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

Get subscription for a given user

Parameters

$uid: User id

$event_type: Event type

$oid: Object id for caching. I.e. for a node it will be nid

$object: Object to check subscriptions to. I.e. $node

Return value

Array of subscriptions for this user and object indexed by sid

2 calls to notifications_user_get_subscriptions()
NotificationsContentTests::testNotificationsContent in tests/notifications_content.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_autosubscribe in notifications_autosubscribe/notifications_autosubscribe.module
Subscribes users to content they post, if not already subscribed

File

./notifications.module, line 652
Notifications module

Code

function notifications_user_get_subscriptions($uid, $event_type, $oid, $object = NULL, $refresh = FALSE) {
  static $subscriptions;
  if ($refresh || !isset($subscriptions[$uid][$event_type][$oid])) {
    $subscriptions[$uid][$event_type][$oid] = array();
    $query_args = notifications_module_information('query', 'user', $event_type, $object);

    // Base query
    $query = array(
      'select' => array(
        's.*',
        'f.*',
      ),
      'from' => array(
        '{notifications} s',
      ),
      'join' => array(
        'INNER JOIN {notifications_fields} f ON s.sid = f.sid',
      ),
      'where' => array(
        's.uid = %d',
        "s.event_type = '%s'",
      ),
      'where args' => array(
        $uid,
        $event_type,
      ),
    );
    foreach ($query_args as $query_params) {
      $query = notifications_query_build($query_params, $query);
    }

    // Build the query merging all the parts
    list($sql, $args) = notifications_query_sql($query);
    $result = db_query($sql, $args);
    while ($sub = db_fetch_object($result)) {
      if (!isset($subscriptions[$uid][$event_type][$oid][$sub->sid])) {
        $subscriptions[$uid][$event_type][$oid][$sub->sid] = $sub;
      }
      $subscriptions[$uid][$event_type][$oid][$sub->sid]->fields[$sub->field] = $sub->value;
    }
  }
  return $subscriptions[$uid][$event_type][$oid];
}