1: <?php
2:
3: namespace PHPixie\Database;
4:
5: abstract class Result implements \Iterator
6: {
7: public function asArray()
8: {
9: $this->rewind();
10: $array = array();
11: foreach ($this as $item)
12: $array[] = $item;
13:
14: return $array;
15: }
16:
17: public function get($field)
18: {
19: if (!$this->valid())
20: return null;
21:
22: return $this->getItemField($this->current(), $field);
23: }
24:
25: public function getField($field, $skipNulls = false)
26: {
27: $this->rewind();
28: $values = array();
29: foreach ($this as $item) {
30: $value = $this->getItemField($item, $field);
31: if ($value !== null || !$skipNulls)
32: $values[] = $value;
33: }
34:
35: return $values;
36: }
37:
38: public function getFields($fields)
39: {
40: $data = array();
41: foreach($this as $item){
42: $values = array();
43: foreach($fields as $field)
44: $values[$field] = $this->getItemField($item, $field);
45: $data[]=$values;
46: }
47:
48: return $data;
49: }
50:
51: public function getItemField($item, $field)
52: {
53: $current = $item;
54: if(!property_exists($current, $field))
55:
56: return null;
57:
58: return $current->$field;
59: }
60:
61: abstract public function current();
62: abstract public function next();
63: abstract public function valid();
64: abstract public function rewind();
65: }
66: