Builds the `ORDER BY` clause.

@return string The `ORDER BY` clause.
336041
protected function _buildOrder($aliases = [])
    {
        $result = [];
        foreach ($this->_parts['order'] as $column => $dir) {
            $column = $this->dialect()->name($column, $aliases);
            $result[] = "{$column} {$dir}";
        }
        return $this->_buildClause('ORDER BY', join(', ', $result));
    }
690657
public function generate()
    {
        $result = '';

        $table  = $this->buildTable();
        $select = $this->buildSelectFields();
        $where  = $this->buildWhere();
        $having = $this->buildHaving();
        $join   = $this->buildJoin();
        $limit  = $this->buildLimit();
        $group  = $this->buildGroup();
        $union  = $this->buildUnion();
        $order  = $this->buildOrder();

        $result .= 'SELECT '.$select.' FROM '.$table;
        if ($join != '') {
            $result .= ' '.$join;
        }
        if ($where != '') {
            $result .= ' '.$where;
        }
        if ($group != '') {
            $result .= ' '.$group;
        }
        if ($order != '') {
            $result .= ' '.$order;
        }
        if ($limit != '') {
            $result .= ' '.$limit;
        }
        if ($having != '') {
            $result .= ' '.$having;
        }
        if ($union != '') {
            $result = '('.$result.')'.$union;
        }

        if ($this->isForUpdate()) {
            $result .= ' FOR UPDATE';
        }

        return $result;
    }
704008
protected function _buildSelect()
        {
            // If the query is raw, just set the $this->_values to be
            // the raw query parameters and return the raw query
            if ($this->_is_raw_query) {
                $this->_values = $this->_raw_parameters;
                return $this->_raw_query;
            }

            // Build and return the full SELECT statement by concatenating
            // the results of calling each separate builder method.
            return $this->_joinIfNotEmpty(
                " ",
                array(
                    $this->_buildSelectStart(),
                    $this->_buildJoin(),
                    $this->_buildWhere(),
                    $this->_buildGroupBy(),
                    $this->_buildHaving(),
                    $this->_buildOrderBy(),
                    $this->_buildLimit(),
                    $this->_buildOffset(),
                )
            );
        }
1180283
protected function build()
    {
        $sql = $this->start . "\n"
            . ($this->from    ? $this->from . "\n"    : null)
            . ($this->join    ? $this->join           : null)
            . ($this->set     ? $this->set . "\n"     : null)
            . ($this->where   ? $this->where . "\n"   : null)
            . ($this->groupby ? $this->groupby . "\n" : null)
            . ($this->orderby ? $this->orderby . "\n" : null)
            . ($this->limit   ? $this->limit . "\n"   : null)
            . ($this->offset  ? $this->offset . "\n"  : null)
            . ";";

        return $sql;
    }
995493
public function order()
    {
        $columns = func_get_args();
        $order = '';
        $i = 0;
        //
        if ($columns) {
            foreach ($columns as $value) {
                if (!$i) {
                    $order .= ' order by '.$value;
                } else {
                    $order .= ','.$value;
                }
                $i = 1;
            }
        }
        //
        $this->order = $order;
        //
        return $this;
    }
1335230
public function buildOrder()
	{
		$orders = [];

		foreach ($this->order as $order)
		{
			if (is_object($order['column']))
			{
				$string = $order['column']->build($this);
			}
			else
			{
				$string = $this->connection->quoteName($order['column']);
			}

			$string .= ' ' . strtoupper($order['dir']);
			$orders[] = $string;
		}

		return 'ORDER BY ' . implode(',', $orders);
	}
643698
public function getOrderBy()
    {
        $orderColumn = $this->getOrderColumn();

        if (is_array($orderColumn)) {
            // An order by raw statement
            return $orderColumn[0];
        }

        $selectedColumnNames = $this->getSelectColumns();

        if (! in_array($orderColumn, $selectedColumnNames)) {
            throw IncorrectOrderColumn::name($orderColumn);
        }

        $order = request('order');

        return [$orderColumn, $order[0]['dir']];
    }
