October\Rain\Database\Traits\Sortable

Overview

Sortable model trait

Usage:

Model table must have sort_order table column.

In the model class definition:

use \October\Rain\Database\Traits\Sortable;

To set orders:

$model->setSortableOrder($recordIds, $recordOrders);

You can change the sort field used by declaring:

const SORT_ORDER = 'my_sort_order';


Public Methods

public static bootSortable()

public static bootSortable(): void

bootSortable trait for this model.

public getQualifiedSortOrderColumn()

public getQualifiedSortOrderColumn(): string 

getQualifiedSortOrderColumn gets the fully qualified "sort order" column.

public getSortOrderColumn()

public getSortOrderColumn(): string 

getSortOrderColumn name of the "sort order" column.

public initializeSortable()

public initializeSortable(): void

initializeSortable trait for this model.

public resetSortableOrdering()

public resetSortableOrdering(): void

resetSortableOrdering can be used to repair corrupt or missing sortable definitions.

public setSortableOrder()

public setSortableOrder(
    mixed $itemIds,
    array|null|bool $referencePool = null
): void 

setSortableOrder sets the sort order of records to the specified orders, supplying a reference pool of sorted values. If reference pool is true, then an incrementing pool is used.

Protected Methods

protected processSortableOrdersInternal()

protected processSortableOrdersInternal(
    $itemIds,
    $referencePool = null
): array