• Full name: \App\Infrastructure\Services\Paginator

Constants

Constant Visibility Type Value
NUM_PLACEHOLDER public '(:num)'

Properties

totalItems

protected int $totalItems

numPages

protected int $numPages

itemsPerPage

protected int $itemsPerPage

currentPage

protected int $currentPage

urlPattern

protected ?string $urlPattern

maxPagesToShow

protected int $maxPagesToShow

previousText

protected string $previousText

nextText

protected string $nextText

Methods

__construct

public __construct(int $totalItems, int $itemsPerPage, int $currentPage, string $urlPattern = ''): mixed

Parameters:

Parameter Type Description
$totalItems int The total number of items.
$itemsPerPage int The number of items per page.
$currentPage int The current page number.
$urlPattern string A URL for each page, with (:num) as a placeholder
for the page number. Ex. '/foo/page/(:num)'

updateNumPages

protected updateNumPages(): void

setMaxPagesToShow

public setMaxPagesToShow(int $maxPagesToShow): void

Parameters:

Parameter Type Description
$maxPagesToShow int

Throws:

if $maxPagesToShow is less than 3. - TypeException


getMaxPagesToShow

public getMaxPagesToShow(): int

setCurrentPage

public setCurrentPage(int $currentPage): void

Parameters:

Parameter Type Description
$currentPage int

getCurrentPage

public getCurrentPage(): int

setItemsPerPage

public setItemsPerPage(int $itemsPerPage): void

Parameters:

Parameter Type Description
$itemsPerPage int

getItemsPerPage

public getItemsPerPage(): int

setTotalItems

public setTotalItems(int $totalItems): void

Parameters:

Parameter Type Description
$totalItems int

getTotalItems

public getTotalItems(): int

getNumPages

public getNumPages(): int

setUrlPattern

public setUrlPattern(string $urlPattern): void

Parameters:

Parameter Type Description
$urlPattern string

getUrlPattern

public getUrlPattern(): string|null

getPageUrl

public getPageUrl(int $pageNum): string

Parameters:

Parameter Type Description
$pageNum int

getNextPage

public getNextPage(): ?int

getPrevPage

public getPrevPage(): ?int

getNextUrl

public getNextUrl(): ?string

getPrevUrl

public getPrevUrl(): string|null

getPages

Get an array of paginated page data.

public getPages(): array

Example: [ ['num' => 1, 'url' => '/example/page/1', 'isCurrent' => false], ['num' => '...', 'url' => NULL, 'isCurrent' => false], ['num' => 3, 'url' => '/example/page/3', 'isCurrent' => false], ['num' => 4, 'url' => '/example/page/4', 'isCurrent' => true ], ['num' => 5, 'url' => '/example/page/5', 'isCurrent' => false], ['num' => '...', 'url' => NULL, 'isCurrent' => false], ['num' => 10, 'url' => '/example/page/10', 'isCurrent' => false], ]


createPage

Create a page data structure.

protected createPage(int $pageNum, bool $isCurrent = false): array

Parameters:

Parameter Type Description
$pageNum int
$isCurrent bool

createPageEllipsis

protected createPageEllipsis(): array

toHtml

Render an HTML pagination control.

public toHtml(): string

__toString

public __toString(): mixed

getCurrentPageFirstItem

public getCurrentPageFirstItem(): float|int|null

getCurrentPageLastItem

public getCurrentPageLastItem(): float|int|null

setPreviousText

public setPreviousText(string $text): static

Parameters:

Parameter Type Description
$text string

setNextText

public setNextText(string $text): static

Parameters:

Parameter Type Description
$text string