Documentation

PaginationResult
in package

PaginationResult Class

Wrapper class for paginated API responses that provides access to data and pagination metadata. This class encapsulates the results of a paginated API call along with navigation links and metadata extracted from Canvas API Link headers.

Usage:

$result = Course::fetchAllPaginated(['per_page' => 50]);
$courses = $result->getData();

if ($result->hasNext()) {
    $nextResult = $result->getNext();
}

echo "Page {$result->getCurrentPage()} of {$result->getTotalPages()}";

Table of Contents

Properties

$currentPage  : int
Current page number
$currentUrl  : string|null
URL for the current page of results
$data  : array<string|int, mixed>
The actual data from the API response
$firstUrl  : string|null
URL for the first page of results
$lastUrl  : string|null
URL for the last page of results
$nextUrl  : string|null
URL for the next page of results
$perPage  : int|null
Number of items per page
$prevUrl  : string|null
URL for the previous page of results
$totalPages  : int|null
Total number of pages (if determinable)

Methods

__construct()  : mixed
PaginationResult constructor
fromLinkHeader()  : self
Create PaginationResult from Link header
getCount()  : int
Get the number of items in the current page
getCurrentPage()  : int
Get the current page number
getCurrentUrl()  : string|null
Get the URL for the current page
getData()  : array<string|int, mixed>
Get the data from the API response
getFirstUrl()  : string|null
Get the URL for the first page
getLastUrl()  : string|null
Get the URL for the last page
getNavigationUrls()  : array<string|int, string>
Get all navigation URLs
getNextUrl()  : string|null
Get the URL for the next page
getPerPage()  : int|null
Get the number of items per page
getPrevUrl()  : string|null
Get the URL for the previous page
getSummary()  : string
Get pagination summary string
getTotalPages()  : int|null
Get the total number of pages
hasMore()  : bool
Check if there are more pages available
hasNext()  : bool
Check if there is a next page
hasPrev()  : bool
Check if there is a previous page
isEmpty()  : bool
Check if the current page is empty
isFirstPage()  : bool
Check if this is the first page
isLastPage()  : bool
Check if this is the last page
toArray()  : array<string|int, mixed>
Convert to array representation

Properties

$currentUrl

URL for the current page of results

private string|null $currentUrl

$data

The actual data from the API response

private array<string|int, mixed> $data

$firstUrl

URL for the first page of results

private string|null $firstUrl

$prevUrl

URL for the previous page of results

private string|null $prevUrl

$totalPages

Total number of pages (if determinable)

private int|null $totalPages

Methods

__construct()

PaginationResult constructor

public __construct(array<string|int, mixed> $data[, array<string|int, string> $navigationLinks = [] ][, int $currentPage = 1 ][, int|null $totalPages = null ][, int|null $perPage = null ]) : mixed
Parameters
$data : array<string|int, mixed>

The API response data

$navigationLinks : array<string|int, string> = []

Associative array of navigation URLs

$currentPage : int = 1

Current page number

$totalPages : int|null = null

Total number of pages

$perPage : int|null = null

Items per page

fromLinkHeader()

Create PaginationResult from Link header

public static fromLinkHeader(array<string|int, mixed> $data, string $linkHeader) : self
Parameters
$data : array<string|int, mixed>

The API response data

$linkHeader : string

The Link header string

Return values
self

getCount()

Get the number of items in the current page

public getCount() : int
Return values
int

getCurrentPage()

Get the current page number

public getCurrentPage() : int
Return values
int

getCurrentUrl()

Get the URL for the current page

public getCurrentUrl() : string|null
Return values
string|null

getData()

Get the data from the API response

public getData() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFirstUrl()

Get the URL for the first page

public getFirstUrl() : string|null
Return values
string|null

getLastUrl()

Get the URL for the last page

public getLastUrl() : string|null
Return values
string|null

getNavigationUrls()

Get all navigation URLs

public getNavigationUrls() : array<string|int, string>
Return values
array<string|int, string>

getNextUrl()

Get the URL for the next page

public getNextUrl() : string|null
Return values
string|null

getPerPage()

Get the number of items per page

public getPerPage() : int|null
Return values
int|null

getPrevUrl()

Get the URL for the previous page

public getPrevUrl() : string|null
Return values
string|null

getSummary()

Get pagination summary string

public getSummary() : string
Return values
string

getTotalPages()

Get the total number of pages

public getTotalPages() : int|null
Return values
int|null

hasMore()

Check if there are more pages available

public hasMore() : bool
Return values
bool

hasNext()

Check if there is a next page

public hasNext() : bool
Return values
bool

hasPrev()

Check if there is a previous page

public hasPrev() : bool
Return values
bool

isEmpty()

Check if the current page is empty

public isEmpty() : bool
Return values
bool

isFirstPage()

Check if this is the first page

public isFirstPage() : bool
Return values
bool

isLastPage()

Check if this is the last page

public isLastPage() : bool
Return values
bool

toArray()

Convert to array representation

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results