1
|
<?php
|
2
|
|
3
|
namespace Illuminate\Pagination;
|
4
|
|
5
|
use Illuminate\Support\HtmlString;
|
6
|
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
|
7
|
use Illuminate\Contracts\Pagination\Presenter as PresenterContract;
|
8
|
|
9
|
class BootstrapThreePresenter implements PresenterContract
|
10
|
{
|
11
|
use BootstrapThreeNextPreviousButtonRendererTrait, UrlWindowPresenterTrait;
|
12
|
|
13
|
/**
|
14
|
* The paginator implementation.
|
15
|
*
|
16
|
* @var \Illuminate\Contracts\Pagination\Paginator
|
17
|
*/
|
18
|
protected $paginator;
|
19
|
|
20
|
/**
|
21
|
* The URL window data structure.
|
22
|
*
|
23
|
* @var array
|
24
|
*/
|
25
|
protected $window;
|
26
|
|
27
|
/**
|
28
|
* Create a new Bootstrap presenter instance.
|
29
|
*
|
30
|
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
|
31
|
* @param \Illuminate\Pagination\UrlWindow|null $window
|
32
|
* @return void
|
33
|
*/
|
34
|
public function __construct(PaginatorContract $paginator, UrlWindow $window = null)
|
35
|
{
|
36
|
$this->paginator = $paginator;
|
37
|
$this->window = is_null($window) ? UrlWindow::make($paginator) : $window->get();
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Determine if the underlying paginator being presented has pages to show.
|
42
|
*
|
43
|
* @return bool
|
44
|
*/
|
45
|
public function hasPages()
|
46
|
{
|
47
|
return $this->paginator->hasPages();
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Convert the URL window into Bootstrap HTML.
|
52
|
*
|
53
|
* @return \Illuminate\Support\HtmlString
|
54
|
*/
|
55
|
public function render()
|
56
|
{
|
57
|
if ($this->hasPages()) {
|
58
|
return new HtmlString(sprintf(
|
59
|
'<ul class="pagination">%s %s %s</ul>',
|
60
|
$this->getPreviousButton(),
|
61
|
$this->getLinks(),
|
62
|
$this->getNextButton()
|
63
|
));
|
64
|
}
|
65
|
|
66
|
return '';
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Get HTML wrapper for an available page link.
|
71
|
*
|
72
|
* @param string $url
|
73
|
* @param int $page
|
74
|
* @param string|null $rel
|
75
|
* @return string
|
76
|
*/
|
77
|
protected function getAvailablePageWrapper($url, $page, $rel = null)
|
78
|
{
|
79
|
$rel = is_null($rel) ? '' : ' rel="'.$rel.'"';
|
80
|
|
81
|
return '<li><a href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a></li>';
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Get HTML wrapper for disabled text.
|
86
|
*
|
87
|
* @param string $text
|
88
|
* @return string
|
89
|
*/
|
90
|
protected function getDisabledTextWrapper($text)
|
91
|
{
|
92
|
return '<li class="disabled"><span>'.$text.'</span></li>';
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Get HTML wrapper for active text.
|
97
|
*
|
98
|
* @param string $text
|
99
|
* @return string
|
100
|
*/
|
101
|
protected function getActivePageWrapper($text)
|
102
|
{
|
103
|
return '<li class="active"><span>'.$text.'</span></li>';
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Get a pagination "dot" element.
|
108
|
*
|
109
|
* @return string
|
110
|
*/
|
111
|
protected function getDots()
|
112
|
{
|
113
|
return $this->getDisabledTextWrapper('...');
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Get the current page from the paginator.
|
118
|
*
|
119
|
* @return int
|
120
|
*/
|
121
|
protected function currentPage()
|
122
|
{
|
123
|
return $this->paginator->currentPage();
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* Get the last page from the paginator.
|
128
|
*
|
129
|
* @return int
|
130
|
*/
|
131
|
protected function lastPage()
|
132
|
{
|
133
|
return $this->paginator->lastPage();
|
134
|
}
|
135
|
}
|