\Dewdrop\Fields\HelperSelectPaginate

This helper paginates a Select object so that a single page of a listing can be retrieved at a time. Yuo can adjust the number of records to return per page.

Helpers do this by enabling your to set custom callbacks for a field. In cases where a custom callback has not been assigned, helpers may attempt to automatically create a callback, using information in the field (e.g. the type of a database-related field).

For all helpers, you can assign custom callbacks globally or on a per-instance basis. Here's an example of defining a custom callback globally for a field:

$field->assignHelperCallback(
    'NameOfHelperToCustomize',
    function ($helper) {
        // Any custom logic you'd like to perform for this field.
    }
);

In the above example, "NameOfHelperToCustomize" is the name of the helper as defined in the helper's $name class property. This string is case insensitive.

To defined a custom callback on a per-instance basis for a helper, you can do the following:

$helper->assign(
    'my_model:field_id',
    function ($helper) {
        // Any custom logic you'd like to perform for this field.
    }
);

If you'd like to decorate an existing callback with additional logic, that's possible using the getFieldAssignment() method:

$field->assignHelperCallback(
    'NameOfHelperToCustomize',
    function ($helper) {
        return '' . call_user_func($helper->getFieldAssignment($field), $helper) . '';
    }
);

When a per-instance callback is assigned, that overrides any global or fallback callbacks. So, you can have an application-wide default (e.g. in a model) behavior for a field that is superseded in specific cases by adding a per-instance callback assignment for the field (e.g. in a view script).

Summary

Methods
Properties
Constants
matchesName()
assign()
getFieldAssignment()
hasValidName()
detectCallableForField()
__construct()
setPrefix()
isEnabled()
enable()
disable()
getPrefix()
getPage()
setPageSize()
getPageSize()
modifySelect()
No public properties found
No constants found
wrapCallable()
$name
N/A
No private methods found
$assignments
$enabled
$page
$pageSize
$request
$prefix
N/A

Properties

$name

$name : string

The name for this helper, used when you want to define a global custom callback for a given field

Type

string

$assignments

$assignments : array

Any per-instance callback assignments for this helper. This array will have field IDs as the keys and callables as the values.

Type

array

$enabled

$enabled : boolean

Whether modifications from this modifier should be applied at all.

Type

boolean

$page

$page : integer

The current page.

Type

integer

$pageSize

$pageSize : integer

The number of records to show per page.

Type

integer

$request

$request : \Dewdrop\Request

A Request object we can use to look up the current page.

Type

\Dewdrop\Request

$prefix

$prefix : string

A param prefix that can be used if you have multiple paginated listings displayed on a single page.

Type

string

Methods

matchesName()

matchesName(string  $name) : boolean

Check to see if the supplied input matches this helper's name (case-insensitive).

Parameters

string $name

Returns

boolean

assign()

assign(mixed  $assignments, callable  $callable = null) : \Dewdrop\Fields\Helper\HelperAbstract

Assign one more custom per-instance callbacks for this helper. If the $arguments param is an array, this method expects that the keys will be field IDs and the values will be callables, assigning custom callbacks for multiple fields in one call. If, however, $assignments is a string or a FieldInterface object, a single custom callback assignment will be made.

Parameters

mixed $assignments
callable $callable

Returns

\Dewdrop\Fields\Helper\HelperAbstract

getFieldAssignment()

getFieldAssignment(\Dewdrop\Fields\FieldInterface  $field) : callable

Get the callback that will be used for the given FieldInterface object.

Parameters

\Dewdrop\Fields\FieldInterface $field

Throws

\Dewdrop\Fields\Exception\HelperCallableNotAvailableForField

Returns

callable

hasValidName()

hasValidName() : boolean

Ensure the helper has a valid $name value. If not, throw an exception.

All helpers must have a name defined so that global custom callbacks can be added to fields.

Throws

\Dewdrop\Fields\Exception\HelperMustHaveName

Returns

boolean

detectCallableForField()

detectCallableForField(\Dewdrop\Fields\FieldInterface  $field) : false

There are no field-specific callables for pagination, so attempting to look them up always returns false.

If no callback candidate is found, just return false from this method, which will be detected by getFieldAssignment(), causing execution to halt.

Parameters

\Dewdrop\Fields\FieldInterface $field

Returns

false

__construct()

__construct(\Dewdrop\Request  $request) 

Provide the HTTP request object that can be used to determine which page is selected.

Parameters

\Dewdrop\Request $request

setPrefix()

setPrefix(string  $prefix) : $this

Set a prefix that can be used on HTTP parameters to avoid collisions with other paginated listings.

Parameters

string $prefix

Returns

$this

isEnabled()

isEnabled() : boolean

Check to see if this helper is enabled.

Returns

boolean

enable()

enable() : $this

Enable this modifier.

Returns

$this

disable()

disable() : $this

Disable this modifier.

Returns

$this

getPrefix()

getPrefix() : string

Get the HTTP param prefix.

Returns

string

getPage()

getPage() : integer

Get current page.

Returns

integer

setPageSize()

setPageSize(integer  $pageSize) : \Dewdrop\Fields\Helper\SelectPaginate

Set number of records displayed per page.

Parameters

integer $pageSize

Returns

\Dewdrop\Fields\Helper\SelectPaginate

getPageSize()

getPageSize() : integer

Get number of records displayed per page.

Returns

integer

modifySelect()

modifySelect(\Dewdrop\Fields  $fields, \Dewdrop\Db\Select  $select) : \Dewdrop\Db\Select

Using the supplied \Dewdrop\Fields and \Dewdrop\Db\Select, modify the Select to include only the current page with the correct number of records. The DB driver is used to ensure we can get the total number of records that _would_ have been returned had no pagination been applied after the query has been executed (using whatever facility is provided for that use in the specific RDBMS).

Parameters

\Dewdrop\Fields $fields
\Dewdrop\Db\Select $select

Throws

\Dewdrop\Exception

Returns

\Dewdrop\Db\Select

wrapCallable()

wrapCallable(callable  $callable, \Dewdrop\Fields\FieldInterface  $field = null) : callable

Wrap a field's callback to ensure that a reference to the helper is always supplied as the first argument to the callback.

Parameters

callable $callable
\Dewdrop\Fields\FieldInterface $field

Returns

callable