Order the results of a directory listing

@param  array   $items
@param  string  $type
@param  string  $by
@param  string  $direction
@return array
974389
protected function sort($items, $type = self::TYPE_BOTH, $by = self::KEY_NAME, $direction = self::ASC)
    {
        $returnArray = array();
        if (count($items) > 0) {
            $tmpArray = array();
            foreach($items as $key => $value) {
                $tmpArray[$key] = $value[$by];
            }

            natcasesort($tmpArray);

            if ($direction == self::DESC) {
                $tmpArray = array_reverse($tmpArray, true);
            }

            foreach($tmpArray as $key => $value) {
                $returnArray[] = $items[$key];
            }

            // If sorting by name, lets seperate the files from the dirs.
            if ($by == self::KEY_NAME && $type == self::TYPE_BOTH) {
                $files = array();
                $dirs  = array();

                foreach ($returnArray as $value) {
                    if ($value[self::KEY_TYPE] == self::TYPE_FILE) {
                        $files[] = $value;
                    } elseif ($value[self::KEY_TYPE] == self::TYPE_DIR) {
                        $dirs[] = $value;
                    }
                }

                if ($direction == self::DESC) {
                    $returnArray = array_merge($files, $dirs);
                } else {
                    $returnArray = array_merge($dirs, $files);
                }
            }
        }
        return $returnArray;
    }
967264
public function setOrderBy($sort, $direction = 'ASC')
    {
        $this->sort = $sort;
        $this->direction = $direction;
        return $this;
    }
284921
private function sortOptionsData(array $items)
    {

        usort($items, function ($item1, $item2) {
            if (!isset($item1['adminSortIndex']) or !isset($item2['adminSortIndex'])) {
                return 0;
            }

            return $item1['adminSortIndex'] <= $item2['adminSortIndex'] ? -1 : 1;
        });

        return $items;
    }
77129
public function orderBy($column, $direction = 'ASC')
    {
        $this->ordering[$this->applyTableAlias($column)] = $direction;

        return $this;
    }
112225
public function order($order, $direction = self::ASC)
    {
        $this->order = $order;
        $this->direction = $direction;
        return $this;
    }
716832
public function scopeSort(Builder $query, $column, $direction)
    {
        if (!in_array($column, $this->sortable)) {
            return $query;
        }

        return $query->orderBy($column, $direction);
    }
1312248
public function order($direction = null)
    {
        if (is_null($direction)) {
            $direction = $this->getOrderDirection();
        } else {
            $this->setOrderDirection($direction);
        }

        // if a direction is set
        if (!empty($direction)) {
            if (!is_string($this->order) && is_callable($this->order)) {
                call_user_func_array($this->order, $this);
            } else {

                $table = $this->getTable();

                // verify that source is a query
                if (!$table->isSourceQueryBuilder()) {
                    throw new \Exception('Table source is not an instance of query builder');
                }

                $table->getSource()->orderBy($this->order, $direction);
            }
        }

        return $this;
    }
1294824
public function orderBy($orderBy, $direction='asc')
    {
        if($direction == 'desc')
            return $this->model->orderBy($orderBy, 'desc');
        else
            return $this->model->orderBy($orderBy, 'asc');
    }
1364707
public function sort($index, $direction)
    {
        if (!in_array($direction, ['ASC', 'DESC'])) {
            throw new CollectionException('Sort direction must be ASC or DESC.');
        }

        $this->_sort = ['index' => $index, 'dir' => $direction];
        return $this;
    }
671897
function orderBy(collection, keys, directions) {
    var index = -1;
    var result = collection.map(function (value) {
        var criteria = keys.map(function (key) { return value[key]; });
        return { criteria: criteria, index: ++index, value: value };
    });
    return baseSortBy(result, function (object, other) {
        return compareMultiple(object, other, directions);
    });
}
1311603
public function orderBy($field, $direction = self::DESC) {
        if (is_array($field)) {
            foreach ($field as $key => $dir) {
                $this->orderBy($key, $dir);
            }

        } else if ($field === 'RAND') {
            $this->_orderBy[] = $this->func('RAND');

        } else if ($field instanceof Func) {
            $this->_orderBy[] = $field;

        } else {
            $direction = strtolower($direction);

            if ($direction != self::ASC && $direction != self::DESC) {
                throw new InvalidArgumentException(sprintf('Invalid order direction %s for field %s', $direction, $field));
            }

            $this->_orderBy[$field] = $direction;
        }

        return $this;
    }
113906
public function listYourRepositories(string $type = AbstractApi::TYPE_ALL,
                                         string $sort = AbstractApi::SORT_FULL_NAME,
                                         string $direction = AbstractApi::DIRECTION_DESC): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/user/repos?:args',
            http_build_query(['type' => $type, 'sort' => $sort, 'direction' => $direction])));
    }
494492
protected function _order($fields)
    {
        $direction = 'ASC';

        $result = [];
        foreach ($fields as $field => $value) {
            if (!is_int($field)) {
                $result[$field] = $value;
                continue;
            }
            if (preg_match('/^(.*?)\s+((?:a|de)sc)$/i', $value, $match)) {
                $value = $match[1];
                $dir = $match[2];
            } else {
                $dir = $direction;
            }
            $result[$value] = $dir;
        }
        return $result;
    }
377592
protected function orderByDirection($field, $direction, $prefixWithTableAlias = true)
    {
        $aliasInsert = $prefixWithTableAlias ? '?f:alias:.' : '';

        if ($this->orderSql == '') {
            $this->orderSql = " ORDER BY {$aliasInsert}?f {$direction}";
        } else {
            $this->orderSql .= ", {$aliasInsert}?f {$direction}";
        }
        $this->orderArguments[] = $field;
    }
543419
public function sortAction($id, $direction)
    {
        $entity = $this->getRepository()->sort($id, $direction);

        $last = $this->getRequest()->headers->get('referer');

        return $this->redirect($last);
    }
1273836
public function order($column, $direction = 'asc')
    {
        $this->set('orderby', $column);
        $this->set('ordertype', $direction);

        return $this;
    }
456469
public function orderBy($fields, string $direction = 'ASC'): IQueryBuilderHandler
    {
        if (\is_array($fields) === false) {
            $fields = [$fields];
        }

        foreach ((array)$fields as $key => $value) {
            $field = $key;
            $type = $value;

            if (\is_int($key) === true) {
                $field = $value;
                $type = $direction;
            }

            if (($field instanceof Raw) === false) {
                $field = $this->addTablePrefix($field);
            }

            $this->statements['orderBys'][] = compact('field', 'type');
        }

        return $this;
    }