Documentation

Paginator
in package

This class is the base for the database query pagination inside of Spitfire.

It provides the necessary tools to generate a list of pages inside your applications so queries aren't able to collapse your system / clients.

By default this class includes a getEmpty method that returns a message when no results are available. Although it is not a good practice to allow classes perform actions that aren't strictly related to their task. But the improvement on readability gained in Views is worth the change.

Tags
link

Related data and tutorials

todo

Somehow this class should cache the counts, so the database doesn't need to read the data every time.

todo

This class should help paginating without the use of LIMIT

todo

Update the pertinent documentation on the wiki

Table of Contents

$distance  : int
The distance suggests spitfire the amount of pages a user should be able to jump from the current page.
$io  : PaginationInterface
This property allows the paginator to communicate with the user to retrieve the current page and present a set of options to jump to another page.
$pageSize  : int
The number of records to be fit in a single page. Once the number of records is exceeded, another page is added.
$query  : Query
The query to paginate. The offset and limit properties of the query may be overwritten by the paginator.
__construct()  : mixed
Paginates a query. Paginating is the process in which a query that delivers a resultset too large to be properly transferred over a network or fit into a window is broken into individual pages.
__toString()  : string
This method makes it quick and comfortable to present the pagination, just by running <code>echo $pagination;</code> wherever your application whishes to present the pages.
getPageCount()  : int
Estimates the number of pages needed to fit all the results for this query.
pages()  : Collection
This function calculates the pages to be displayed in the pagination. It calculates the ideal amount of pages to be displayed (based on the max you want) and generates an array with the numbers for those pages.
records()  : mixed
Gets the records that populate the current page.

Properties

$distance

The distance suggests spitfire the amount of pages a user should be able to jump from the current page.

private int $distance = 3

When there's enough pages, the user should be able to jump at least (distance) and at most (distance * 2).

$io

This property allows the paginator to communicate with the user to retrieve the current page and present a set of options to jump to another page.

private PaginationInterface $io

$pageSize

The number of records to be fit in a single page. Once the number of records is exceeded, another page is added.

private int $pageSize

$query

The query to paginate. The offset and limit properties of the query may be overwritten by the paginator.

private Query $query

Methods

__construct()

Paginates a query. Paginating is the process in which a query that delivers a resultset too large to be properly transferred over a network or fit into a window is broken into individual pages.

public __construct(Query $query[, PaginationInterface $io = null ][, int $pageSize = 20 ]) : mixed
Parameters
$query : Query
$io : PaginationInterface = null
$pageSize : int = 20
Return values
mixed

__toString()

This method makes it quick and comfortable to present the pagination, just by running <code>echo $pagination;</code> wherever your application whishes to present the pages.

public __toString() : string

Please note, the pagination will also render HTML whenever your query returns an empty result. Therefore, you don't need to check whether the result set is empty or not.

Return values
string

getPageCount()

Estimates the number of pages needed to fit all the results for this query.

public getPageCount() : int
Return values
int

pages()

This function calculates the pages to be displayed in the pagination. It calculates the ideal amount of pages to be displayed (based on the max you want) and generates an array with the numbers for those pages.

public pages() : Collection

If you use the default distance of 3 you will always receive up to 9 pages. Those include the first, the last, the current and the three higher and lower pages. For page 7/20 you will receive (1,4,5,6,7,8,9,10,20).

In case the pagination doesn't find enough elements whether on the right or left it will try to extend this with results on the other one. This avoids broken looking paginations when reaching the final results of a set.

Return values
Collection

records()

Gets the records that populate the current page.

public records() : mixed
Return values
mixed

Search results