You are here

function views_content_cache_query_builder in Views content cache 6.2

Same name and namespace in other branches
  1. 7.3 views_content_cache.module \views_content_cache_query_builder()

A simple SQL where clause builder.

This function will recursively build a WHERE clause.

Return value

An array with two keyed, values:

  • 'clause' - containing the meat of a WHERE clause.
  • 'args' - An array of arguments for the db_query call.
2 calls to views_content_cache_query_builder()
ViewsContentCacheUnitTest::testQueryBuilder in tests/views_content_cache.test
views_content_cache_update_get in ./views_content_cache.module
Retrieve the latest update record for a given cache id.

File

./views_content_cache.module, line 384
Views content cache cache.

Code

function views_content_cache_query_builder($query_array) {

  // Arrays of clauses and args:
  $clauses = array();
  $args = array();

  // First flatten this array:
  foreach (element_children($query_array) as $key) {
    if (is_array($query_array[$key]) && isset($query_array[$key]['#glue'])) {
      $query_array[$key] = views_content_cache_query_builder($query_array[$key]);
    }
    if (isset($query_array[$key]['#clause'])) {
      $clauses[] = $query_array[$key]['#clause'];
      if (is_array($query_array[$key]['#args'])) {
        $args = array_merge($args, $query_array[$key]['#args']);
      }
    }
  }
  $glue = isset($query_array['#glue']) ? $query_array['#glue'] : 'AND';

  // If we are ORing, we need to add some brackets
  return array(
    '#clause' => '(' . implode(" {$glue} ", $clauses) . ')',
    '#args' => $args,
  );
}