Skip to content

Commit

Permalink
Fixed #2812. New Pagination View: "floating".
Browse files Browse the repository at this point in the history
  • Loading branch information
Geert De Deckere authored and ryross committed Jun 13, 2010
1 parent bc26d1d commit 112e752
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions views/pagination/floating.php
@@ -0,0 +1,94 @@
<?php
/*
First Previous 1 2 3 ... 22 23 24 25 26 [27] 28 29 30 31 32 ... 48 49 50 Next Last
*/

// Number of page links in the begin and end of whole range
$count_out = ( ! empty($config['count_out'])) ? (int) $config['count_out'] : 3;
// Number of page links on each side of current page
$count_in = ( ! empty($config['count_in'])) ? (int) $config['count_in'] : 5;

// Beginning group of pages: $n1...$n2
$n1 = 1;
$n2 = min($count_out, $total_pages);

// Ending group of pages: $n7...$n8
$n7 = max(1, $total_pages - $count_out + 1);
$n8 = $total_pages;

// Middle group of pages: $n4...$n5
$n4 = max($n2 + 1, $current_page - $count_in);
$n5 = min($n7 - 1, $current_page + $count_in);
$use_middle = ($n5 >= $n4);

// Point $n3 between $n2 and $n4
$n3 = (int) (($n2 + $n4) / 2);
$use_n3 = ($use_middle && (($n4 - $n2) > 1));

// Point $n6 between $n5 and $n7
$n6 = (int) (($n5 + $n7) / 2);
$use_n6 = ($use_middle && (($n7 - $n5) > 1));

// Links to display as array(page => content)
$links = array();

// Generate links data in accordance with calculated numbers
for ($i = $n1; $i <= $n2; $i++)
{
$links[$i] = $i;
}
if ($use_n3)
{
$links[$n3] = '&hellip;';
}
for ($i = $n4; $i <= $n5; $i++)
{
$links[$i] = $i;
}
if ($use_n6)
{
$links[$n6] = '&hellip;';
}
for ($i = $n7; $i <= $n8; $i++)
{
$links[$i] = $i;
}

?>
<p class="pagination">

<?php if ($first_page !== FALSE): ?>
<a href="<?php echo $page->url($first_page) ?>"><?php echo __('First') ?></a>
<?php else: ?>
<?php echo __('First') ?>
<?php endif ?>

<?php if ($previous_page !== FALSE): ?>
<a href="<?php echo $page->url($previous_page) ?>"><?php echo __('Previous') ?></a>
<?php else: ?>
<?php echo __('Previous') ?>
<?php endif ?>

<?php foreach ($links as $number => $content): ?>

<?php if ($number === $current_page): ?>
<strong><?php echo $content ?></strong>
<?php else: ?>
<a href="<?php echo $page->url($number) ?>"><?php echo $content ?></a>
<?php endif ?>

<?php endforeach ?>

<?php if ($next_page !== FALSE): ?>
<a href="<?php echo $page->url($next_page) ?>"><?php echo __('Next') ?></a>
<?php else: ?>
<?php echo __('Next') ?>
<?php endif ?>

<?php if ($last_page !== FALSE): ?>
<a href="<?php echo $page->url($last_page) ?>"><?php echo __('Last') ?></a>
<?php else: ?>
<?php echo __('Last') ?>
<?php endif ?>

</p><!-- .pagination -->

0 comments on commit 112e752

Please sign in to comment.