-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
LengthAwarePaginator.php
127 lines (107 loc) · 2.67 KB
/
LengthAwarePaginator.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace Log1x\Pagi;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\HtmlString;
use Illuminate\Pagination\LengthAwarePaginator as Paginator;
class LengthAwarePaginator extends Paginator
{
/**
* The default pagination view.
*
* @var string
*/
public static $defaultView = 'pagi::pagination';
/**
* The default "simple" pagination view.
*
* @var string
*/
public static $defaultSimpleView = 'pagi::pagination';
/**
* Get the URL for a given page number.
*
* @param int $page
* @return string
*/
public function url($page)
{
if ($page <= 0) {
$page = 1;
}
$url = get_pagenum_link($page, false);
if (count($this->query) > 0) {
return $url .
(Str::contains($url, '?') ? '&' : '?') .
Arr::query($this->query) .
$this->buildFragment();
}
return $url;
}
/**
* Get the URL for the next page.
*
* @return string|null
*/
public function nextPageUrl()
{
global $paged;
if (is_single()) {
return;
}
$paged = empty($paged) ? 1 : $paged;
$nextPage = (int) $paged + 1;
$maxPages = count($this->items);
if (! $maxPages || $maxPages >= $nextPage) {
return get_pagenum_link($nextPage, false);
}
}
/**
* Get the URL for the previous page.
*
* @return string|null
*/
public function previousPageUrl()
{
global $paged;
if (is_single()) {
return;
}
$nextPage = (int) $paged - 1;
$nextPage = $nextPage < 1 ? 1 : $nextPage;
return get_pagenum_link($nextPage, false);
}
/**
* Render the paginator using the given view.
*
* @param string|null $view
* @param array $data
* @return \Illuminate\Contracts\Support\Htmlable
*/
public function links($view = null, $data = [])
{
return $this->render($view, $data);
}
/**
* Render the paginator using the given view.
*
* @param string|null $view
* @param array $data
* @return \Illuminate\Contracts\Support\Htmlable
*/
public function render($view = null, $data = [])
{
return new HtmlString(static::viewFactory()->make($view ?: static::$defaultView, array_merge($data, [
'pagi' => $this,
]))->render());
}
/**
* Get the array of elements to pass to the view.
*
* @return array
*/
public function elements()
{
return parent::elements();
}
}