Documentation

Pagination
in package

Pagination Helper - Reusable pagination class

Provides pagination calculations and utilities for displaying paginated content. Handles offset/limit calculations, page navigation, and URL generation.

Tags
author

Bdelive - Group 8

version
1.0.0

Table of Contents

Properties

$currentPage  : int
Current page number
$itemsPerPage  : int
Number of items per page
$totalItems  : int
Total number of items to paginate
$totalPages  : int
Total number of pages

Methods

__construct()  : void
Constructor - Initialize pagination
getCurrentPage()  : int
Get the current page number
getFirstPage()  : int
Get the first page number
getLastPage()  : int
Get the last page number
getLimit()  : int
Get the limit for database queries
getLink()  : string
Generate a URL link for a specific page number
getOffset()  : int
Get the offset for database queries
getTotalItems()  : int
Get the total number of items
getTotalPages()  : int
Get the total number of pages
hasNext()  : bool
Check if there is a next page
hasPrevious()  : bool
Check if there is a previous page

Properties

$currentPage

Current page number

private int $currentPage

$itemsPerPage

Number of items per page

private int $itemsPerPage

$totalItems

Total number of items to paginate

private int $totalItems

$totalPages

Total number of pages

private int $totalPages

Methods

__construct()

Constructor - Initialize pagination

public __construct(int $totalItems[, int $itemsPerPage = 10 ][, int|null $currentPage = null ]) : void

Calculates total pages and validates current page number. If current page is not provided, it reads from $_GET['p'] or defaults to 1.

Parameters
$totalItems : int

Total number of items to paginate

$itemsPerPage : int = 10

Number of items per page (default: 10)

$currentPage : int|null = null

Current page number (null to read from $_GET['p'])

getCurrentPage()

Get the current page number

public getCurrentPage() : int
Return values
int

Current page number (1-based)

getFirstPage()

Get the first page number

public getFirstPage() : int
Return values
int

Always returns 1

getLastPage()

Get the last page number

public getLastPage() : int
Return values
int

Last page number (total pages)

getLimit()

Get the limit for database queries

public getLimit() : int

Returns the number of items per page (LIMIT value for SQL).

Return values
int

The limit value (number of items per page)

Generate a URL link for a specific page number

public getLink(int $pageNumber) : string

Preserves existing query parameters and adds/updates the 'p' parameter.

Parameters
$pageNumber : int

The page number to generate a link for

Return values
string

URL with query parameters including the page number

getOffset()

Get the offset for database queries

public getOffset() : int

Calculates the OFFSET value for SQL LIMIT queries.

Return values
int

The offset value (number of items to skip)

getTotalItems()

Get the total number of items

public getTotalItems() : int
Return values
int

Total number of items

getTotalPages()

Get the total number of pages

public getTotalPages() : int
Return values
int

Total number of pages

hasNext()

Check if there is a next page

public hasNext() : bool
Return values
bool

True if there is a next page, false otherwise

hasPrevious()

Check if there is a previous page

public hasPrevious() : bool
Return values
bool

True if there is a previous page, false otherwise


        
On this page

Search results