public function getPagination($urlPattern, $maxDisplayPages=10) {
    if ($this->getPageCount() <= 1) {
      return null;
    }

    // calculate pages
    $getPage = function($val) use ($urlPattern) {
      return ['num' => $val, 'url' => str_replace('{page}', $val, $urlPattern)];
    };

    $first = 1;
    $last = $this->getPageCount();
    $page = $this->getPage();

    $halfRange = floor($maxDisplayPages/2);
    $startPage = ($page < $halfRange) ? $first : max([$page-$halfRange, $first]);
    $endPage = $maxDisplayPages-1 + $startPage;
    $endPage = ($last < $endPage) ? $last : $endPage;
    $diff = $startPage - $endPage + $maxDisplayPages-1;
    $startPage -= ($startPage - $diff > 0) ? $diff : 0;

    $pages = array_map($getPage, range($startPage, $endPage));

    return [
        'first' => $getPage($first),
        'last' => $getPage($last),
        'current' => $getPage($page),
        'prev' => $page > $startPage ? $getPage($page-1) : null,
        'next' => $page < $endPage ? $getPage($page+1) : null,
        'pages' => $pages,
    ];
  }