Parses ORDER BY clause.
@return string
511472
protected function parseSorting(){
		$order = array();
		foreach($this->stmt->getSorting() as $rule){
			list($field, $type) = $rule;
			$order[] = $this->tryDelimite($field) . ($type !== null ? ' ' . $type : '');
		}
		return "\nORDER BY " . implode(', ', $order);
	}
86197
protected function getOrderByClause($conn = null) {
		$statement = new QueryStatement($conn);
		$orders = $this->orders;
		foreach ($orders as &$order) {
			$order_parts = explode(' ', $order);
			if (count($order_parts) == 1 || count($order_parts) == 2) {
				$statement->addIdentifier($order_parts[0]);
				$order_parts[0] = QueryStatement::IDENTIFIER;
			}
			$order = implode(' ', $order_parts);
		}
		$statement->string = "\nORDER BY " . implode(', ', $orders);
		return $statement;
	}
985598
public function parse()
    {
        $input = $this->queryString;

        // Parse string if it's not already parsed into an array
        if (is_string($this->queryString)) {
            $input = [];
            parse_str($this->queryString, $input);
        }

        $this->query = new Query($input);

        $this->parseQ();
        $this->parseEmbeds();
        $this->parseIncludes();
        $this->parseExcludes();
        $this->parseSorts();

        return $this->query;
    }
1067949
protected function parseOrder()
	{
		if(!isset($this->operationOption['order']))
		{
			return '';
		}
		$result = '';
		foreach($this->operationOption['order'] as $order)
		{
			switch(isset($order['type']) ? $order['type'] : '')
			{
				case 'field':
					$result .= $this->parseOrderByField($order) . ',';
					break;
				default:
					if(is_array($order))
					{
						foreach($order as $key => $value)
						{
							if(is_numeric($key))
							{
								$result .= $value . ',';
							}
							else
							{
								$result .= $this->parseKeyword($key) . ' ' . $value . ',';
							}
						}
					}
					else
					{
						$result .= $order . ',';
					}
					break;
			}
		}
		if ('' === $result)
		{
			return '';
		}
		else
		{
			return 'order by ' . substr($result, 0, - 1) . ' ';
		}
	}
306850
protected function addOrdering()
    {
        if ($this->parser->getOrder()) {
            $this->query->orderByRaw($this->parser->getOrder());
        }

        return $this;
    }
100615
public function parse(array $criteria, array $orderBy = array(), $limit = null, $offset = null)
    {
        $statement = new Expr\Statement();

        if(!empty($criteria)) {
            $statement->setClause('condition', $this->parseCriteria($criteria));
        }

        if(!empty($orderBy)) 
            $statement->setClause('order', $this->parseOrderBy($orderBy));
        if($limit)
            $statement->setClause('limit', $this->parseLimit($limit));
        if($offset)
            $statement->setClause('offset', $this->parseOffset($offset));

        return new Query($statement, $this->persister);
    }
43589
public function OrderBy($Value = NULL) {
      if ($Value === NULL)
         return $this->_OrderBy;

      if (is_string($Value))
         $Value = array($Value);

      if (is_array($Value)) {
         // Set the order of this object.
         $OrderBy = array();

         foreach($Value as $Part) {
            if (StringEndsWith($Part, ' desc', TRUE))
               $OrderBy[] = array(substr($Part, 0, -5), 'desc');
            elseif (StringEndsWith($Part, ' asc', TRUE))
               $OrderBy[] = array(substr($Part, 0, -4), 'asc');
            else
               $OrderBy[] = array($Part, 'asc');
         }
         $this->_OrderBy = $OrderBy;
      } elseif (is_a($Value, 'Gdn_SQLDriver')) {
         // Set the order of the given sql.
         foreach ($this->_OrderBy as $Parts) {
            $Value->OrderBy($Parts[0], $Parts[1]);
         }
      }
   }
697313
public function getQuery()
    {
        $sql = $this->setQuery;
        $sql .= $this->getWhere();
        $sql .= $this->getGroupBy();
        $sql .= $this->getOrderBy();
        $sql .= $this->getHaving();
        $sql .= $this->getLimit();

        $this->setQuery = null;
        $this->setWhere = null;
        $this->setHaving = null;
        $this->setOrderBy = null;
        $this->setGroupBy = null;
        $this->setLimit = null;

        return str_replace('  ', ' ', $sql);
    }
