order by.

@param $attribute
@param bool $desc 默认升序(false), 如需降序, 传入 true

@return static
503525
public function orderBy($attribute, bool $desc = false)
    {
        $this->collection = $this->collection->sortBy($attribute, SORT_REGULAR, $desc);

        return $this;
    }
699001
public function orderBy($field, $order = 'ASC')
    {
        if(is_string($field) && trim($field) != '') {
            $field = trim($field);
            $field = ltrim($field, 'ORDER BY ');
            $this->order = ' ORDER BY `'.$field.'`'.(($order == 'DESC') ? ' DESC' : ' ASC');
        }
        return $this;
    }
487158
public function order($order, $type = 'DESC')
    {

        $this->string['order'] .= $this->useBuilder('order')
            ->order($order, $type);

        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;
		}
758186
public function relatedByCategoryValues($values, $attribute = null)
    {
        return $this->anyCategoryValues($values, $attribute)->addOrderBy(new Expression('COUNT(*) DESC'));
    }
1285511
protected function mergeOrderByAttributes(array $attributes, $alias = null)
    {
        if (!$this->isWildCardSelection() && !empty($this->orderBy)) {
            $orderBy = $this->getAttributesForAlias(array_keys($this->orderBy), $alias);
            $lcAttributes = array_map('strtolower', $attributes);
            foreach ($orderBy as $attribute) {
                if (!in_array(strtolower($attribute), $lcAttributes)) {
                    $attributes[] = $attribute;
                }
            }
        }

        return $attributes;
    }
646465
final public function sort(array $attributes = array())
    {
        $productImage   = $this->find($attributes['movingId']);
        $positionEntity = $this->find($attributes['movedId']);

        if ($productImage instanceof ProductImage) {
            if ($this->fireEvent('sorting', array($productImage)) === false) {
                return false;
            }

            $productImage->setCaller($this);
            $productImage->{$attributes['type']}($positionEntity);

            $this->fireEvent('sorted', array($productImage));

            return $productImage;
        }

        throw new Exception(sprintf(Exception::CANT_UPDATE_MODEL,
            'Subbly\\Model\\Product',
            $this->name()
        ));
    }
731978
public function sort($order = 'asc')
    {
        if ($order == 'desc') {
            rsort($this->_map);
        }else{
            sort($this->_map);
        }

        return $this;
    }
615163
public function attributeUseHandler(
        string $attribute,
        Type\HandlerDeserializerInterface $deserialize,
        Type\HandlerSerializerInterface $serialize
    ): ObjectInterface {
        return $this;
    }
153223
public function order($field, $order = 'desc')
    {
        $field = $this->model->field($field);
        $order = $this->normalizeOrder($order);

        $this->builder->addOrderBy($this->connection->quoteIdentifier($field->mappedName()), $order);

        return $this;
    }
802692
public function getRank(string $key, bool $desc = false): ?int
    {
        //获取降序排名
        if ($desc) {
            return $this->handle->zRevRank($this->name, $key);
        }

        //获取升序排名
        return $this->handle->zRank($this->name, $key);
    }
542379
final public function sort(array $attributes = array())
    {
        $category       = $this->find($attributes['movingId']);
        $positionEntity = $this->find($attributes['movedId']);

        if ($category instanceof Category) {
            if ($this->fireEvent('sorting', array($category)) === false) {
                return false;
            }

            $category->setCaller($this);
            $category->{$attributes['type']}($positionEntity);

            $this->fireEvent('sorted', array($category));

            return $category;
        }

        throw new Exception(sprintf(Exception::CANT_UPDATE_MODEL,
            'Subbly\\Model\\Category',
            $this->name()
        ));
    }
138463
public function removeAttribute(Attribute $attribute)
    {
        foreach ($this->attributes as $key => $attributeElement) {
            if ($attributeElement === $attribute) {
                unset($this->attributes[$key]);
                break;
            }
        }

        return $this;
    }
957193
protected static function firstByAttributes($attributes)
	{
		$query = static::query();

		foreach ($attributes as $key => $value)
		{
			$query->where($key, $value);
		}

		return $query->first() ?: null;
	}
869039
final protected function order_by($column, $order = 'ASC'){
        $order = 'DESC' === strtoupper($order) ? 'DESC' : 'ASC';
        $this->_order_by[] = sprintf('%s %s', $this->escape_column_name($column), $order);
        return $this;
    }
1199729
public function orderBy($column, $type = 'asc')
    {
        if (! is_null($this->order)) {
            return $this;
        }

        if (!in_array($type, ['asc', 'desc'])) {
            $type = 'asc';
        }

        $this->order = 'order by `'.$column.'` '.$type;

        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;
    }