You are here

function quant_node_query in Quant 6

Same name and namespace in other branches
  1. 7 quant.quant.inc \quant_node_query()

Build a node database query Avoid grabbing nodes that act as organic groups

Parameters

$additional_fields: An array of additional database fields to fetch other than 'created'

$custom: Boolean indication whether we should return a format for query or queryCustom. (See hook_quants() documentation)

Return value

A database query statement

1 call to quant_node_query()
_quant_quants in includes/quants.inc
Implementation of hook_quants()

File

includes/quants.inc, line 213
Provide our quant objects

Code

function quant_node_query($additional_fields = array(), $custom = FALSE) {
  $query = '';
  $omit = array();

  // Add required field to array
  $additional_fields[] = 'created';

  // Omit group nodes, if any
  if (module_exists('og')) {
    $types = db_query("SELECT type FROM {node_type}");
    while ($node = db_fetch_object($types)) {
      if (og_is_group_type($node->type)) {
        $omit[] = $node->type;
      }
    }
  }
  if (count($omit)) {
    $query = "SELECT " . implode(', ', $additional_fields) . " FROM {node} WHERE created >= %d" . ($custom ? " AND created <= %d " : " ") . "AND type NOT IN ('" . implode('\', \'', $omit) . "') ORDER BY created DESC";
  }
  else {
    $query = "SELECT " . implode(', ', $additional_fields) . " FROM {node} WHERE created >= %d" . ($custom ? " AND created <= %d " : " ") . "ORDER BY created DESC";
  }
  return $query;
}