Sorts the LDAP search results by the specified field
and direction.

@param $field
@param string $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;
    }
67863
final public function orderBy($orderby, $direction = '')
    {
        if (strtolower($direction) == 'random') {
            $orderby = ''; // Random results want or don't need a field name
            $direction = $this->_randomKeyword;
        } elseif (trim($direction) != '') {
            $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' ' . $direction : ' ASC';
        }


        if (strpos($orderby, ',') !== FALSE) {
            $temp = array();
            foreach (explode(',', $orderby) as $part) {
                $part = trim($part);
                if (!in_array($part, $this->arrayAliasedTables)) {
                    $part = $this->identifiers(trim($part));
                }
                $temp[] = $part;
            }

            $orderby = implode(', ', $temp);
        } else if ($direction != $this->_randomKeyword) {
            $orderby = $this->identifiers($orderby);
        }

        $orderbyStatement = $orderby . $direction;

        $this->arrayOrderBy[] = $orderbyStatement;
        if ($this->arrayCaching === TRUE) {
            $this->arrayCacheOrderBy[] = $orderbyStatement;
            $this->arrayCacheExists[] = 'orderby';
        }

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

        return $this;
    }
784780
public function sort($column, $direction = 'asc')
    {
        if (is_int($direction)) {
            $direction = ($direction == -1) ? 'desc' : 'asc';
        }
        $this->query->orderBy($column, $direction);

        return $this;
    }
637591
public function sortByProperty( $property, $direction = null )
    {
        $this->sort( $this->generateSortByPropertyClosure( $property, $direction ) );
        return $this;
    }
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;
    }
144551
public function scopeSortedBySourceAttribute(Builder $query, $attribute, $direction = 'ASC')
    {
        return $this->orderQueryBySourceAttribute($query, $attribute, $direction);
    }
373205
public function orderBy($column, $direction = 'ASC')
    {
        $this->orderBy = $column;
        $this->orderByDirection = $direction;

        return $this;
    }
1016576
public function sortBy($field, $options = SORT_REGULAR, $descending = false)
    {
        $results = [];

        foreach ($this->divisions as $key => $value) {
            $meta = $value->toArray();
            $results[$key] = $meta[$field];
        }

        $descending ? arsort($results, $options)
                    : asort($results, $options);
        
        foreach (array_keys($results) as $key) {
            $results[$key] = $this->divisions[$key];
        }

        return new static($this->manager, $results);
    }
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;
	}
592084
public function orderBy($fields = array())
		{
			foreach ($fields as $col => $val) {
				if ($val == -1 or $val === false or strtolower($val) == 'desc') {
					$this->sorts[$col] = -1;
				} else {
					$this->sorts[$col] = 1;
				}
			}

			return $this;
		}
1168820
public PushOptions sort(final String field, final int direction) {
        if (sort != null) {
            throw new IllegalStateException("sortDocument can not be set if sort already is");
        }
        if (sortDocument == null) {
            sortDocument = new BasicDBObject();
        }
        sortDocument.put(field, direction);
        return this;
    }
1336908
public function addOrderByField($field = 'order', $direction_desc = false, $table = '', $do_not_use_table_in_sql = false): self
    {
        // No table provided
        if (!$table) {
            $table = $this->getDbTableName();
        }

        $direction = $direction_desc ? 'DESC' : ' ASC';

        // Swap fields with translation table
        if (\in_array($field, $this->translation_fields, true)) {
            $this->translation_join_count++;
            $this->addJoinTable(['cms_translations', $this->getTranslationTableJoinAlias() . $this->translation_join_count], 'id', $field, 'LEFT', $table);

            $this->order_fields[] = [
                'table'                   => false,
                'field'                   => '`' . $this->getTranslationTableJoinAlias() . $this->translation_join_count . '`.`' . $this->getLanguage() . '`',
                'direction'               => $direction,
                'do_not_use_table_in_sql' => true,
                'type'                    => 'string'
            ];
        } else {
            $this->order_fields[] = [
                'table'                   => $table,
                'field'                   => $field,
                'direction'               => $direction,
                'do_not_use_table_in_sql' => $do_not_use_table_in_sql,
                'type'                    => 'simple'
            ];
        }

        return $this;
    }
914372
public function add($field, $direction)
	{
		$this->orderRules[] = array(
				self::FIELD_POS => $field,
				self::DIRECTION_POS => $direction
		);
	}
478320
private function buildFieldSortClause(array $values, $direction)
    {
        if (!array_key_exists(1, $values)) {
            throw new InvalidArgumentException(
                'Field sort clause requires ContentType identifier'
            );
        }

        if (!array_key_exists(2, $values)) {
            throw new InvalidArgumentException(
                'Field sort clause requires FieldDefinition identifier'
            );
        }

        return new Field($values[1], $values[2], $direction);
    }
970804
public function orderBy($field, $direction = 'asc')
    {
        $this->setOrderByField($field);
        $this->setOrderByDirection($direction);

        return $this;
    }
1110059
public function orderBy($index, $direction = 'desc')
    {
        if ($direction != 'desc') {
            $direction = 'asc';
        }

        if (is_array($index)) {
            $this->attributes['order'][] = $index;
        } else {
            $this->attributes['order'][] = [$index, $direction];
        }

        return $this;
    }