Abstract.php
00001 <?php
00011 abstract class Dsao_Db_Table_DataHandler_Row_Abstract
00012 extends Dsao_Db_Table_DataHandler_Abstract
00013 {
00017 protected $_row = null;
00018
00025 protected function _fetchMinimal($primaryKeyColumn = 'id')
00026 {
00027 $identifiers = $this->_getValidIdentifiers();
00028
00029
00030 $select = $this->getTable()->select(true)
00031 ->reset(Zend_Db_Select::COLUMNS)->columns($primaryKeyColumn);
00032
00033
00034 foreach ($identifiers as $identifier)
00035 {
00036
00037
00038 $select->where($identifier.' = ?', $this->__get($identifier));
00039 }
00040
00041 $row = $select->fetchRow();
00042
00043 return ($row ? $row->toArray() : array());
00044 }
00045
00051 public function delete()
00052 {
00053 parent::delete();
00054
00055
00056
00057 if (null === $this->isSynchronous())
00058 {
00059 $this->getSelect()->fetchRow()->delete();
00060 }
00061
00062 else
00063 {
00064 $this->getRow(false)->delete();
00065 }
00066
00067 return $this;
00068 }
00069
00075 public function exists()
00076 {
00077
00078 if (null !== ($exists = parent::exists()))
00079 {
00080 return $exists;
00081 }
00082
00083 $rowData = $this->_fetchMinimal();
00084
00085
00086 if (isset($rowData['id']) && !$this->isReadOnly())
00087 {
00088 $this->__set('id', $rowData['id']);
00089 }
00090
00091 return (bool) $rowData;
00092 }
00093
00100 public function getRow($throw = true)
00101 {
00102
00103 if ((!$this->isSynchronous() || null === $this->_row) && $throw)
00104 {
00105 throw new Dsao_Exception
00106 ('dsao_db_table_datahandler_row_abstract_row_asynchronous');
00107 }
00108
00109 return $this->_row;
00110 }
00111
00117 public function insert()
00118 {
00119 parent::insert($properties);
00120
00121
00122 $this->getTable()->insert($this->_data->getArrayCopy());
00123
00124 return $this;
00125 }
00126
00133 public function refresh($override = false)
00134 {
00135 parent::refresh();
00136
00137
00138
00139 if (true === $this->isSynchronous()
00140 || (false === $this->isSynchronous && $override))
00141 {
00142 $this->getRow(false)->refresh();
00143 }
00144
00145 else
00146 {
00147 $this->_fetchRow();
00148
00149 $this->setData($this->_row->toArray());
00150 }
00151
00152 return $this;
00153 }
00154
00161 public function setRow(Zend_Db_Table_Row_Abstract $row)
00162 {
00163
00164 if ($row->getTable()->info(Zend_Db_Table_Abstract::NAME)
00165 != $this->getTable()->info(Zend_Db_Table_Abstract::NAME))
00166 {
00167 throw new Dsao_Exception
00168 ('dsao_db_table_datahandler_row_abstract_table_invalid');
00169 }
00170
00171
00172 $this->_row = $row;
00173
00174
00175 $this->_data = $row->toArray();
00176
00177
00178 $this->_synchronous = true;
00179 $this->_valid = true;
00180
00181 return $this;
00182 }
00183
00190 public function update(array $properties = array())
00191 {
00192 $this->getRow(false)->setFromArray($this->getData($properties))->save();
00193 }
00194 }