154699
public function buildQuery()
    {
        $this->setSelectFrom();
        $this->setLeftJoins($this->qb);
        $this->setWhere($this->qb);
        $this->setWhereResultCallback($this->qb);
        $this->setWhereAllCallback($this->qb);
        $this->setOrderBy();
        $this->setLimit();

        return $this;
    }
697141
protected function buildQuery()
    {
        /** @var Search $search */
        $search = $this->repository->createSearch();
        $search->setSize($this->limit);
        $search->addSort(new Sort('left', Sort::ORDER_ASC));
        $search->addQuery(new TermQuery('active', true), 'must');
        if (!$this->loadHiddenCategories) {
            $search->addQuery(new TermQuery('is_hidden', 0), 'must');
        }

        return $search;
    }
244977
public function orderBy($order) 
    {
        
        $this->sql .= ' ORDER BY ';
        
        foreach($order as $column) {
            $this->sql .= $this->quoteColumnName($column[0]) .' '. $column[1] . ', ';
        }
        
        $this->sql = trim($this->sql, ', ');
        
        return $this;
    }
926935
public function orderByScoreDesc(): self
    {
        return $this->sortByDesc(function (Result $result) {
            return $result->getScore($this->maxCommits(), $this->maxComplexity());
        });
    }
783677
public function sqlOrders()
    {
        if (!$this->hasOrders()) {
            return '';
        }

        $parts = [];
        foreach ($this->orders() as $order) {
            if (!$order instanceof DatabaseOrder) {
                $order = $this->createOrder($order->data());
            }

            $sql = $order->sql();
            if (strlen($sql) > 0) {
                $parts[] = $sql;
            }
        }

        if (empty($parts)) {
            return '';
        }

        return ' ORDER BY '.implode(', ', $parts);
    }
1347805
public function build()
    {
        $sql = [
            $this->table->build(),
            $this->set->build(),
            $this->where->build(),
            $this->orderBy->build(),
            $this->limit->build(),
        ];

        $this->values = array_merge(
            array_values($this->set->getValues()),
            $this->where->getValues());

        return implode(' ', array_filter($sql));
    }
280742
private function buildQuery()
    {
        $this->validateQuery();

        $statement = "";
        if ($this->select !== null) {
            $statement .= sprintf("%s %s ", self::SELECT, $this->select);
        }
        if ($this->from !== null) {
            $statement .= sprintf("%s %s ", self::FROM, $this->from);
        }
        if ($this->where !== null) {
            $statement .= sprintf("%s %s ", self::WHERE, $this->where);
        }
        if ($this->orderBy !== null) {
            $statement .= sprintf("%s %s ", self::ORDER_BY, $this->orderBy);
        }
        if ($this->limit !== null) {
            $statement .= sprintf("%s %s ", self::LIMIT, $this->limit);
        }
        if ($this->offset !== null) {
            $statement .= sprintf("%s %s ", self::OFFSET, $this->offset);
        }

        return trim($statement);
    }
776730
private function _constructSql() {
        if($this->sql) {
            return [$this->sql,$this->params];
        }
        $distinct = $this->distinct ? 'DISTINCT' : '';
        $groupby = '';
        if (!empty($this->group)) {
            $groupby = 'GROUP BY ' . $this->group;
        }
        if (!empty($this->having)) {
            $groupby .= ' ' . $this->having;
        }
        $order = !empty($this->order) ? "ORDER BY $this->order" : '';

        $this->fields = $this->fields?$this->fields:'*';
        $sql = "SELECT $distinct $this->fields FROM `$this->table` $this->alias $this->join $this->where $groupby $order $this->limit";
        $sql = str_replace('table.',$this->alias.'.',$sql);
        return [$sql,$this->params];
    }
871565
public function orderBy()
    {
        if (Request::input('order')) {
            return Request::input('order');
        }

        if ($this->orderBy) {
            return $this->orderBy;
        }

        return $this->model->getKeyName();
    }
348160
protected function getOrder()
    {
        if (null === $this->order) {
            $this->order = $this->getSession() ? $this->getSession()->getOrder() : null;
        }

        return $this->order;
    }