You are here

function notifications_query_build in Notifications 5

Same name and namespace in other branches
  1. 6.4 includes/query.inc \notifications_query_build()
  2. 6 notifications.module \notifications_query_build()
  3. 6.2 notifications.module \notifications_query_build()
  4. 6.3 notifications.module \notifications_query_build()

Query builder for subscriptions

Parameters

$params: Array of query conditions

3 calls to notifications_query_build()
Notifications_API_Tests::testNotificationsBasicAPI in tests/notifications_api.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_queue in ./notifications.module
Queue events for notifications
notifications_user_get_subscriptions in ./notifications.module
Get subscription for a given user

File

./notifications.module, line 343
Notifications module

Code

function notifications_query_build($params, $base = array()) {
  $query = $base + array(
    'select' => array(),
    'join' => array(),
    'where' => array(),
    'args' => array(),
  );
  foreach ($params as $name => $elements) {
    if ($name == 'fields') {
      foreach ($elements as $field => $value) {

        // Handle array values with IN conditions
        if (is_array($value)) {
          $placeholders = array_fill(0, count($value), "'%s'");
          $query['where'][] = "f.field = '%s' AND f.value IN (" . implode(', ', $placeholders) . ")";
          $query['args'][] = $field;
          $query['args'] = array_merge($query['args'], $value);
        }
        else {
          $query['where'][] = "f.field = '%s' AND f.value = '%s'";
          $query['args'][] = $field;
          $query['args'][] = $value;
        }
      }
    }
    elseif (is_array($elements)) {
      $query[$name] = array_merge($query[$name], $elements);
    }
    else {
      $query[$name][] = $elements;
    }
  }
  return $query;
}