Go to the documentation of this file.00001 <?php
00010 class db_rowset extends object implements Iterator, Countable, ArrayAccess {
00011
00017 protected $_pointer = 0;
00018
00024 protected $_count;
00025
00031 protected $_rows = array();
00032
00038 protected $fields;
00039
00040 protected function afterInit() {
00041 $this->_count = count($this->cfg->data);
00042 }
00043
00049 public function getDb() {
00050 return $this->cfg->db;
00051 }
00052
00058 public function getTable() {
00059 return $this->cfg->table;
00060 }
00061
00068 public function getWhere(array $prm = array()) {
00069 return $this->getDb()->getWhere($prm);
00070 }
00071
00077 public function getFields($mode='flat') {
00078 if (!$this->fields[$mode])
00079 $this->fields[$mode] = array_keys($this->get(0)->getValues($mode));
00080 return $this->fields[$mode];
00081 }
00082
00089 public function get($number) {
00090 if (!array_key_exists($number, $this->_rows) && $this->cfg->checkInArray('data', $number)) {
00091 $this->_rows[$number] = db::get('row', $this->getTable(), array(
00092 'db'=>$this->getDb(),
00093 'table'=>$this->getTable(),
00094 'data'=>$this->cfg->getInArray('data', $number),
00095 ));
00096 }
00097 return isset($this->_rows[$number]) ? $this->_rows[$number] : null;
00098 }
00099
00105 public function add($row) {
00106 if ($row instanceof db_row) {
00107 $this->_rows[$this->_count] = $row;
00108 $array = $row->getData();
00109 } else {
00110 $array = $row;
00111 }
00112 $this->cfg->setInArray('data', $this->_count, $array);
00113 $this->_count++;
00114 }
00115
00121 public function getData() {
00122 return $this->cfg->data;
00123 }
00124
00129 public function rewind() {
00130 $this->_pointer = 0;
00131 }
00132
00139 public function current() {
00140 return $this->get($this->_pointer);
00141 }
00142
00149 public function key() {
00150 return $this->_pointer;
00151 }
00152
00157 public function next() {
00158 $this->_pointer++;
00159 }
00160
00168 public function valid() {
00169 return $this->_pointer < $this->_count;
00170 }
00171
00178 public function count() {
00179 return $this->_count;
00180 }
00181
00189 public function offsetExists($offset) {
00190 $this->get($offset);
00191 return array_key_exists($offset, $this->_rows);
00192 }
00193
00201 public function offsetGet($offset) {
00202 return $this->get($offset);
00203 }
00204
00213 public function offsetSet($offset, $value) {
00214 return $this->_rows[$offset] = $value;
00215 }
00216
00223 public function offsetUnset($offset) {
00224 unset($this->_rows[$offset]);
00225 }
00226
00227 }