Parse the sort variable

@param string|array $mSort The sort variable

@return array
358792
protected function getCountCommonParseSort($mSort)
    {
        $aOut = ['column' => null, 'order' => null];

        // --------------------------------------------------------------------------

        if (is_string($mSort)) {

            $aOut['column'] = $mSort;
            return $aOut;

        } elseif (isset($mSort['column'])) {

            $aOut['column'] = $mSort['column'];

        } else {

            //  Take the first element
            $aOut['column'] = reset($mSort);
            $aOut['column'] = is_string($aOut['column']) ? $aOut['column'] : null;
        }

        if ($aOut['column']) {

            //  Determine order
            if (isset($mSort['order'])) {

                $aOut['order'] = $mSort['order'];

            } elseif (count($mSort) > 1) {

                //  Take the last element
                $aOut['order'] = end($mSort);
                $aOut['order'] = is_string($aOut['order']) ? $aOut['order'] : null;
            }
        }

        return $aOut;
    }
633909
protected function parseOrder($order, $options = [])
    {
        if (is_array($order)) {
            $array = [];
            foreach ($order as $key => $val) {
                if (is_numeric($key)) {
                    if (false === strpos($val, '(')) {
                        $array[] = $this->parseKey($val, $options);
                    } else {
                        $array[] = $val;
                    }
                } else {
                    $sort    = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : '';
                    $array[] = $this->parseKey($key, $options) . ' ' . $sort;
                }
            }
            $order = implode(',', $array);
        }

        return !empty($order) ? ' ORDER BY ' . $order : '';
    }
441116
public function sort(Sorting $sorting)
	{
		if (is_callable($sorting->getSortCallback())) {
			call_user_func(
				$sorting->getSortCallback(),
				$this->data_source,
				$sorting->getSort()
			);

			return $this;
		}

		$sort = $sorting->getSort();

		if (!empty($sort)) {
			$this->data_source->removeClause('ORDER BY');
			$this->data_source->orderBy($sort);
		} else {
			/**
			 * Has the statement already a order by clause?
			 */
			$this->data_source->clause('ORDER BY');

			if ($this->data_source instanceof Dibi\Fluent) {
				$reflection = new \ReflectionClass('Dibi\Fluent');
			} else {
				$reflection = new \ReflectionClass('DibiFluent');
			}

			$cursor_property = $reflection->getProperty('cursor');
			$cursor_property->setAccessible(true);
			$cursor = $cursor_property->getValue($this->data_source);

			if (!$cursor) {
				$this->data_source->orderBy($this->primary_key);
			}
		}

		return $this;
	}
1157287
protected static function buildSortArray($sort)
    {
        if (empty($sort)) {
            return null;
        }

        if (!is_array($sort)) {
            $sort = array_map('trim', explode(',', trim($sort, ',')));
        }
        $out = [];
        foreach ($sort as $combo) {
            if (!is_array($combo)) {
                $combo = array_map('trim', explode(' ', trim($combo, ' ')));
            }
            $dir = 1;
            $field = '';
            switch (count($combo)) {
                case 1:
                    $field = $combo[0];
                    break;
                case 2:
                    $field = $combo[0];
                    switch ($combo[1]) {
                        case -1:
                        case 'desc':
                        case 'DESC':
                        case 'dsc':
                        case 'DSC':
                            $dir = -1;
                            break;
                    }
            }
            if (!empty($field)) {
                $out[$field] = $dir;
            }
        }

        return $out;
    }
304731
private static function handleSort($query, $sort = null)
    {
        $replace = '';

        if ($sort !== null) {
            $sort ->validate(static::class);

            $tableAttribute = (
                $sort->table === null
                ? $sort->attribute
                : $sort->table . '"."' .$sort->attribute
            );

            $replace = "\n" . sprintf(
                'ORDER BY "%s" %s',
                $tableAttribute,
                ($sort->ascending ? 'ASC' : 'DESC')
            );
        }

        $query = str_replace(
            '{{sort}}',
            $replace,
            $query
        );

        return $query;
    }
912102
public function parseResults(LoopResult $loopResult)
    {
        /** @var ImportModel $type */
        foreach ($loopResult->getResultDataCollection() as $type) {
            $loopResultRow = new LoopResultRow($type);

            $url = URL::getInstance()->absoluteUrl(
                $this->getBaseUrl() . "/" . $type->getId()
            );

            try {
                $loopResultRow
                    ->set("HANDLE_CLASS", $type->getHandleClass())
                    ->set("ID", $type->getId())
                    ->set("TITLE", $type->getVirtualColumn("i18n_TITLE"))
                    ->set("DESCRIPTION", $type->getVirtualColumn("i18n_DESCRIPTION"))
                    ->set("URL", $url)
                    ->set("POSITION", $type->getPosition())
                    ->set("CATEGORY_ID", $type->getByName($this->getCategoryName()))
                ;
            } catch (ClassNotFoundException $e) {
            } catch (\ErrorException $e) {
            }

            $this->addOutputFields($loopResultRow, $type);
            $loopResult->addRow($loopResultRow);
        }

        return $loopResult;
    }
