-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPagination.php
More file actions
91 lines (79 loc) · 2.49 KB
/
Pagination.php
File metadata and controls
91 lines (79 loc) · 2.49 KB
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
<?php
declare(strict_types=1);
/**
* This file is part of the EaseTWBootstrap3 package
*
* https://github.com/VitexSoftware/php-ease-twbootstrap
*
* (c) Vítězslav Dvořák <http://vitexsoftware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Ease\TWB;
class Pagination extends \Ease\Html\UlTag
{
/**
* Fragment adresy pro stránkování.
*/
public string $url = '?page=';
/**
* Stránkování Twitter Bootrstap.
*
* @param int $pages celkový počet stránek
* @param int $current aktuální stránka
* @param string $url Fragment adresy
*/
public function __construct($pages, $current = 0, $url = '?page=')
{
$this->url = $url;
parent::__construct(null, ['class' => 'pagination']);
if ($current === 0) {
$this->addPage('#', Part::glyphIcon('fast-backward'), 'disabled');
} else {
$this->addPage(0, Part::glyphIcon('fast-backward'));
}
if ($current === 0) {
$this->addPage('#', Part::glyphIcon('chevron-left'), 'disabled');
} else {
$this->addPage($current - 1, Part::glyphIcon('chevron-left'));
}
for ($page = 0; $page <= $pages - 1; ++$page) {
// Stavajici
if ($current === $page) {
$this->addPage($page, $page + 1, 'active');
} else {
$this->addPage($page, $page + 1);
}
}
if ($current >= $pages - 1) {
$this->addPage('#', Part::glyphIcon('chevron-right'), 'disabled');
} else {
$this->addPage($current + 1, Part::glyphIcon('chevron-right'));
}
if ($current >= $pages - 1) {
$this->addPage('#', Part::glyphIcon('fast-forward'), 'disabled');
} else {
$this->addPage($pages - 1, Part::glyphIcon('fast-forward'));
}
}
/**
* Přidá krok strankování.
*
* @param int $page
* @param string $label
* @param null|mixed $style
*/
public function addPage($page, $label = null, $style = null): void
{
$link = $this->url.$page;
if ($style) {
$this->addItemSmart(
new \Ease\Html\ATag($link, $label),
['class' => $style],
);
} else {
$this->addItemSmart(new \Ease\Html\ATag($link, $label));
}
}
}