|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** PaginationList.php */ |
|
11
|
|
|
namespace Applications\Repository; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* class for accessing a pagination list. |
|
15
|
|
|
*/ |
|
16
|
|
|
class PaginationList |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* List of ids. |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $ids = array(); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Pointer |
|
27
|
|
|
* @var int|bool |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $pointer = false; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Count of list items |
|
33
|
|
|
* @var int |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $count = 0; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Creates a new PaginationList |
|
39
|
|
|
* @param array $ids |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(array $ids = array()) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->setList($ids); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Sets the list entries |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $ids |
|
50
|
|
|
* @return \Applications\Repository\PaginationList |
|
51
|
|
|
*/ |
|
52
|
|
|
public function setList(array $ids) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->ids = $ids; |
|
55
|
|
|
$this->count = count($ids); |
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Set current list entry (move pointer). |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $id |
|
63
|
|
|
* @return int|bool |
|
|
|
|
|
|
64
|
|
|
*/ |
|
65
|
|
|
public function setCurrent($id) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->pointer = array_search($id, $this->ids); |
|
|
|
|
|
|
68
|
|
|
return $this->pointer; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Gets current list entry. |
|
73
|
|
|
* |
|
74
|
|
|
* @return NULL|array |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getCurrent() |
|
77
|
|
|
{ |
|
78
|
|
|
if (false === $this->pointer || empty($this->ids)) { |
|
79
|
|
|
return null; |
|
80
|
|
|
} |
|
81
|
|
|
return $this->ids[$this->pointer]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Gets the current position. |
|
86
|
|
|
* |
|
87
|
|
|
* @return int |
|
|
|
|
|
|
88
|
|
|
*/ |
|
89
|
|
|
public function getPosition() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->pointer + 1; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Gets the total count. |
|
96
|
|
|
* |
|
97
|
|
|
* @return int |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getCount() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->count; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* gets the id BEFORE the current entry. |
|
106
|
|
|
* |
|
107
|
|
|
* @return null|string |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getPrevious() |
|
110
|
|
|
{ |
|
111
|
|
|
if (false === $this->pointer || !$this->count || 0 == $this->pointer) { |
|
112
|
|
|
return null; |
|
113
|
|
|
} |
|
114
|
|
|
return $this->ids[$this->pointer - 1]; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Gets the id BEHIND the current entry. |
|
119
|
|
|
* |
|
120
|
|
|
* @return string |
|
121
|
|
|
* @return NULL|multitype: |
|
|
|
|
|
|
122
|
|
|
*/ |
|
123
|
|
|
public function getNext() |
|
124
|
|
|
{ |
|
125
|
|
|
if (false === $this->pointer || !$this->count || $this->count == $this->pointer) { |
|
126
|
|
|
return null; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$pointer = $this->pointer + 1; |
|
130
|
|
|
|
|
131
|
|
|
return isset($this->ids[$pointer]) ? $this->ids[$pointer] : null; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.