/**
* Set the ORDER BY value
*
* @param mixed $by
* @param string $order
* @return AbstractSql
*/
public function orderBy($by, $order = 'ASC')
{
$byColumns = null;
if (is_array($by)) {
$quotedAry = [];
foreach ($by as $value) {
$quotedAry[] = $this->sql->quoteId(trim($value));
}
$byColumns = implode(', ', $quotedAry);
} else {
if (strpos($by, ',') !== false) {
$ary = explode(',', $by);
$quotedAry = [];
foreach ($ary as $value) {
$quotedAry[] = $this->sql->quoteId(trim($value));
}
$byColumns = implode(', ', $quotedAry);
} else {
$byColumns = $this->sql->quoteId(trim($by));
}
}
$this->orderBy .= (null !== $this->orderBy ? ', ' : '') . $byColumns;
$order = strtoupper($order);
if (strpos($order, 'RAND') !== false) {
$this->orderBy = $this->sql->getDbType() == \Pop\Db\Sql::SQLITE ? ' RANDOM()' : ' RAND()';
} else {
if ($order == 'ASC' || $order == 'DESC') {
$this->orderBy .= ' ' . $order;
}
}
return $this;
}