src/ORM/PaginatedList.php
public function PaginationSummary($context = 4)
    {
        $result = new ArrayList();
        $current = $this->CurrentPage();
        $total = $this->TotalPages();

        // Make the number even for offset calculations.
        if ($context % 2) {
            $context--;
        }

        // If the first or last page is current, then show all context on one
        // side of it - otherwise show half on both sides.
        if ($current == 1 || $current == $total) {
            $offset = $context;
        } else {
            $offset = floor($context / 2);
        }

        $left = max($current - $offset, 1);
        $right = min($current + $offset, $total);
        $range = range($current - $offset, $current + $offset);

        if ($left + $context > $total) {
            $left = $total - $context;
        }

        for ($i = 0; $i < $total; $i++) {
            $link = HTTP::setGetVar(
                $this->getPaginationGetVar(),
                $i * $this->getPageLength(),
                ($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
            );
            $num = $i + 1;

            $emptyRange = $num != 1 && $num != $total && (
                $num == $left - 1 || $num == $right + 1
            );

            if ($emptyRange) {
                $result->push(new ArrayData(array(
                    'PageNum' => null,
                    'Link' => null,
                    'CurrentBool' => false
                )));
            } elseif ($num == 1 || $num == $total || in_array($num, $range)) {
                $result->push(new ArrayData(array(
                    'PageNum' => $num,
                    'Link' => $link,
                    'CurrentBool' => $current == $num
                )));
            }
        }

        return $result;
    }
public function PaginationSummary($context = 4)
    {
        $result = new ArrayList();
        $current = $this->CurrentPage();
        $total = $this->TotalPages();

        // Make the number even for offset calculations.
        if ($context % 2) {
            $context--;
        }

        // If the first or last page is current, then show all context on one
        // side of it - otherwise show half on both sides.
        if ($current == 1 || $current == $total) {
            $offset = $context;
        } else {
            $offset = floor($context / 2);
        }

        $left = max($current - $offset, 1);
        $right = min($current + $offset, $total);
        $range = range($current - $offset, $current + $offset);

        if ($left + $context > $total) {
            $left = $total - $context;
        }

        for ($i = 0; $i < $total; $i++) {
            $link = HTTP::setGetVar(
                $this->getPaginationGetVar(),
                $i * $this->getPageLength(),
                ($this->request instanceof HTTPRequest) ? $this->request->getURL(true) : null
            );
            $num = $i + 1;

            $emptyRange = $num != 1 && $num != $total && (
                $num == $left - 1 || $num == $right + 1
            );

            if ($emptyRange) {
                $result->push(new ArrayData(array(
                    'PageNum' => null,
                    'Link' => null,
                    'CurrentBool' => false
                )));
            } elseif ($num == 1 || $num == $total || in_array($num, $range)) {
                $result->push(new ArrayData(array(
                    'PageNum' => $num,
                    'Link' => $link,
                    'CurrentBool' => $current == $num
                )));
            }
        }

        return $result;
    }
public function PaginationSummary ( $ context = 4 ) { $ result = new ArrayList ( ) ; $ current = $ this -> CurrentPage ( ) ; $ total = $ this -> TotalPages ( ) ; // Make the number even for offset calculations. if ( $ context % 2 ) { $ context -- ; } // If the first or last page is current, then show all context on one // side of it - otherwise show half on both sides. if ( $ current == 1 || $ current == $ total ) { $ offset = $ context ; } else { $ offset = floor ( $ context / 2 ) ; } $ left = max ( $ current - $ offset , 1 ) ; $ right = min ( $ current + $ offset , $ total ) ; $ range = range ( $ current - $ offset , $ current + $ offset ) ; if ( $ left + $ context > $ total ) { $ left = $ total - $ context ; } for ( $ i = 0 ; $ i < $ total ; $ i ++ ) { $ link = HTTP :: setGetVar ( $ this -> getPaginationGetVar ( ) , $ i * $ this -> getPageLength ( ) , ( $ this -> request instanceof HTTPRequest ) ? $ this -> request -> getURL ( true ) : null ) ; $ num = $ i + 1 ; $ emptyRange = $ num != 1 && $ num != $ total && ( $ num == $ left - 1 || $ num == $ right + 1 ) ; if ( $ emptyRange ) { $ result -> push ( new ArrayData ( array ( 'PageNum' => null , 'Link' => null , 'CurrentBool' => false ) ) ) ; } elseif ( $ num == 1 || $ num == $ total || in_array ( $ num , $ range ) ) { $ result -> push ( new ArrayData ( array ( 'PageNum' => $ num , 'Link' => $ link , 'CurrentBool' => $ current == $ num ) ) ) ; } } return $ result ; }
Returns a summarised pagination which limits the number of pages shown
around the current page for visually balanced.

Example: 25 pages total, currently on page 6, context of 4 pages
[prev] [1] ... [4] [5] [[6]] [7] [8] ... [25] [next]

Example template usage:
<code>
<% if MyPages.MoreThanOnePage %>
<% if MyPages.NotFirstPage %>
<a class="prev" href="$MyPages.PrevLink">Prev</a>
<% end_if %>
<% loop MyPages.PaginationSummary(4) %>
<% if CurrentBool %>
$PageNum
<% else %>
<% if Link %>
<a href="$Link">$PageNum</a>
<% else %>
...
<% end_if %>
<% end_if %>
<% end_loop %>
<% if MyPages.NotLastPage %>
<a class="next" href="$MyPages.NextLink">Next</a>
<% end_if %>
<% end_if %>
</code>

@param  int $context The number of pages to display around the current
page. The number should be event, as half the number of each pages
are displayed on either side of the current one.
@return SS_List
Returns a summarised pagination which limits the number of pages shown around the current page for visually balanced .