240605
protected function _prepareOrderByQuery($query = null)
    {
        // sorting
        $sortFields = $this->getListSorting();

        if (is_array($sortFields) && count($sortFields)) {
            // only add order by at full sql not for count(*)
            $query .= ' order by ';
            $addSeparator = false;

            $listItem = $this->getItemListBaseObject();
            $languageId = $listItem->isMultilang() ? $listItem->getLanguage() : \OxidEsales\Eshop\Core\Registry::getLang()->getBaseLanguage();

            $descending = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('adminorder');
            $descending = $descending !== null ? (bool)$descending : $this->_blDesc;

            foreach ($sortFields as $table => $fieldData) {
                $table = $table ? (getViewName($table, $languageId) . '.') : '';
                foreach ($fieldData as $column => $sortDirectory) {
                    $field = $table . $column;

                    //add table name to column name if no table name found attached to column name
                    $query .= ((($addSeparator) ? ', ' : '')) . \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quoteIdentifier($field);

                    //V oxActive field search always DESC
                    if ($descending || $column == "oxactive" || strcasecmp($sortDirectory, 'desc') == 0) {
                        $query .= ' desc ';
                    }

                    $addSeparator = true;
                }
            }
        }

        return $query;
    }
492109
protected function prepareOrderBy(): string
    {
        if (empty($this->orderBy)) {
            return '';
        }
        $orders = [];
        foreach ($this->orderBy as $column => $order) {
            $orders[] = $column . ' ' . $order;
        }
        return ' ORDER BY ' . implode(', ', $orders);
    }
871674
private function _prepareOrderBy()
	{
		$sQuery = '';

		if (is_array($this->_aOrderBy) && count($this->_aOrderBy) > 0) {

			$sQuery .= ' ORDER BY '.implode(',', $this->_aOrderBy).' ';
		}

		return $sQuery;
	}
34095
private function getOrderDirection(): string
    {
        $result = !empty($this->searchData['sort_by_order']) ?
            $this->searchData['sort_by_order'] :
            Options::DEFAULT_SORT_BY_ORDER;

        return $result;
    }
343228
protected function parseOrder($order) {
        if(is_string($order)) {
            $array   =  explode(',',$order);
            $order   =  array();
            foreach ($array as $key=>$val){
                $arr  =  explode(' ',trim($val));
                if(isset($arr[1])) {
                    $arr[1]  =  $arr[1]=='asc'?1:-1;
                }else{
                    $arr[1]  =  1;
                }
                $order[$arr[0]]    = $arr[1];
            }
        }
        return $order;
    }
267441
public function reverseOrderBy()
    {
        $order = $this->getOrderBy();
        $this->orderby = array();

        foreach ($order as $clause => $dir) {
            $dir = (strtoupper($dir) == 'DESC') ? 'ASC' : 'DESC';
            $this->addOrderBy($clause, $dir);
        }

        return $this;
    }
785752
public function render_order()
    {
        if (!$this->args['order']) {
            return'';
        }
        $x = array();
        foreach ($this->args['order'] as $tmp) {
            list($arg, $desc) = $tmp;
            $x[] = $this->consume($arg).($desc ? (' '.$desc) : '');
        }

        return 'order by '.implode(', ', array_reverse($x));
    }
202007
private function getSelectQuery()
	{
		$result = $this->getSelectClause();

		if ($join = $this->getJoinClause()) {
			$result .= ' ' . $join;
		}

		if ($where = $this->getWhereClause()) {
			$result .= ' ' . $where;
		}

		if ($groupBy = $this->getGroupByClause()) {
			$result .= ' ' . $groupBy;
		}

		if ($orderBy = $this->getOrderByClause()) {
			$result .= ' ' . $orderBy;
		}

		if ($limit = $this->getLimitClause()) {
			$result .= ' ' . $limit;
		}

		if ($offset = $this->getOffsetClause()) {
			$result .= ' ' . $offset;
		}

		return $result;
	}
112205
public function order($spec)
    {
        if (!is_array($spec)) {
            $spec = array($spec);
        }

        // force 'ASC' or 'DESC' on each order spec, default is ASC.
        foreach ($spec as $val) {
            if ($val instanceof Zend_Db_Expr) {
                $expr = $val->__toString();
                if (empty($expr)) {
                    continue;
                }
                $this->_parts[self::ORDER][] = $val;
            } else {
                if (empty($val)) {
                    continue;
                }
                $direction = self::SQL_ASC;
                if (preg_match('/(.*\W)(' . self::SQL_ASC . '|' . self::SQL_DESC . ')\b/si', $val, $matches)) {
                    $val = trim($matches[1]);
                    $direction = $matches[2];
                }
                if (preg_match('/\(.*\)/', $val)) {
                    $val = new Zend_Db_Expr($val);
                }
                $this->_parts[self::ORDER][] = array($val, $direction);
            }
        }

        return $this;
    }