|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace mav3rick177\RapidPagination; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
|
6
|
|
|
use Illuminate\Contracts\Support\Jsonable; |
|
7
|
|
|
use Illuminate\Support\Collection; |
|
8
|
|
|
use Illuminate\Support\Str; |
|
9
|
|
|
use Illuminate\Support\Traits\Macroable; |
|
10
|
|
|
use mav3rick177\RapidPagination\Base\PaginationResult as BasePaginationResult; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* PaginationResult |
|
14
|
|
|
* |
|
15
|
|
|
* @see BasePaginationResult |
|
16
|
|
|
* @mixin Collection |
|
17
|
|
|
*/ |
|
18
|
|
|
class PaginationResult extends BasePaginationResult implements \JsonSerializable, Arrayable, Jsonable |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The view factory resolver callback. |
|
23
|
|
|
* |
|
24
|
|
|
* @var \Closure |
|
25
|
|
|
*/ |
|
26
|
|
|
protected static $viewFactoryResolver; |
|
27
|
|
|
|
|
28
|
|
|
use Macroable { |
|
29
|
|
|
__call as macroCall; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Make dynamic calls into the collection. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $method |
|
36
|
|
|
* @param array $parameters |
|
37
|
|
|
* @return mixed |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __call($method, array $parameters) |
|
40
|
|
|
{ |
|
41
|
|
|
if (static::hasMacro($method)) { |
|
42
|
|
|
return $this->macroCall($method, $parameters); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $this->records->$method(...$parameters); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Set URL for the previous page. |
|
50
|
|
|
* |
|
51
|
|
|
* @return string|null |
|
52
|
|
|
*/ |
|
53
|
|
|
public function makePreviousUrl($state) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->previousUrl = $this->url('prev', $state); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Set URL for the next page. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string|null |
|
62
|
|
|
*/ |
|
63
|
|
|
public function makeNextUrl($state) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->nextUrl = $this->url('next', $state); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Set URL for the next page. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string|null |
|
73
|
|
|
*/ |
|
74
|
|
|
public function setTabID($tab) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->tab = $tab; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get the URL. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function url($direction, $state) |
|
86
|
|
|
{ |
|
87
|
|
|
$uri = url()->current() . '?'. 'direction=' . $direction . '&state=' . $state . '&tab=' . $this->tab; |
|
88
|
|
|
return $uri; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get the instance as an array. |
|
93
|
|
|
* |
|
94
|
|
|
* @return array |
|
95
|
|
|
*/ |
|
96
|
|
|
public function toArray() |
|
97
|
|
|
{ |
|
98
|
|
|
$array = []; |
|
99
|
|
|
foreach (get_object_vars($this) as $key => $value) { |
|
100
|
|
|
$array[Str::snake($key)] = $value; |
|
101
|
|
|
} |
|
102
|
|
|
return $array; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Convert the object into something JSON serializable. |
|
107
|
|
|
* |
|
108
|
|
|
* @return mixed |
|
109
|
|
|
*/ |
|
110
|
|
|
public function jsonSerialize() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->toArray(); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Convert the object to its JSON representation. |
|
117
|
|
|
* |
|
118
|
|
|
* @param int $options |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
|
|
public function toJson($options = 0) |
|
122
|
|
|
{ |
|
123
|
|
|
return json_encode($this->jsonSerialize(), $options); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|