Retrieve all records

@param array $sort   sort
@param array $fields fields

@return Collection
555442
public static function all( $sort = array() , $fields = array())
    {
        $criteria = array();
        self::processCriteriaWithType($criteria);
        return self::find($criteria, self::mapFields($sort), self::mapFields($fields));
    }
57101
public function orderBy($fields, $defaultDirection = 'ASC')
    {
        if (!is_array($fields)) {
            $fields = array($fields);
        }

        foreach ($fields as $key => $value) {
            $field = $key;
            $type = $value;
            if (is_int($key)) {
                $field = $value;
                $type = $defaultDirection;
            }
            if (!$field instanceof Raw) {
                $field = $this->addTablePrefix($field);
            }
            $this->statements['orderBys'][] = compact('field', 'type');
        }

        return $this;
    }
1309665
public static function lists($field, $filters = null)
    {
        $model = new static;

        $query = static::query(null, $model)->where($filters);

        $list = [];

        if (is_string($field)) {
            $keyField = $model->getPrimaryKey();
            $valueField = $field;

            $query = $query->select([$keyField, $valueField]);
            if (in_array('display_order', $model->getFields(), true)) {
                return $query->orderBy(['display_order' => SORT_DESC, $keyField => SORT_ASC])->fetch(true);
            } else {
                return $query->orderBy($keyField)->fetch(true);
            }
        } else {
            $keyField = key($field);
            $valueField = current($field);
            /** @noinspection ForeachSourceInspection */
            foreach ($query->select([$keyField, $valueField])->fetch(true) as $v) {
                $key = $v[$keyField];
                $value = $v[$valueField];

                if (!isset($list[$key])) {
                    $list[$key] = $value;
                } elseif (is_array($list[$key])) {
                    $list[$key][] = $value;
                } else {
                    $list[$key] = [$list[$key], $value];
                }
            }

            return $list;
        }
    }
1167432
public function sort($fields)
    {
        foreach ($fields as $fieldName => $order) {
            if (is_string($order)) {
                $order = strtolower($order) === 'asc' ? 1 : -1;
            }

            if (is_scalar($order)) {
                $fields[$fieldName] = (integer) $order;
            }
        }
        $this->sort = $fields;
        $this->riakCursor->sort($fields);
        return $this;
    }
648225
protected function _getSortFields()
    {
        $sortFields = [];

        foreach ($this->controller->sortFields as $field => $options) {
            if (isset($options['actions']) &&
                is_array($options['actions']) &&
                in_array($this->action, $options['actions'])
            ) {
                $sortFields[$field] = $options;
            }
        }

        return $sortFields;
    }
924317
public static function sortCol($result,$array)
    {
        foreach ($result as $key => $fields) {
         $dados[] = self::sortkeys($fields,$array);
        }

        if(!$dados){ $dados = [];}

        return $dados;
    }
760401
protected function sortRecords(&$results, ReadQuery $query)
    {
        if (list($sortField, $sortDirection) = $query->getSortBy()) {
            usort($results, function($a, $b) use ($sortField, $sortDirection) {

                $leftValue = $this->getRecordField($a, $sortField);
                $rightValue = $this->getRecordField($b, $sortField);

                if ($sortDirection == 'DESC') {
                    return strcmp((string) $rightValue, (string) $leftValue);
                } else {
                    return strcmp((string) $leftValue, (string) $rightValue);
                }
            });
        }
    }
797901
public static function sort(array $records, array $fields) {
        $records = new coursecat_sortable_records($records);
        $records->sortfields = $fields;
        $records->uasort(array($records, 'sort_by_many_fields'));
        return $records->getArrayCopy();
    }
710938
public function get($where = array(), $order = array())
    {
        $this->connectToDB();
        $this->queryBuilder->table($this->view());
        //where
        $this->where($where);
        //order
        foreach($order as $field => $direction) {
            $this->queryBuilder->orderBy($field, $direction);
        }
        $records = $this->queryBuilder->get();
        return $records;
    }
