function quant_node_query in Quant 7
Same name and namespace in other branches
- 6 includes/quants.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 ./
quant.quant.inc - Implements hook_quants().
File
- ./
quant.quant.inc, line 307 - Quant hook implementations.
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')) {
foreach (node_type_get_types() as $type => $node) {
if (og_is_group_type('node', $type)) {
$omit[] = $type;
}
}
}
$query = "SELECT " . implode(', ', $additional_fields) . " FROM {node}";
if ($custom) {
$query .= " WHERE created >= :period0 AND created <= :period1";
}
else {
$query .= " WHERE created >= :period";
}
if (count($omit)) {
$query .= " AND type NOT IN ('" . implode('\', \'', $omit) . "')";
}
$query .= " ORDER BY created DESC";
return $query;
}