interface Sortable implements SS_List (View source)

deprecated 5.4.0 Will be merged into SS_List

Additional interface for SS_List classes that are sortable.

All methods in this interface are immutable - they should return new instances with the sort applied, rather than applying the sort in place

Methods

public
T[]
toArray()

Returns all the items in the list in an array.

from  SS_List
public
array
toNestedArray()

Returns the contents of the list as an array of maps.

from  SS_List
public
add(mixed $item)

Adds an item to the list, making no guarantees about where it will appear.

from  SS_List
public
remove(mixed $item)

Removes an item from the list.

from  SS_List
public
T|null
first()

Returns the first item in the list.

from  SS_List
public
T|null
last()

Returns the last item in the list.

from  SS_List
public
Map
map(string $keyfield = 'ID', string $titlefield = 'Title')

Returns a map of a key field to a value field of all the items in the list.

from  SS_List
public
T|null
find(string $key, mixed $value)

Returns the first item in the list where the key field is equal to the value.

from  SS_List
public
array
column(string $colName = "ID")

Returns an array of a single field value for all items in the list.

from  SS_List
public
T>
each(callable $callback)

Walks the list using the specified callback

from  SS_List
public
bool
canSortBy(string $by)

Returns TRUE if the list can be sorted by a field.

public
T>
sort()

Return a new instance of this list that is sorted by one or more fields. You can either pass in a single field name and direction, or a map of field names to sort directions.

public
T>
reverse()

Return a new instance of this list based on reversing the current sort.

Details

T[] toArray()

Returns all the items in the list in an array.

Return Value

T[]

array toNestedArray()

Returns the contents of the list as an array of maps.

Return Value

array

add(mixed $item)

Adds an item to the list, making no guarantees about where it will appear.

Parameters

mixed $item

remove(mixed $item)

Removes an item from the list.

Parameters

mixed $item

T|null first()

Returns the first item in the list.

Return Value

T|null

T|null last()

Returns the last item in the list.

Return Value

T|null

Map map(string $keyfield = 'ID', string $titlefield = 'Title')

Returns a map of a key field to a value field of all the items in the list.

Parameters

string $keyfield
string $titlefield

Return Value

Map

T|null find(string $key, mixed $value)

Returns the first item in the list where the key field is equal to the value.

Parameters

string $key
mixed $value

Return Value

T|null

array column(string $colName = "ID")

Returns an array of a single field value for all items in the list.

Parameters

string $colName

Return Value

array

T> each(callable $callback)

Walks the list using the specified callback

Parameters

callable $callback

Return Value

T>

bool canSortBy(string $by)

Returns TRUE if the list can be sorted by a field.

Parameters

string $by

Return Value

bool

T> sort()

Return a new instance of this list that is sorted by one or more fields. You can either pass in a single field name and direction, or a map of field names to sort directions.

Return Value

T>

Examples

$list = $list->sort('Name'); // default ASC sorting
$list = $list->sort('Name DESC'); // DESC sorting
$list = $list->sort('Name', 'ASC');
$list = $list->sort(array('Name'=>'ASC,'Age'=>'DESC'));

T> reverse()

Return a new instance of this list based on reversing the current sort.

Return Value

T>

Examples

$list = $list->reverse();