Sort an array of records as per by a ReadQuery getSortBy()

@param $results
@param ReadQuery $query
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);
                }
            });
        }
    }
1244553
private function applySortStateToResult(ResultInterface $results, $activeSortId)
    {
        $sort = $this->dbAdapter->getSortTypeFromId($activeSortId);
        $sortString = new SortString($sort->getSortString());
        $results->setSort($sortString->getAsArray());

        return $results;
    }
1240115
private function executeSearch($query, $limit, $start, $sort = null)
    {
        $qParam = new Parameter\Query($query);
        $groupParam = new Parameter\Group();
        $startParam = new Parameter\Start($start);
        $limitParam = new Parameter\Rows($limit);
        $typeParam = new Parameter\FilterQuery('type:event OR (type:actor AND category_id:8.15.0.0.0)');

        $params = array(
            $qParam,
            $groupParam,
            $limitParam,
            $startParam,
            $typeParam,
        );

        if ($this->includePrivateItems) {
            $privateParam = new Parameter\FilterQuery('private:*');

            $params[] = $privateParam;
        }

        if ($sort) {
            $params[] = new Parameter\Parameter('sort', $sort);
        }

        $response = $this->searchAPI2->search($params);

        return $response;
    }
572387
function queryRow($query, $resultType = MYSQLI_ASSOC)
  {
    $res = $this->q($query);
    if ($res->num_rows == 0)
      $row = false;
    else
      $row = $res->fetch_array($resultType);
    $res->close();
    return $row;
  }
840972
public function scopePimp(Builder $builder, $query = [], $sort = [], $relations = [])
    {
        $query = $query ?: array_except(Input::all(), [$this->sortParameterName, $this->withParameterName]);
        $builder->filtered($query)->sorted($sort)->withRelations($relations);
    }
1172785
public static function query($query)
    {
        //
        static::applySchema();

        //
        $table = self::getTable();
        $whereArray = [];

        //
        if (isset($query['where'])) {
            $whereArray[] = '('.$query['where'].')';
            unset($query['where']);
        }

        //
        foreach ($query as $field => $value) {
            if (in_array($field, ['order', 'limit'])) {
                continue;
            }
            $whereArray[] = "{$field} = '{$value}'";
        }

        //
        $where = count($whereArray) > 0 ? 'WHERE '.implode(' AND ', $whereArray) : '';
        $order = isset($query['order']) ? 'ORDER BY '.$query['order'] : '';
        $limit = isset($query['limit']) ? 'LIMIT '.$query['limit'] : '';
        $sql = "SELECT * FROM {$table} {$where} {$order} {$limit}";
        $results = static::getDatabase()->getResults($sql);

        //
        foreach ($results as &$record) {
            $record = static::create($record);
        }

        return $results;
    }
411668
private function sort(array $databases, $sort, $reverseSort)
    {
        switch ($sort) {
            case 'name':
                ksort($databases);
                break;

            case 'size':
                uasort(
                    $databases,
                    function ($a, $b) {
                        return $a['size'] > $b['size'];
                    }
                );
                break;

            default:
                throw new Exception\DomainException("Invalid sort option \"$sort\".");
        }

        if ($reverseSort) {
            $databases = array_reverse($databases, true);
        }

        return $databases;
    }
1320113
public function processColumnListing($results)
    {
        return array_values(array_map(function ($result)
        {
            $result = (object) $result;

            return $result->column_name;

        }, $results));
    }
63407
function (query, items) {
            var sortExpressions = query.query.sort,
                self = this;

            if(sortExpressions){
                return items.sort(function (a, b) {
                    var sortExpression,
                        ret = 0;
                    for (var i = 0; i < sortExpressions.length; i++) {
                        sortExpression = sortExpressions[i];
                        ret = self._compareExpression(a, b, sortExpression);
                        if (ret !== 0) {
                            return ret;
                        }
                    }
                    return ret;
                });
            } else {
                return items;
            }

        }
657117
public function applyOrderBy(SelectQuery $query)
    {
        foreach ($this->sortColumns as $column => $direction) {
            $query->orderBy(
                $column,
                $direction === Query::SORT_ASC ? SelectQuery::ASC : SelectQuery::DESC
            );
        }
        // @todo Review needed
        // The following line was added because without it, loading sub user groups through the Public API
        // fails with the database error "Unknown column sort_column_0". The change does not break any
        // integration tests or legacy persistence tests, but it can break something else, so review is needed
        // Discussion: https://github.com/ezsystems/ezpublish-kernel/commit/8749d0977307858c3e2a7d82f3be90fa21973357#L1R102
        $this->sortColumns = array();
    }
424493
protected function _sort(QueryBuilder $qb, array $sorts = [])
    {
        foreach ($sorts as $field => $direction) {
            $qb->addOrderBy('e.'.$field, $direction);
        }
        return $qb;
    }
707058
protected function execute(string $query, array $bindings = [])
    {
        $query = N1qlQuery::fromString($query);
        $query->consistency($this->consistency);
        $query->crossBucket($this->crossBucket);
        $query->positionalParams($bindings);
        $result = $this->executeQuery($query);
        $this->metrics = $result->metrics ?? [];

        return $result;
    }
310372
private function checkResultCount(array $result, $query)
    {
        if (count($result) === 0) {
            throw new RowNotFoundException('Row not found for query: ' . $query);
        }

        if (count($result) > 1) {
            throw new MultipleRowFoundException('Multiple row found for query: ' . $query);
        }
    }
112759
private function iteratorFromResults(array $results)
    {
        $values = [];

        foreach ($results as $pair) {
            $entry = new IndexEntry();

            $entry->indexKey  = $pair->key;
            $entry->objectKey = $pair->value;

            $values[] = $entry;
        }

        return new ArrayIterator($values);
    }
188714
function sortQueryresults(matches, order) {
  const orderArray = order.split(',').map(k => {
    let dir = 'asc';
    let key = k;

    if (k.charAt(0) === '-') {
      key = k.substring(1);
      dir = 'desc';
    }

    return [item => deserializeQueryParam(item[key]), dir];
  });

  const keys = orderArray.map(_.first);
  const orders = orderArray.map(_.last);

  return _.orderBy(matches, keys, orders);
}
429640
final protected function process(\SelectQueryInterface $select, Query $query)
    {
        $sortField = null;

        if ($query->hasSortField()) {
            $sortField = $query->getSortField();

            $select->orderBy($this->fields[$sortField]['column'], Query::SORT_DESC === $query->getSortOrder() ? 'desc' : 'asc');
        }

        // Add a predictible ordering column
        if ($sortField !== $this->idColumn) {
            $select->orderBy($this->idColumn, Query::SORT_DESC === $query->getSortOrder() ? 'desc' : 'asc');
        }

        if ($this->fulltextField) {
            if ($searchstring = $query->getSearchString()) {
                $select->condition($this->fulltextField, '%'.db_like($searchstring).'%', 'LIKE');
            }
        }

        $this->applyFilters($select, $query);

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

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

        return $dados;
    }