class PaginatedList extends ListDecorator (View source)

A decorator that wraps around a data list in order to provide pagination.

Methods

__construct(SS_List $list, array|ArrayAccess $request = [])

Constructs a new paginated list instance around a list.

string
getPaginationGetVar()

Returns the GET var that is used to set the page start. This defaults to "start".

$this
setPaginationGetVar(string $var)

Sets the GET var used to set the page start.

int
getPageLength()

Returns the number of items displayed per page. This defaults to 10.

$this
setPageLength(int $length)

Set the number of items displayed per page. Set to zero to disable paging.

$this
setCurrentPage(int $page)

Sets the current page.

int
getPageStart()

Returns the offset of the item the current page starts at.

$this
setPageStart(int $start)

Sets the offset of the item that current page starts at. This should be a multiple of the page length.

int
getTotalItems()

Returns the total number of items in the unpaginated list.

$this
setTotalItems(int $items)

Sets the total number of items in the list. This is useful when doing custom pagination.

$this
setPaginationFromQuery(SQLSelect $query)

Sets the page length, page start and total items from a query object's limit, offset and unlimited count. The query MUST have a limit clause.

bool
getLimitItems()

Returns whether or not the underlying list is limited to the current pagination range when iterating.

$this
setLimitItems(bool $limit)

No description

getIterator()

No description

array
toArray()

No description

Pages(int $max = null)

Returns a set of links to all the pages in the list. This is useful for basic pagination.

PaginationSummary(int $context = 4)

Returns a summarised pagination which limits the number of pages shown around the current page for visually balanced.

int
CurrentPage()

No description

int
TotalPages()

No description

bool
MoreThanOnePage()

No description

bool
FirstPage()

No description

bool
NotFirstPage()

No description

bool
LastPage()

No description

bool
NotLastPage()

No description

int
FirstItem()

Returns the number of the first item being displayed on the current page. This is useful for things like "displaying 10-20".

int
LastItem()

Returns the number of the last item being displayed on this page.

string
FirstLink()

Returns a link to the first page.

string
LastLink()

Returns a link to the last page.

string
NextLink()

Returns a link to the next page, if there is another page after the current one.

string
PrevLink()

Returns a link to the previous page, if the first page is not currently active.

TotalItems()

Returns the total number of items in the list

setRequest(HTTPRequest|ArrayAccess $request)

Set the request object for this list

getRequest()

Get the request object for this list

Details

__construct(SS_List $list, array|ArrayAccess $request = [])

Constructs a new paginated list instance around a list.

Parameters

SS_List $list

The list to paginate. The getRange method will be used to get the subset of objects to show.

array|ArrayAccess $request

Either a map of request parameters or request object that the pagination offset is read from.

Exceptions

Exception

string getPaginationGetVar()

Returns the GET var that is used to set the page start. This defaults to "start".

If there is more than one paginated list on a page, it is necessary to set a different get var for each using {@link setPaginationGetVar()}.

Return Value

string

$this setPaginationGetVar(string $var)

Sets the GET var used to set the page start.

Parameters

string $var

Return Value

$this

int getPageLength()

Returns the number of items displayed per page. This defaults to 10.

Return Value

int

$this setPageLength(int $length)

Set the number of items displayed per page. Set to zero to disable paging.

Parameters

int $length

Return Value

$this

$this setCurrentPage(int $page)

Sets the current page.

Parameters

int $page

Page index beginning with 1

Return Value

$this

int getPageStart()

Returns the offset of the item the current page starts at.

Return Value

int

$this setPageStart(int $start)

Sets the offset of the item that current page starts at. This should be a multiple of the page length.

Parameters

int $start

Return Value

$this

int getTotalItems()

Returns the total number of items in the unpaginated list.

Return Value

int

$this setTotalItems(int $items)

Sets the total number of items in the list. This is useful when doing custom pagination.

Parameters

int $items

Return Value

$this

$this setPaginationFromQuery(SQLSelect $query)

Sets the page length, page start and total items from a query object's limit, offset and unlimited count. The query MUST have a limit clause.

Parameters

SQLSelect $query

Return Value

$this

bool getLimitItems()

Returns whether or not the underlying list is limited to the current pagination range when iterating.

By default the limit method will be called on the underlying list to extract the subset for the current page. In some situations, if the list is custom generated and already paginated you don't want to additionally limit the list. You can use {@link setLimitItems} to control this.

Return Value

bool

$this setLimitItems(bool $limit)

Parameters

bool $limit

Return Value

$this

Traversable getIterator()

Return Value

Traversable

array toArray()

Return Value

array

SS_List Pages(int $max = null)

Returns a set of links to all the pages in the list. This is useful for basic pagination.

By default it returns links to every page, but if you pass the $max parameter the number of pages will be limited to that number, centered around the current page.

Parameters

int $max

Return Value

SS_List

SS_List PaginationSummary(int $context = 4)

Returns a summarised pagination which limits the number of pages shown around the current page for visually balanced.

Example: 25 pages total, currently on page 6, context of 4 pages [prev] [1] ... [4] [5] [[6]] [7] [8] ... [25] [next]

Example template usage: <% if MyPages.MoreThanOnePage %> <% if MyPages.NotFirstPage %> <% end_if %> <% loop MyPages.PaginationSummary(4) %> <% if CurrentBool %> $PageNum <% else %> <% if Link %> $PageNum <% else %> ... <% end_if %> <% end_if %> <% end_loop %> <% if MyPages.NotLastPage %> <% end_if %> <% end_if %>

Parameters

int $context

The number of pages to display around the current page. The number should be event, as half the number of each pages are displayed on either side of the current one.

Return Value

SS_List

int CurrentPage()

Return Value

int

int TotalPages()

Return Value

int

bool MoreThanOnePage()

Return Value

bool

bool FirstPage()

Return Value

bool

bool NotFirstPage()

Return Value

bool

bool LastPage()

Return Value

bool

bool NotLastPage()

Return Value

bool

int FirstItem()

Returns the number of the first item being displayed on the current page. This is useful for things like "displaying 10-20".

Return Value

int

int LastItem()

Returns the number of the last item being displayed on this page.

Return Value

int

Returns a link to the first page.

Return Value

string

Returns a link to the last page.

Return Value

string

Returns a link to the next page, if there is another page after the current one.

Return Value

string

Returns a link to the previous page, if the first page is not currently active.

Return Value

string

TotalItems()

Returns the total number of items in the list

setRequest(HTTPRequest|ArrayAccess $request)

Set the request object for this list

Parameters

HTTPRequest|ArrayAccess $request

getRequest()

Get the request object for this list