nyroFwk  0.2
rowset.class.php
Go to the documentation of this file.
1 <?php
10 class db_rowset extends object implements Iterator, Countable, ArrayAccess {
11 
17  protected $_pointer = 0;
18 
24  protected $_count;
25 
31  protected $_rows = array();
32 
38  protected $fields;
39 
40  protected function afterInit() {
41  $this->_count = count($this->cfg->data);
42  }
43 
49  public function getDb() {
50  return $this->cfg->db;
51  }
52 
58  public function getTable() {
59  return $this->cfg->table;
60  }
61 
68  public function getWhere(array $prm = array()) {
69  return $this->getDb()->getWhere($prm);
70  }
71 
77  public function getFields($mode='flat') {
78  if (!$this->fields[$mode])
79  $this->fields[$mode] = array_keys($this->get(0)->getValues($mode));
80  return $this->fields[$mode];
81  }
82 
89  public function get($number) {
90  if (!array_key_exists($number, $this->_rows) && $this->cfg->checkInArray('data', $number)) {
91  $this->_rows[$number] = db::get('row', $this->getTable(), array(
92  'db'=>$this->getDb(),
93  'table'=>$this->getTable(),
94  'data'=>$this->cfg->getInArray('data', $number),
95  ));
96  }
97  return isset($this->_rows[$number]) ? $this->_rows[$number] : null;
98  }
99 
105  public function add($row) {
106  if ($row instanceof db_row) {
107  $this->_rows[$this->_count] = $row;
108  $array = $row->getData();
109  } else {
110  $array = $row;
111  }
112  $this->cfg->setInArray('data', $this->_count, $array);
113  $this->_count++;
114  }
115 
121  public function getData() {
122  return $this->cfg->data;
123  }
124 
129  public function rewind() {
130  $this->_pointer = 0;
131  }
132 
139  public function current() {
140  return $this->get($this->_pointer);
141  }
142 
149  public function key() {
150  return $this->_pointer;
151  }
152 
157  public function next() {
158  $this->_pointer++;
159  }
160 
168  public function valid() {
169  return $this->_pointer < $this->_count;
170  }
171 
178  public function count() {
179  return $this->_count;
180  }
181 
189  public function offsetExists($offset) {
190  $this->get($offset);
191  return array_key_exists($offset, $this->_rows);
192  }
193 
201  public function offsetGet($offset) {
202  return $this->get($offset);
203  }
204 
213  public function offsetSet($offset, $value) {
214  return $this->_rows[$offset] = $value;
215  }
216 
223  public function offsetUnset($offset) {
224  unset($this->_rows[$offset]);
225  }
226 
227  public function __toString() {
228  $tmp = array();
229  foreach($this as $row)
230  $tmp[] = $row.'';
231  return 'rowSet_'.implode('_', $tmp);
232  }
233 
234 }
offsetUnset($offset)
getWhere(array $prm=array())
offsetExists($offset)
offsetGet($offset)
offsetSet($offset, $value)
getFields($mode='flat')
static get($type, $table, array $prm=array())
Definition: db.class.php:87
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13