1 | <?php |
||
12 | class Entry_Collection extends Collection { |
||
13 | /** |
||
14 | * Lazy fetching and counting of data defers |
||
15 | * all processing of entries and entry data until |
||
16 | * it is really requested. |
||
17 | * |
||
18 | * @see \GV\Entry_Collection::add_fetch_callback |
||
19 | * @see \GV\Entry_Collection::add_count_callback |
||
20 | * |
||
21 | * @var array Lazy data loading callbacks. |
||
22 | */ |
||
23 | private $callbacks = array(); |
||
24 | |||
25 | /** |
||
26 | * @var \GV\Entry_Filter[] Filtering criteria. |
||
27 | */ |
||
28 | public $filters = array(); |
||
29 | |||
30 | /** |
||
31 | * @var \GV\Entry_Sort[] Sorting criteria. |
||
32 | */ |
||
33 | public $sorts = array(); |
||
34 | |||
35 | /** |
||
36 | * @var int The offset. |
||
37 | */ |
||
38 | public $offset = 0; |
||
39 | |||
40 | /** |
||
41 | * @var int The limit. |
||
42 | */ |
||
43 | public $limit = 20; |
||
44 | |||
45 | /** |
||
46 | * @var int The current page. |
||
47 | */ |
||
48 | public $current_page = 1; |
||
49 | |||
50 | /** |
||
51 | * @var int The number of entries fetched. |
||
52 | */ |
||
53 | private $fetched = -1; |
||
54 | |||
55 | /** |
||
56 | * Add an \GV\Entry to this collection. |
||
57 | * |
||
58 | * @param \GV\Entry $entry The entry to add to the internal array. |
||
59 | * |
||
60 | * @api |
||
61 | * @since 2.0 |
||
62 | * @return void |
||
63 | */ |
||
64 | 77 | public function add( $entry ) { |
|
73 | |||
74 | /** |
||
75 | * Get a \GV\Entry from this list. |
||
76 | * |
||
77 | * @param int $entry_id The ID of the entry to get. |
||
78 | * @param string $backend The form backend identifier, allows for multiple form backends in the future. Unused until then. |
||
79 | * |
||
80 | * @api |
||
81 | * @since 2.0 |
||
82 | * |
||
83 | * @return \GV\Entry|null The \GV\entry with the $entry_id as the ID, or null if not found. |
||
84 | */ |
||
85 | public function get( $entry_id, $backend = 'gravityforms' ) { |
||
93 | |||
94 | /** |
||
95 | * Count the total number of \GV\Entry objects that are possible to get. |
||
96 | * |
||
97 | * @api |
||
98 | * @since 2.0 |
||
99 | * |
||
100 | * @return int The total number of entries that are fetchable. |
||
101 | */ |
||
102 | 49 | public function total() { |
|
120 | |||
121 | /** |
||
122 | * Get the total number of entries that are fetched. |
||
123 | * |
||
124 | * @api |
||
125 | * @since develop |
||
126 | * |
||
127 | * @return int The number of entries fetched now. |
||
128 | */ |
||
129 | 36 | public function count() { |
|
132 | |||
133 | /** |
||
134 | * Get the entries as an array. |
||
135 | * |
||
136 | * @api |
||
137 | * @since 2.0 |
||
138 | * |
||
139 | * @return \GV\Entry[] The entries as an array. |
||
140 | */ |
||
141 | 84 | public function all() { |
|
147 | |||
148 | /** |
||
149 | * Pluck by key. |
||
150 | * |
||
151 | * @api |
||
152 | * @since develop |
||
153 | * |
||
154 | * @param string $key The key to pluck by. |
||
155 | * |
||
156 | * @return array The plucked values. |
||
157 | */ |
||
158 | 1 | public function pluck( $key ) { |
|
168 | |||
169 | /** |
||
170 | * Get the last \GV\Entry in this collection. |
||
171 | * |
||
172 | * @api |
||
173 | * @since 2.0 |
||
174 | * |
||
175 | * @return \GV\Entry|null The last entry or null. |
||
176 | */ |
||
177 | public function last() { |
||
183 | |||
184 | /** |
||
185 | * Get the first \GV\Entry in this collection. |
||
186 | * |
||
187 | * @api |
||
188 | * @since 2.0 |
||
189 | * |
||
190 | * @return \GV\Entry|null The first entry or null. |
||
191 | */ |
||
192 | 4 | public function first() { |
|
198 | |||
199 | /** |
||
200 | * Hydrate this collection now. |
||
201 | * |
||
202 | * @api |
||
203 | * @since 2.0 |
||
204 | * |
||
205 | * @return \GV\Entry_Collection This collection, now hydrated. |
||
206 | */ |
||
207 | 74 | public function fetch() { |
|
232 | |||
233 | /** |
||
234 | * Apply a filter to the current collection. |
||
235 | * |
||
236 | * This operation is non-destructive as a copy of the collection is returned. |
||
237 | * |
||
238 | * @param \GV\Entry_Filter $filter The filter to be applied. |
||
239 | * |
||
240 | * @api |
||
241 | * @since 2.0 |
||
242 | * |
||
243 | * @return \GV\Entry_Collection A copy of the this collection with the filter applied. |
||
244 | */ |
||
245 | 73 | public function filter( \GV\Entry_Filter $filter ) { |
|
253 | |||
254 | /** |
||
255 | * Sort. |
||
256 | * |
||
257 | * @param \GV\Entry_Sort $sort The sort to apply to this collection. |
||
258 | * |
||
259 | * @api |
||
260 | * @since 2.0 |
||
261 | * |
||
262 | * @return \GV\Entry_Collection A copy of the this collection with the sort applied. |
||
263 | */ |
||
264 | 10 | public function sort( $sort ) { |
|
272 | |||
273 | /** |
||
274 | * Limit the fetch to a specified window. |
||
275 | * |
||
276 | * @param int $limit The limit. |
||
277 | * |
||
278 | * @api |
||
279 | * @since 2.0 |
||
280 | * |
||
281 | * @return \GV\Entry_Collection A copy of the this collection with the limit applied. |
||
282 | */ |
||
283 | 73 | public function limit( $limit ) { |
|
289 | |||
290 | /** |
||
291 | * Add an $offset to these entries. |
||
292 | * |
||
293 | * Useful, you know, for pagination and stuff. Not too useful directly. |
||
294 | * |
||
295 | * @see \GV\Entry_Collection::page() |
||
296 | * |
||
297 | * @param int $offset The number of entries to skip in the database. |
||
298 | * |
||
299 | * @api |
||
300 | * @since 2.0 |
||
301 | * |
||
302 | * @return \GV\Entry_Collection A copy of the this collection with the offset applied. |
||
303 | */ |
||
304 | 73 | public function offset( $offset ) { |
|
310 | |||
311 | /** |
||
312 | * Set the current page. |
||
313 | * |
||
314 | * @param int $page Set the current page to this page. Ends up agumenting the $offset in \GV\Entry_Offset |
||
315 | * |
||
316 | * @return \GV\Entry_Collection A copy of the this collection with the offset applied. |
||
317 | */ |
||
318 | 73 | public function page( $page ) { |
|
324 | |||
325 | /** |
||
326 | * Defer fetching of data to the provided callable. |
||
327 | * |
||
328 | * The callback signature should be as follows: |
||
329 | * \GV\Entry_Collection callback( \GV\Entry_Filter $filter, \GV\Entry_Sort $sort, \GV\Entry_Offset $offset ); |
||
330 | * |
||
331 | * The methods that trigger the callback are: |
||
332 | * - \GV\Entry_Collection::fetch |
||
333 | * |
||
334 | * ::fetch is triggered via: |
||
335 | * - \GV\Entry_Collection::all |
||
336 | * - \GV\Entry_Collection::last |
||
337 | * |
||
338 | * @param callable $callback The callback to call when needed. |
||
339 | * |
||
340 | * @internal |
||
341 | * @since 2.0 |
||
342 | * |
||
343 | * @return void |
||
344 | */ |
||
345 | 72 | public function add_fetch_callback( $callback ) { |
|
348 | |||
349 | /** |
||
350 | * Defer counting of data to the provided callable. |
||
351 | * |
||
352 | * The callback signature should be as follows: |
||
353 | * int callback( \GV\Entry_Filter $filter ); |
||
354 | * |
||
355 | * The methods that trigger the callback are: |
||
356 | * - \GV\Entry_Collection::count |
||
357 | * |
||
358 | * @param callable $callback The callback to call when needed. |
||
359 | * |
||
360 | * @internal |
||
361 | * @since 2.0 |
||
362 | * |
||
363 | * @return void |
||
364 | */ |
||
365 | 72 | public function add_count_callback( $callback ) { |
|
368 | |||
369 | /** |
||
370 | * Add a callback for lazy loading/counting. |
||
371 | * |
||
372 | * @param callable $callback The callback to call when needed. |
||
373 | * |
||
374 | * @return void |
||
375 | */ |
||
376 | 72 | private function add_callback( $type, $callback ) { |
|
383 | |||
384 | /** |
||
385 | * @inheritdoc |
||
386 | */ |
||
387 | 74 | public function clear() { |
|
391 | } |
||
392 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.