-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathVisualPaginator.php
65 lines (58 loc) · 1.77 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
<?php
namespace Crm\ApplicationModule\Components\VisualPaginator;
use Nette\Application\Attributes\Persistent;
use Nette\Application\UI\Control;
use Nette\Utils\Paginator;
/**
* Visual paginator control.
*
* Simple component used for rendering listing pagination.
*
* @author David Grudl
* @copyright Copyright (c) 2009 David Grudl
* @package Nette Extras
*/
class VisualPaginator extends Control
{
private Paginator $paginator;
#[Persistent]
public $page = 1;
/**
* @return Paginator
*/
public function getPaginator()
{
if (!isset($this->paginator)) {
$this->paginator = new Paginator;
}
return $this->paginator;
}
public function render($option1 = '', $option2 = 5)
{
$paginator = $this->getPaginator();
$page = $paginator->page;
if ($paginator->pageCount < 2) {
$steps = [$page];
} else {
$arr = range(max($paginator->firstPage, $page - $option2), min($paginator->lastPage, $page + $option2));
$count = 1;
$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->option1 = $option1;
$this->template->option2 = $option2;
$this->template->steps = $steps;
$this->template->paginator = $paginator;
$this->template->setFile(__DIR__ . '/bootstrap-paginator.latte');
$this->template->render();
}
public function loadState(array $params): void
{
parent::loadState($params);
$this->getPaginator()->page = $this->page;
}
}