You are here

function notifications_get_subscriptions in Notifications 5

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

Get subscriptions that fit a set of conditions.

Parameters

$params: Array of parameters for the query

$conditions: Optional array of condition fields

$limit: Whether to limit the result to subscriptions with exatly that condition fields

$key: Optional key field to use as the array index. Will default to sid

Return value

Array of subscriptions indexed by uid, module, field, value, author

6 calls to notifications_get_subscriptions()
Notifications_API_Tests::testNotificationsBasicAPI in tests/notifications_api.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_content_page_author in notifications_content/notifications_content.module
User subscriptions to content types
notifications_content_page_nodetype in notifications_content/notifications_content.module
User subscriptions to content types
notifications_save_subscription in ./notifications.module
Update or create subscription
notifications_tags_user_form in notifications_tags/notifications_tags.module
Returns the taxonomy subscription form

... See full list

File

./notifications.module, line 600
Notifications module

Code

function notifications_get_subscriptions($params, $conditions = array(), $limit = TRUE, $key = 'sid', $pager = NULL) {

  // Build query
  $join = $where = array();
  if ($conditions) {
    if ($limit) {
      $params += array(
        'conditions' => count($conditions),
      );
    }
    $index = 0;
    foreach ($conditions as $name => $value) {
      $alias = "f{$index}";
      $join[] = "INNER JOIN {notifications_fields} {$alias} ON s.sid = {$alias}.sid ";
      $params["{$alias}.field"] = $name;
      if (!is_null($value)) {
        $params["{$alias}.value"] = $value;
      }
      $index++;
    }
  }
  foreach ($params as $field => $value) {
    $name = strstr($field, '.') ? $field : 's.' . $field;
    $where[] = is_numeric($value) && strstr($field, 's.') ? $name . ' = %d' : "{$name} = '%s'";
  }
  $sql = 'SELECT * FROM {notifications} s ' . implode(' ', $join) . ' WHERE ' . implode(' AND ', $where);
  if ($pager) {
    $sql .= ' ORDER BY s.sid';
    $result = pager_query($sql, $pager, 0, NULL, $params);
  }
  else {
    $result = db_query($sql, $params);
  }
  $subscriptions = array();
  while ($s = db_fetch_object($result)) {
    $subscriptions[$s->{$key}] = notifications_load_subscription($s);
  }
  return $subscriptions;
}