12769
protected function sortVariables(array $vars)
    {
        usort($vars, function($a, $b) {
            return $a->options['modifier'] >= $b->options['modifier'] ? 1 : -1;
        });

        return $vars;
    }
389728
function sort(array &$var,$col,$order=SORT_ASC) {
		uasort(
			$var,
			function($val1,$val2) use($col,$order) {
				list($v1,$v2)=[$val1[$col],$val2[$col]];
				$out=is_numeric($v1) && is_numeric($v2)?
					Base::instance()->sign($v1-$v2):strcmp($v1,$v2);
				if ($order==SORT_DESC)
					$out=-$out;
				return $out;
			}
		);
		$var=array_values($var);
	}
832343
private function getSortArrayParameter($sortCondition)
    {
        $sortArray = [
            $sortCondition['column']->getUniqueId(),
        ];

        if ('DESC' === $sortCondition['sortDirection']) {
            $desc = SORT_DESC;
            $sortArray[] = $desc;
        } else {
            $asc = SORT_ASC;
            $sortArray[] = $asc;
        }

        switch (get_class($sortCondition['column']->getType())) {
            case Column\Type\Number::class:
                $numeric = SORT_NUMERIC;
                $sortArray[] = $numeric;
                break;

            case Column\Type\PhpString::class:
                $string = SORT_NATURAL | SORT_FLAG_CASE;
                $sortArray[] = $string;
                break;

            default:
                $regular = SORT_REGULAR;
                $sortArray[] = $regular;
                break;
        }

        return $sortArray;
    }
524292
protected function sort($order)
    {
        $ordered = [];

        $matrix = [
            'label'     => 'getLabels',
            'component' => 'getComponents',
            'message'   => 'getMessage',
        ];

        foreach ($order as $identifier) {
            $components = $this->{$matrix[$identifier]}();
            foreach ($components as $component) {
                $index                              = count($ordered);
                $this->indexReverse[$identifier][0] = $index;
                $this->index[$index]                = $identifier;
                $ordered[]                          = $component;
            }
        }

        return $ordered;
    }
679244
public static function ksort($data)
    {
        if (static::isArray($data) ) {
            foreach ( $data as &$v ) {
                if (is_array($v)) {
                    $v = static::ksort($v);
                }
            }
        }

        ksort($data);

        return $data;
    }
1114226
public function parse(){
		$where = $order = $group = $limit = $q = '';
		$source = $this->parseSource();

		if($this->stmt->getConditions())
			$where = $this->parseWhere();
		if($this->stmt instanceof Result && $this->stmt->getGrouping())
			$group = $this->parseGrouping();
		if($this->stmt->getSorting())
			$order = $this->parseSorting();

		$this->clauses = array($source, $where, $group, $order);

		if($this->stmt->getType() === Manager::STMT_SELECT)
			$q = $this->parseSelectStmt();
		elseif($this->stmt->getType() === Manager::STMT_INSERT)
			$q = $this->parseInsertStmt();
		elseif($this->stmt->getType() === Manager::STMT_UPDATE)
			$q = $this->parseUpdateStmt();
		elseif($this->stmt->getType() === Manager::STMT_DELETE)
			$q = $this->parseDeleteStmt();

		return trim($q);
	}
325196
public function getListSorting()
    {
        $sSortParameter = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('sort');
        if ($this->_aCurrSorting === null && !$sSortParameter && ($oBaseObject = $this->getItemListBaseObject())) {
            $sCatView = $oBaseObject->getCoreTableName();

            $this->_aCurrSorting[$sCatView]["oxrootid"] = "desc";
            $this->_aCurrSorting[$sCatView]["oxleft"] = "asc";

            return $this->_aCurrSorting;
        } else {
            return parent::getListSorting();
        }
    }
