Pop\Db\Sql\AbstractSql::orderBy PHP Метод

orderBy() публичный Метод

Set the ORDER BY value
public orderBy ( mixed $by, string $order = 'ASC' ) : AbstractSql
$by mixed
$order string
Результат AbstractSql
    public function orderBy($by, $order = 'ASC')
    {
        $byColumns = null;
        if (is_array($by)) {
            $quotedAry = array();
            foreach ($by as $value) {
                $quotedAry[] = $this->sql->quoteId(trim($value));
            }
            $byColumns = implode(', ', $quotedAry);
        } else {
            if (strpos($by, ',') !== false) {
                $ary = explode(',', $by);
                $quotedAry = array();
                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;
    }