protected function buildNumericPager()
{
$buttonType = $this->getButtonType();
$controls = $this->getControls();
$pageCount = $this->getPageCount();
$pageIndex = $this->getCurrentPageIndex() + 1;
$maxButtonCount = $this->getPageButtonCount();
$buttonCount = $maxButtonCount > $pageCount ? $pageCount : $maxButtonCount;
$startPageIndex = 1;
$endPageIndex = $buttonCount;
if ($pageIndex > $endPageIndex) {
$startPageIndex = (int) (($pageIndex - 1) / $maxButtonCount) * $maxButtonCount + 1;
if (($endPageIndex = $startPageIndex + $maxButtonCount - 1) > $pageCount) {
$endPageIndex = $pageCount;
}
if ($endPageIndex - $startPageIndex + 1 < $maxButtonCount) {
if (($startPageIndex = $endPageIndex - $maxButtonCount + 1) < 1) {
$startPageIndex = 1;
}
}
}
if ($startPageIndex > 1) {
if (($text = $this->getFirstPageText()) !== '') {
$button = $this->createPagerButton($buttonType, true, $text, self::CMD_PAGE_FIRST, '');
$controls->add($button);
$controls->add("\n");
}
$prevPageIndex = $startPageIndex - 1;
$button = $this->createPagerButton($buttonType, true, $this->getPrevPageText(), self::CMD_PAGE, "{$prevPageIndex}");
$controls->add($button);
$controls->add("\n");
}
for ($i = $startPageIndex; $i <= $endPageIndex; ++$i) {
if ($i === $pageIndex) {
$label = $this->createPagerButton($buttonType, false, "{$i}", self::CMD_PAGE, '');
$controls->add($label);
} else {
$button = $this->createPagerButton($buttonType, true, "{$i}", self::CMD_PAGE, "{$i}");
$controls->add($button);
}
if ($i < $endPageIndex) {
$controls->add("\n");
}
}
if ($pageCount > $endPageIndex) {
$controls->add("\n");
$nextPageIndex = $endPageIndex + 1;
$button = $this->createPagerButton($buttonType, true, $this->getNextPageText(), self::CMD_PAGE, "{$nextPageIndex}");
$controls->add($button);
if (($text = $this->getLastPageText()) !== '') {
$controls->add("\n");
$button = $this->createPagerButton($buttonType, true, $text, self::CMD_PAGE_LAST, '');
$controls->add($button);
}
}
}