function order_by($orderby, $direction = '')
{
if (strtolower($direction) == 'random') {
$orderby = '';
// Random results want or don't need a field name
$direction = $this->_random_keyword;
} elseif (trim($direction) != '') {
$direction = in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE) ? ' ' . $direction : ' ASC';
}
if (strpos($orderby, ',') !== FALSE) {
$temp = array();
foreach (explode(',', $orderby) as $part) {
$part = trim($part);
if (!in_array($part, $this->ar_aliased_tables)) {
$part = $this->_protect_identifiers(trim($part));
}
$temp[] = $part;
}
$orderby = implode(', ', $temp);
} else {
if ($direction != $this->_random_keyword) {
$orderby = $this->_protect_identifiers($orderby);
}
}
$orderby_statement = $orderby . $direction;
$this->ar_orderby[] = $orderby_statement;
if ($this->ar_caching === TRUE) {
$this->ar_cache_orderby[] = $orderby_statement;
$this->ar_cache_exists[] = 'orderby';
}
return $this;
}