-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVisualPaginator.php
92 lines (75 loc) · 1.88 KB
/
VisualPaginator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Nette Framework Extras
*
* This source file is subject to the New BSD License.
*
* For more information please see http://extras.nettephp.com
*
* @copyright Copyright (c) 2009 David Grudl
* @license New BSD License
* @link http://extras.nettephp.com
* @package Nette Extras
* @version $Id: VisualPaginator.php 4 2009-07-14 15:22:02Z david@grudl.com $
*/
use Nette\Application\UI\Control;
use Nette\Utils\Paginator;
/**
* Visual paginator control.
*
* @author David Grudl
* @copyright Copyright (c) 2009 David Grudl
* @package Nette Extras
*/
class VisualPaginator extends Control
{
/** @var Paginator */
private $paginator;
/** @persistent */
public $page = 1;
/**
* @return Nette\Paginator
*/
public function getPaginator()
{
if (!$this->paginator) {
$this->paginator = new Paginator;
}
return $this->paginator;
}
/**
* Renders paginator.
* @return void
*/
public function render()
{
$paginator = $this->getPaginator();
$page = $paginator->page;
if ($paginator->pageCount < 2) {
$steps = array($page);
} else {
$arr = range(max($paginator->firstPage, $page - 3), min($paginator->lastPage, $page + 3));
$count = 4;
$quotient = ($paginator->pageCount - 1) / $count;
for ($i = 0; $i <= $count; $i++) {
$arr[] = round($quotient * $i) + $paginator->firstPage;
}
sort($arr);
$steps = array_values(array_unique($arr));
}
$this->template->steps = $steps;
$this->template->paginator = $paginator;
$this->template->setFile(dirname(__FILE__) . '/template.phtml');
$this->template->render();
}
/**
* Loads state informations.
* @param array
* @return void
*/
public function loadState(array $params)
{
parent::loadState($params);
$this->getPaginator()->page = $this->page;
}
}