221520
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!isset($data['Field'])) {
            throw new Exceptions\Parser("The <Field> sort clause doesn't exist in the input structure");
        }

        if (!is_array($data['Field'])) {
            throw new Exceptions\Parser('The <Field> sort clause has missing arguments: contentTypeIdentifier, fieldDefinitionIdentifier');
        }

        $data['Field'] = $this->normalizeData($data['Field']);

        $direction = isset($data['Field']['direction']) ? $data['Field']['direction'] : null;

        if (!in_array($direction, [Query::SORT_ASC, Query::SORT_DESC])) {
            throw new Exceptions\Parser('Invalid direction format in <Field> sort clause');
        }

        if (isset($data['Field']['identifier'])) {
            if (false === strpos($data['Field']['identifier'], '/')) {
                throw new Exceptions\Parser('<Field> sort clause parameter "identifier" value has to be in "contentTypeIdentifier/fieldDefinitionIdentifier" format');
            }

            list($contentTypeIdentifier, $fieldDefinitionIdentifier) = explode('/', $data['Field']['identifier'], 2);
        } else {
            if (!isset($data['Field']['contentTypeIdentifier'])) {
                throw new Exceptions\Parser('<Field> sort clause have missing parameter "contentTypeIdentifier"');
            }
            if (!isset($data['Field']['fieldDefinitionIdentifier'])) {
                throw new Exceptions\Parser('<Field> sort clause have missing parameter "fieldDefinitionIdentifier"');
            }

            $contentTypeIdentifier = $data['Field']['contentTypeIdentifier'];
            $fieldDefinitionIdentifier = $data['Field']['fieldDefinitionIdentifier'];
        }

        return new FieldSortClause($contentTypeIdentifier, $fieldDefinitionIdentifier, $direction);
    }
666510
public function getSort($className='CSort')
	{
		if($this->_sort===null)
		{
			$this->_sort=new $className;
			if(($id=$this->getId())!='')
				$this->_sort->sortVar=$id.'_sort';
		}
		return $this->_sort;
	}
1358688
public function superSort($array, $method = 'asort', $as = null, $sortFlag = SORT_REGULAR) {

		$originalArray = $array;

		$method = strtolower($method);

		// Check whether we're using an 'as' method.

		$asMethods = ['sortas', 'rsortas', 'natcasesortas', 'natsortas'];
		$usingAsMethod = in_array($method, $asMethods);

		// Normalize the source array.

		if (! is_array($array)) {

			// TODO: Add better handling for other types of objects (e.g. Arrayables, Collections)

			if ($array instanceof ElementQuery) {
				$array = $array->all();
			}
			else
			{
				$array = [];
			}

		}

		// Normalize the sort flag param.

		settype($sortFlag, 'integer');

		// Pre-processing if we're using an 'as' method...

		if ($usingAsMethod) {

			// Normalize `as` param.

			if (empty($as) || !is_string($as)) {
				$as = '';
			}

			// Create a transformed 'as' array by processing each item as an object template.

			$asArray = $array;

			foreach ($array as $k => $v) {
				$asArray[$k] = Craft::$app->getView()->renderObjectTemplate($as, $v);
			}

		}

		// Do the business.

		switch ($method) {

			case 'asort':
				asort($array, $sortFlag);
				break;

			case 'arsort':
				arsort($array, $sortFlag);
				break;

			case 'krsort':
				krsort($array, $sortFlag);
				break;

			case 'ksort':
				ksort($array, $sortFlag);
				break;

			case 'natcasesort':
				natcasesort($array);
				break;

			case 'natsort':
				natsort($array);
				break;

			case 'rsort':
				rsort($array, $sortFlag);
				break;

			case 'sort':
				sort($array, $sortFlag);
				break;

			case 'shuffle':
				shuffle($array);
				break;

			case 'natcasesortas':
				natcasesort($asArray);
				break;

			case 'natsortas':
				natsort($asArray);
				break;

			case 'rsortas':
				arsort($asArray, $sortFlag);
				break;

			case 'sortas':
				asort($asArray, $sortFlag);
				break;

		}

		// Post-processing if we're using an 'as' method...

		if ($usingAsMethod) {

			// Reassemble the result from the newly-sorted transformed 'as' array.

			$array = [];

			foreach ($asArray as $k => $v) {
				$array[$k] = $originalArray[$k];
			}

		}

		return $array;

	}
37876
public static function sortProperties(array $contents, $sort)
    {
        switch ($sort) {
            case self::SORT_VISIBILITY:
                /** @var array<array-key, BasicObject[]> Containers to quickly stable sort by type */
                $containers = array(
                    BasicObject::ACCESS_PUBLIC => array(),
                    BasicObject::ACCESS_PROTECTED => array(),
                    BasicObject::ACCESS_PRIVATE => array(),
                    BasicObject::ACCESS_NONE => array(),
                );

                foreach ($contents as $item) {
                    $containers[$item->access][] = $item;
                }

                return \call_user_func_array('array_merge', $containers);
            case self::SORT_FULL:
                \usort($contents, array('Kint\\Renderer\\Renderer', 'sortPropertiesFull'));
                // no break
            default:
                return $contents;
        }
    }