1358589
public function pushEachSort($field, array $sort)
    {
        // add modifiers
        if (empty($sort)) {
            throw new Exception('Sort condition is empty');
        }
        
        if (!isset($this->operators['$push'][$field]['$each'])) {
            throw new Exception('Field ' . $field . ' must be pushed with $each modifier');
        }
        
        $this->operators['$push'][$field]['$sort'] = $sort;
        
        return $this;
    }
1349600
protected function sortRoutes($sort, array $routes)
    {
        return Arr::sort($routes, function ($route) use ($sort) {
            return $route[$sort];
        });
    }
613681
public function sort(array $sort = null) {
        if ($sort === null) {
            return $this->sort;
        }

        $sortData = [];

        foreach ($sort as $field) {
            $field = trim($field);
            $dir = 'asc';

            if (empty($field)) {
                throw new RuntimeException('Badly formatted sort', 400);
            }

            if (strpos($field, ':') !== false) {
                list($fieldName, $dir) = explode(':', $field);

                if ($dir !== 'asc' && $dir !== 'desc') {
                    throw new RuntimeException('Invalid sort value: ' . $field, 400);
                }

                $field = $fieldName;
            }

            $sortData[] = [
                'field' => $field,
                'sort' => $dir,
            ];
        }

        $this->sort = $sortData;

        return $this;
    }
1368204
public function sortCollection(Collection $collection, $orderBy, $orderDir = 'asc', $orderManual = null, $sort_flags = null)
    {
        $items = $collection->toArray();
        if (!$items) {
            return [];
        }

        $lookup = md5(json_encode($items) . json_encode($orderManual) . $orderBy . $orderDir);
        if (!isset($this->sort[$lookup][$orderBy])) {
            $this->buildSort($lookup, $items, $orderBy, $orderManual, $sort_flags);
        }

        $sort = $this->sort[$lookup][$orderBy];

        if ($orderDir !== 'asc') {
            $sort = array_reverse($sort);
        }

        return $sort;

    }
329841
public function all($fields = [], $sorted = true, $sortBy = 'cn', $sortByDirection = 'asc')
    {
        $personCategory = $this->adldap->getPersonFilter('category');
        $person = $this->adldap->getPersonFilter('person');

        $search = $this->adldap->search()
            ->select($fields)
            ->where($personCategory, '=', $person)
            ->where('samaccounttype', '=', Adldap::ADLDAP_NORMAL_ACCOUNT);

        if ($sorted) {
            $search->sortBy($sortBy, $sortByDirection);
        }

        return $search->get();
    }
1036033
public static function get_records_select($select, $params = null, $sort = '', $fields = '*', $limitfrom = 0, $limitnum = 0) {
        global $DB;

        $records = $DB->get_records_select(static::TABLE, $select, $params, $sort, $fields, $limitfrom, $limitnum);

        // We return class instances.
        $instances = array();
        foreach ($records as $key => $record) {
            $instances[$key] = new static(0, $record);
        }

        return $instances;

    }
153185
public function sourceRecords($params, $sort, $limit)
    {
        if ($sort) {
            $parts = explode(' ', $sort);
            $field = $parts[0];
            $direction = $parts[1];
        }
        $where = null;
        if (isset($params['Title']) && $params['Title'] != '') {
            $where = 'Title LIKE \'%' . $params['Title'] . '%\'';
        }
        /** @var ArrayList|Tag[] $ret */
        $ret = Tag::get()->where($where);
        /** @var ArrayList $returnSet */
        $returnSet = ArrayList::create();
        if ($ret)
            foreach ($ret as $record) {
                $record->Itemcount = $record->News()->count();
                $returnSet->push($record);
            }

        return $returnSet;
    }
1069299
public static function sort_field($arr, $sortField, $sortDirection = SORT_ASC)
    {
        self::sort_multi($arr, [$sortField => $sortDirection]);
        return $arr;
    }