1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
12 | abstract class Kohana_Jam_Query_Builder_Collection extends Jam_Query_Builder_Select implements Countable, ArrayAccess, Iterator, Serializable { |
||
13 | |||
14 | /** |
||
15 | * Create object of class Jam_Query_Builder_Collection |
||
16 | * @param string $model |
||
17 | * @return Jam_Query_Builder_Collection |
||
18 | */ |
||
19 | public static function factory($model) |
||
23 | |||
24 | /** |
||
25 | * The result of this colleciton |
||
26 | * @var Database_Result |
||
27 | */ |
||
28 | protected $_result; |
||
29 | |||
30 | /** |
||
31 | * Result Setter / Getter |
||
32 | * @param Database_Result $result |
||
33 | * @return Database_Result|Jam_Query_Builder_Collection |
||
34 | */ |
||
35 | 81 | public function result(Database_Result $result = NULL) |
|
49 | |||
50 | /** |
||
51 | * Load the info for the collection result, as if was loaded from the database |
||
52 | * @param array $fields |
||
53 | * @return Jam_Query_Builder_Collection |
||
54 | */ |
||
55 | 39 | public function load_fields(array $fields) |
|
60 | |||
61 | /** |
||
62 | * Use the Jam::build_template() to return the model for the row in the results |
||
63 | * @param array $value |
||
64 | * @return Jam_Model |
||
65 | */ |
||
66 | 57 | protected function _load_model($value) |
|
77 | |||
78 | /** |
||
79 | * Return all of the models in the result as an array. |
||
80 | * |
||
81 | * // Indexed array of all models |
||
82 | * $rows = $result->as_array(); |
||
83 | * |
||
84 | * // Associative array of models by "id" |
||
85 | * $rows = $result->as_array('id'); |
||
86 | * |
||
87 | * // Associative array of fields, "id" => "name" |
||
88 | * $rows = $result->as_array('id', 'name'); |
||
89 | * |
||
90 | * @param string column for associative keys |
||
91 | * @param string column for values |
||
92 | * @return array |
||
93 | */ |
||
94 | 11 | public function as_array($key = NULL, $value = NULL) |
|
107 | |||
108 | /** |
||
109 | * Get the ids of the models in an array |
||
110 | * @return array |
||
111 | */ |
||
112 | 3 | public function ids() |
|
116 | |||
117 | /** |
||
118 | * Return the first model |
||
119 | * @return Jam_Model|null |
||
120 | */ |
||
121 | 42 | public function first() |
|
125 | |||
126 | /** |
||
127 | * Return the first model, throw Jam_Exception_Notfound if there was no result |
||
128 | * @return Jam_Model |
||
129 | * @throws Jam_Exception_Notfound |
||
130 | */ |
||
131 | public function first_insist() |
||
139 | |||
140 | /** |
||
141 | * Find out the primary_key of an item of the $_content |
||
142 | * @param mixed $value |
||
143 | * @return int |
||
144 | */ |
||
145 | protected function _id($value) |
||
156 | |||
157 | public function search($item) |
||
174 | |||
175 | public function has($item) |
||
179 | |||
180 | /** |
||
181 | * Implement Countable |
||
182 | * @return int |
||
183 | */ |
||
184 | 10 | public function count() |
|
188 | |||
189 | /** |
||
190 | * Implement ArrayAccess |
||
191 | * |
||
192 | * @param int $offset |
||
193 | * @return Jam_Model |
||
194 | */ |
||
195 | 10 | public function offsetGet($offset) |
|
203 | |||
204 | /** |
||
205 | * Implement ArrayAccess |
||
206 | * |
||
207 | * @param int $offset |
||
208 | * @return boolean |
||
209 | */ |
||
210 | 1 | public function offsetExists($offset) |
|
214 | |||
215 | /** |
||
216 | * Implement ArrayAccess |
||
217 | */ |
||
218 | 1 | public function offsetSet($offset, $value) |
|
222 | |||
223 | /** |
||
224 | * Implement ArrayAccess |
||
225 | */ |
||
226 | 1 | public function offsetUnset($offset) |
|
230 | |||
231 | /** |
||
232 | * Implement Iterator |
||
233 | */ |
||
234 | 7 | public function rewind() |
|
238 | |||
239 | /** |
||
240 | * Implement Iterator |
||
241 | * @return Jam_Model |
||
242 | */ |
||
243 | 10 | public function current() |
|
251 | |||
252 | /** |
||
253 | * Implement Iterator |
||
254 | * @return int |
||
255 | */ |
||
256 | 2 | public function key() |
|
260 | |||
261 | /** |
||
262 | * Implement Iterator |
||
263 | */ |
||
264 | 7 | public function next() |
|
268 | |||
269 | /** |
||
270 | * Implement Iterator |
||
271 | * @return bool |
||
272 | */ |
||
273 | 7 | public function valid() |
|
277 | |||
278 | 1 | public function serialize() |
|
282 | |||
283 | 1 | public function unserialize($data) |
|
289 | } |
||
290 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.