00001 <?php
00030 abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Countable, ArrayAccess
00031 {
00037 protected $_data = array();
00038
00044 protected $_table;
00045
00053 protected $_connected = true;
00054
00060 protected $_tableClass;
00061
00067 protected $_rowClass = 'Zend_Db_Table_Row';
00068
00074 protected $_pointer = 0;
00075
00081 protected $_count;
00082
00088 protected $_rows = array();
00089
00093 protected $_stored = false;
00094
00098 protected $_readOnly = false;
00099
00105 public function __construct(array $config)
00106 {
00107 if (isset($config['table'])) {
00108 $this->_table = $config['table'];
00109 $this->_tableClass = get_class($this->_table);
00110 }
00111 if (isset($config['rowClass'])) {
00112 $this->_rowClass = $config['rowClass'];
00113 }
00114 if (!class_exists($this->_rowClass)) {
00115 require_once 'Zend/Loader.php';
00116 Zend_Loader::loadClass($this->_rowClass);
00117 }
00118 if (isset($config['data'])) {
00119 $this->_data = $config['data'];
00120 }
00121 if (isset($config['readOnly'])) {
00122 $this->_readOnly = $config['readOnly'];
00123 }
00124 if (isset($config['stored'])) {
00125 $this->_stored = $config['stored'];
00126 }
00127
00128
00129 $this->_count = count($this->_data);
00130
00131 $this->init();
00132 }
00133
00139 public function __sleep()
00140 {
00141 return array('_data', '_tableClass', '_rowClass', '_pointer', '_count', '_rows', '_stored',
00142 '_readOnly');
00143 }
00144
00152 public function __wakeup()
00153 {
00154 $this->_connected = false;
00155 }
00156
00164 public function init()
00165 {
00166 }
00167
00173 public function isConnected()
00174 {
00175 return $this->_connected;
00176 }
00177
00183 public function getTable()
00184 {
00185 return $this->_table;
00186 }
00187
00196 public function setTable(Zend_Db_Table_Abstract $table)
00197 {
00198 $this->_table = $table;
00199 $this->_connected = false;
00200
00201
00202 foreach ($this as $row) {
00203 $connected = $row->setTable($table);
00204 if ($connected == true) {
00205 $this->_connected = true;
00206 }
00207 }
00208 return $this->_connected;
00209 }
00210
00217 public function getTableClass()
00218 {
00219 return $this->_tableClass;
00220 }
00221
00229 public function rewind()
00230 {
00231 $this->_pointer = 0;
00232 return $this;
00233 }
00234
00242 public function current()
00243 {
00244 if ($this->valid() === false) {
00245 return null;
00246 }
00247
00248
00249 if (empty($this->_rows[$this->_pointer])) {
00250 $this->_rows[$this->_pointer] = new $this->_rowClass(
00251 array(
00252 'table' => $this->_table,
00253 'data' => $this->_data[$this->_pointer],
00254 'stored' => $this->_stored,
00255 'readOnly' => $this->_readOnly
00256 )
00257 );
00258 }
00259
00260
00261 return $this->_rows[$this->_pointer];
00262 }
00263
00271 public function key()
00272 {
00273 return $this->_pointer;
00274 }
00275
00283 public function next()
00284 {
00285 ++$this->_pointer;
00286 }
00287
00295 public function valid()
00296 {
00297 return $this->_pointer < $this->_count;
00298 }
00299
00307 public function count()
00308 {
00309 return $this->_count;
00310 }
00311
00320 public function seek($position)
00321 {
00322 $position = (int) $position;
00323 if ($position < 0 || $position >= $this->_count) {
00324 require_once 'Zend/Db/Table/Rowset/Exception.php';
00325 throw new Zend_Db_Table_Rowset_Exception("Illegal index $position");
00326 }
00327 $this->_pointer = $position;
00328 return $this;
00329 }
00330
00338 public function offsetExists($offset)
00339 {
00340 return isset($this->_data[(int) $offset]);
00341 }
00342
00350 public function offsetGet($offset)
00351 {
00352 $this->_pointer = (int) $offset;
00353
00354 return $this->current();
00355 }
00356
00364 public function offsetSet($offset, $value)
00365 {
00366 }
00367
00374 public function offsetUnset($offset)
00375 {
00376 }
00377
00386 public function getRow($position, $seek = false)
00387 {
00388 $key = $this->key();
00389 try {
00390 $this->seek($position);
00391 $row = $this->current();
00392 } catch (Zend_Db_Table_Rowset_Exception $e) {
00393 require_once 'Zend/Db/Table/Rowset/Exception.php';
00394 throw new Zend_Db_Table_Rowset_Exception('No row could be found at position ' . (int) $position);
00395 }
00396 if ($seek == false) {
00397 $this->seek($key);
00398 }
00399 return $row;
00400 }
00401
00409 public function toArray()
00410 {
00411
00412
00413 foreach ($this->_rows as $i => $row) {
00414 $this->_data[$i] = $row->toArray();
00415 }
00416 return $this->_data;
00417 }
00418
00419 }