GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gv-collection.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * A generic Collection base class.
11  */
12 class Collection {
13  /**
14  * @var array Main storage for objects in this collection.
15  */
16  private $storage = array();
17 
18  /**
19  * Add an object to this collection.
20  *
21  * @param mixed $value The object to be added.
22  *
23  * @api
24  * @since 2.0
25  * @return void
26  */
27  public function add( $value ) {
28  $this->storage []= $value;
29  }
30 
31  /**
32  * Clear this collection.
33  *
34  * @api
35  * @since 2.0
36  * @return void
37  */
38  public function clear() {
39  $this->count() && ( $this->storage = array() );
40  }
41 
42  /**
43  * Merge another collection into here.
44  *
45  * @param \GV\Collection $collection The collection to be merged.
46  *
47  * @api
48  * @since 2.0
49  * @return void
50  */
51  public function merge( \GV\Collection $collection ) {
52  array_map( array( $this, 'add'), $collection->all() );
53  }
54 
55  /**
56  * Returns all the objects in this collection as an an array.
57  *
58  * @api
59  * @since 2.0
60  * @return array The objects in this collection.
61  */
62  public function all() {
63  return $this->storage;
64  }
65 
66  /**
67  * Get the last added object.
68  *
69  * @api
70  * @since 2.0
71  * @return mixed|null The last item in here, or null if there are none.
72  */
73  public function last() {
74  return end( $this->storage );
75  }
76 
77  /**
78  * Get the first added object.
79  *
80  * @api
81  * @since 2.0
82  * @return mixed|null The first item in here, or null if there are none.
83  */
84  public function first() {
85  return reset( $this->storage );
86  }
87 
88  /**
89  * Returns the count of the objects in this collection.
90  *
91  * @api
92  * @since 2.0
93  * @return int The size of this collection.
94  */
95  public function count() {
96  return count( $this->storage );
97  }
98 }
count()
Returns the count of the objects in this collection.
all()
Returns all the objects in this collection as an an array.
merge(\GV\Collection $collection)
Merge another collection into here.
If this file is called directly, abort.
last()
Get the last added object.
clear()
Clear this collection.
first()
Get the first added object.
add( $value)
Add an object to this collection.