class PaginationService (View source)

Builds Pagination objects and resolves the rows-per-page value within the allowed bounds.

Constants

MIN_ROWS_PER_PAGE

MAX_ROWS_PER_PAGE

ROWS_PER_PAGE_PRESETS

Offered in the page-size dropdowns; any value within the bounds is still honoured.

DEFAULT_ROWS_PER_PAGE

Methods

__construct(UserPreferenceService|null $userPreferenceService = null)

No description

createPagination(int $totalItems, int $itemsPerPage, int $currentPage)

Create a pagination object with proper validation

int
getUserRowsPerPage(int $defaultRowsPerPage, int|null $userId, int|null $requestedRowsPerPage)

Resolves the page size: the value the request asked for wins and is stored as the user's preference, otherwise the stored preference, otherwise the configured default.

static int|null
acceptedRowsPerPage(mixed $submitted)

A submitted page size, when it is a number inside the supported range; any value in range is accepted, not only the presets.

static array
pagerWindow(int $total, int $rowAmount, int $currentPage)

Sliding window of up to nine page links centred on the current page, with break indicators when the window does not touch the first or last page.

array
getRowsPerPageOptions(int ...$extra)

Page sizes to offer, so the current and configured values are always selectable.

Details

__construct(UserPreferenceService|null $userPreferenceService = null)

No description

Parameters

UserPreferenceService|null $userPreferenceService

Pagination createPagination(int $totalItems, int $itemsPerPage, int $currentPage)

Create a pagination object with proper validation

Parameters

int $totalItems
int $itemsPerPage
int $currentPage

Return Value

Pagination

int getUserRowsPerPage(int $defaultRowsPerPage, int|null $userId, int|null $requestedRowsPerPage)

Resolves the page size: the value the request asked for wins and is stored as the user's preference, otherwise the stored preference, otherwise the configured default.

Parameters

int $defaultRowsPerPage

Default rows per page from config

int|null $userId

User ID to get preferences for

int|null $requestedRowsPerPage

Page size from the query string (Request::getRowsPerPage())

Return Value

int

Validated rows per page value

static int|null acceptedRowsPerPage(mixed $submitted)

A submitted page size, when it is a number inside the supported range; any value in range is accepted, not only the presets.

Parameters

mixed $submitted

Return Value

int|null

static array pagerWindow(int $total, int $rowAmount, int $currentPage)

Sliding window of up to nine page links centred on the current page, with break indicators when the window does not touch the first or last page.

Deliberately not the Pagination model: that one shifts the window left near the last page, which would change what the search pager renders.

Parameters

int $total
int $rowAmount
int $currentPage

Return Value

array

array getRowsPerPageOptions(int ...$extra)

Page sizes to offer, so the current and configured values are always selectable.

Parameters

int ...$extra

Return Value

array