HasSortableRelations

HasSortableRelations trait

 trait Winter\Storm\Database\Traits\HasSortableRelations

Usage:

In the model class definition add:

use \Winter\Storm\Database\Traits\HasSortableRelations;

public $sortableRelations = ['relation_name' => 'sort_order_column'];

To set orders:

$model->setSortableRelationOrder($relationName, $recordIds, $recordOrders);

Methods

public getRelationSortOrderColumn (string $relationName) : string

Get the name of the "sort_order" column.

Parameters
Property Description
$relationName
string
Returns
string

public initializeHasSortableRelations () : void

Initialize the HasSortableRelations trait for this model.

Sets the sort_order value if a related model has been attached.

Returns
void

public setRelationOrder (string $relationName, string | integer | array $itemIds, array $itemOrders = []) : void

Set the sort order of records to the specified orders. If the orders is undefined, the record identifier is used.

Parameters
Property Description
$relationName
string
$itemIds
string | integer | array
$itemOrders
array
Returns
void

protected getSortableRelations () : array

Return all configured sortable relations.

Returns
array

protected updateRelationOrder (string $relationName, string | integer | Winter\Sorm\Database\Model $id, string $column, integer $order) : void

Update relation record sort_order.

Parameters
Property Description
$relationName
string
$id
string | integer | Winter\Sorm\Database\Model
$column
string
$order
integer
Returns
void
Copyright © 2024 Winter CMS