_table = $config['table']; $this->_tableClass = get_class($this->_table); } if (isset($config['rowClass'])) { $this->_rowClass = $config['rowClass']; } Zend_Loader::loadClass($this->_rowClass); if (isset($config['data'])) { $this->_data = $config['data']; } if (isset($config['stored'])) { $this->_stored = $config['stored']; } // set the count of rows $this->_count = count($this->_data); } /** * Store data, class names, and state in serialized object * * @return array */ public function __sleep() { return array('_data', '_tableClass', '_rowClass', '_pointer', '_count', '_rows', '_stored'); } /** * Setup to do on wakeup. * A de-serialized Rowset should not be assumed to have access to a live * database connection, so set _connected = false. * * @return void */ public function __wakeup() { $this->_connected = false; } /** * Returns the table object, or null if this is disconnected rowset * * @return Zend_Db_Table_Abstract */ public function getTable() { return $this->_table; } /** * Set the table object, to re-establish a live connection * to the database for a Rowset that has been de-serialized. * * @param Zend_Db_Table_Abstract $table * @return boolean * @throws Zend_Db_Table_Row_Exception */ public function setTable(Zend_Db_Table_Abstract $table) { $this->_table = $table; $this->_connected = false; // @todo This works only if we have iterated through // the result set once to instantiate the rows. foreach ($this->_rows as $row) { $connected = $row->setTable($table); if ($connected == true) { $this->_connected = true; } } return $this->_connected; } /** * Query the class name of the Table object for which this * Rowset was created. * * @return string */ public function getTableClass() { return $this->_tableClass; } /** * Rewind the Iterator to the first element. * Similar to the reset() function for arrays in PHP. * Required by interface Iterator. * * @return void */ public function rewind() { $this->_pointer = 0; } /** * Return the current element. * Similar to the current() function for arrays in PHP * Required by interface Iterator. * * @return Zend_Db_Table_Row_Abstract current element from the collection */ public function current() { if ($this->valid() === false) { return null; } // do we already have a row object for this position? if (empty($this->_rows[$this->_pointer])) { $this->_rows[$this->_pointer] = new $this->_rowClass( array( 'table' => $this->_table, 'data' => $this->_data[$this->_pointer], 'stored' => $this->_stored ) ); } // return the row object return $this->_rows[$this->_pointer]; } /** * Return the identifying key of the current element. * Similar to the key() function for arrays in PHP. * Required by interface Iterator. * * @return int */ public function key() { return $this->_pointer; } /** * Move forward to next element. * Similar to the next() function for arrays in PHP. * Required by interface Iterator. * * @return void */ public function next() { ++$this->_pointer; } /** * Check if there is a current element after calls to rewind() or next(). * Used to check if we've iterated to the end of the collection. * Required by interface Iterator. * * @return bool False if there's nothing more to iterate over */ public function valid() { return $this->_pointer < $this->_count; } /** * Returns the number of elements in the collection. * * Implements Countable::count() * * @return int */ public function count() { return $this->_count; } /** * Returns true if and only if count($this) > 0. * * @return bool * @deprecated since 0.9.3; use count() instead */ public function exists() { return $this->_count > 0; } /** * Returns all data as an array. * * Updates the $_data property with current row object values. * * @return array */ public function toArray() { // @todo This works only if we have iterated through // the result set once to instantiate the rows. foreach ($this->_rows as $i => $row) { $this->_data[$i] = $row->toArray(); } return $this->_data; } }