public function buildQuery($overrideLimits = false)
{
// Get a "select all" query
$db = $this->getDbo();
$query = $db->getQuery(true)->select('*')->from($this->getTableName());
// Run the "before build query" hook and behaviours
$this->triggerEvent('onBeforeBuildQuery', array(&$query, $overrideLimits));
// Apply custom WHERE clauses
if (count($this->whereClauses)) {
foreach ($this->whereClauses as $clause) {
$query->where($clause);
}
}
$order = $this->getState('filter_order', null, 'cmd');
if (!array_key_exists($order, $this->knownFields)) {
$order = $this->getIdFieldName();
$this->setState('filter_order', $order);
}
$order = $db->qn($order);
$dir = strtoupper($this->getState('filter_order_Dir', null, 'cmd'));
if (!in_array($dir, array('ASC', 'DESC'))) {
$dir = 'ASC';
$this->setState('filter_order_Dir', $dir);
}
$query->order($order . ' ' . $dir);
// Run the "before after query" hook and behaviours
$this->triggerEvent('onAfterBuildQuery', array(&$query, $overrideLimits));
return $query;
}