Sorts the result by referrer value.

@param string $direction Mongo sort direction: 1 => ascending; -1 => descending

@return $this
@throws AnalyticsDbException
320231
public function sortByRef($direction)
    {
        if ($this->id != '$ref') {
            throw new AnalyticsDbException('In order to sort by ref, you need to first group by ref.');
        }

        $direction = (int)$direction;
        $this->pipeline['$sort'] = ['_id' => $direction];

        return $this;
    }
278598
public function add_sort($field, $direction = 'ASC') {
        if (!isset($this->_query_modifiers['sort'])) {
            $this->_query_modifiers['sort'] = array();
        }

        $this->_query_modifiers['sort'][$field] = $direction;
    }
941018
public function sortBy($column, $direction = 'asc')
    {
        $this->sortBy = $column;
        if (in_array(strtolower($direction), array('asc', 'desc'))) {
            $this->sortByDirection = $direction;
        } else {
            $this->sortByDirection = 'asc';
        }
    }
45489
public function groupBy($fields, $direction = false)
    {
        $this->groupBy->addFields($fields, $direction);

        return $this;
    }
506428
public function orderBy(
        string $cypher,
        string $direction = 'ASC'
    ): self {
        $direction = \strtolower($direction);

        $query = new self;
        $query->clauses = $this->clauses->add(
            Clause\OrderByClause::$direction($cypher)
        );

        return $query;
    }
967264
public function setOrderBy($sort, $direction = 'ASC')
    {
        $this->sort = $sort;
        $this->direction = $direction;
        return $this;
    }
637591
public function sortByProperty( $property, $direction = null )
    {
        $this->sort( $this->generateSortByPropertyClosure( $property, $direction ) );
        return $this;
    }
394423
public function setDirection($direction)
    {
        if ($direction !== self::DIRECTION_FORWARD && $direction !== self::DIRECTION_REVERSE && $direction !== self::DIRECTION_BOTH) {
            throw new InvalidArgumentException('Invalid direction given');
        }
        $this->direction = $direction;

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

        return $this;
    }
599862
public static function parseDirection($direction = Order::ASC)
    {
        if (preg_match('/^asc$/i', $direction)) {
            return Order::ASC;
        } else {
            return Order::DESC;
        }
    }
373205
public function orderBy($column, $direction = 'ASC')
    {
        $this->orderBy = $column;
        $this->orderByDirection = $direction;

        return $this;
    }
1234286
public function move($direction)
    {
        if ($direction === self::DIR_FORWARD) {
            return $this->next();
        } elseif ($direction === self::DIR_BACKWARD) {
            return $this->prev();
        }

        throw new InvalidArgumentException(sprintf('Unknown direction %s', $direction));
    }
1017147
public static function sortKeys(array $array, string $direction = 'ASC')
    {
        $direction = (strtolower($direction) === 'desc') ? SORT_DESC : SORT_ASC;
        if ($direction === SORT_ASC) {
            ksort($array);
        } else {
            krsort($array);
        }

        return $array;
    }
1239861
public function sortBy($fieldName, $direction = null)
	{
		$predefinedFields = $this->get('sort');
		$sortingFields = [];

		// Field exists, prioritize and set direction (if any).
		if ($field = $this->findField($fieldName, $predefinedFields)) {
			// Field was defined without options.
			if (!is_array($field)) {
				if ($direction) {
					$sortingFields[] = [$fieldName => $direction];
				} else {
					$sortingFields[] = $fieldName;
				}
			} else {
				// Set direction, otherwise it will just use the default definition.
				if ($direction) {
					// Defined as {"post_date" : {"order" : "asc", "mode": "avg"}}
					if (is_array($field[$fieldName])) {
						$field[$fieldName]['order'] = $direction;
					} // Defined as {"post_date" : "asc"}
					else {
						$field[$fieldName] = $direction;
					}
				}
				$sortingFields[] = $field;
			}
		} // Field does not exist, add it.
		else {
			$sortingFields[] = [$fieldName => $direction];
		}

		// Add the predefined fields but remove the one we are sorting on.
		if ($predefinedFields) {
			foreach ($predefinedFields as $field) {
				if (!is_array($field) && $fieldName == $field) {
					continue;
				} elseif (is_array($field) && array_key_exists($fieldName, $field)) {
					continue;
				}

				$sortingFields[] = $field;
			}
		}

		$this->set('sort', $sortingFields);

		return $this;
	}
634963
public function sortByRelation($column, $direction = 'ASC')
    {
        $relations = explode('.', $column);
        $column    = array_pop($relations);

        /** @var \Illuminate\Database\Eloquent\Model $model */
        $model = $this->repository->makeModel();

        $this->instance->getQuery()->orders = [];

        foreach ($relations as $relation) {
            /* @var Relation $relationClass */
            $this->joinRelation($relationClass = $model->{camel_case($relation)}());

            $model = $relationClass->getRelated();
        }

        $selectedColumns = $this->instance->getQuery()->columns;

        $addColumn = DB::raw("{$this->repository->makeModel()->getTable()}.*");

        if (is_array($selectedColumns) && array_search('*', $selectedColumns, true) !== null) {
            $this->instance->getQuery()->columns[array_search('*', $selectedColumns, true)] = $addColumn;
        } else {
            $this->instance->select($addColumn);
        }

        $this->instance->orderBy("{$model->getTable()}.{$column}", $direction);

        return $this;
    }
343799
public function sortBy($field, $direction = 'desc')
    {
        $this->sortByField = $field;

        if (strtolower($direction) === 'asc') {
            $this->sortByDirection = SORT_ASC;
        } else {
            $this->sortByDirection = SORT_DESC;
        }

        return $this;
    }
1360658
public function orderBy($key, $direction = self::ORDER_ASC, $tableName = null)
    {
        if (!$tableName) {
            $tableName = $this->getTableName();
        }
        $this->orderBy[] = ['key' => $key, 'direction' => $direction, 'tableName' => $tableName];
        return $this;
    }