Skip to content

Instantly share code, notes, and snippets.

@lfbittencourt
Created April 23, 2014 16:57
Show Gist options
  • Save lfbittencourt/11223468 to your computer and use it in GitHub Desktop.
Save lfbittencourt/11223468 to your computer and use it in GitHub Desktop.
SimplePaginator class.
<?php
class SimplePaginator
{
protected $pageCount;
protected $pageRangeLength = 5;
public function __construct($pageCount, $pageRangeLength)
{
$this->pageCount = $pageCount;
$this->pageRangeLength = $pageRangeLength;
}
public function getPageRange($currentPage)
{
$pageRangeLength = min($this->pageCount, $this->pageRangeLength);
$firstPage = max(1, min(
$currentPage - floor($pageRangeLength / 2),
$this->pageCount - $pageRangeLength + 1
));
return range($firstPage, $firstPage + $pageRangeLength - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment