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     // Select-Statement erstellen und nur primäre Spalte laden
00030     $select = $this->getTable()->select(true)
00031       ->reset(Zend_Db_Select::COLUMNS)->columns($primaryKeyColumn);
00032 
00033     // Where-Klausel aus Identifizierern bauen
00034     foreach ($identifiers as $identifier)
00035     {
00036       // Da die Identifizierer fest im Code verankert sind und keine vom
00037       // Benutzer übergebenene Werte, wird hier nicht gequotet
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     // Falls Objekt noch nicht aus Datenbank geladen, erst laden und dann
00056     // löschen
00057     if (null === $this->isSynchronous())
00058     {
00059       $this->getSelect()->fetchRow()->delete();
00060     }
00061     // Ansonsten Zeile löschen
00062     else
00063     {
00064       $this->getRow(false)->delete();
00065     }
00066 
00067     return $this;
00068   }
00069 
00075   public function exists()
00076   {
00077     // Falls schon übergeordnete Funktion Vorhandensein eindeutig klären konnte
00078     if (null !== ($exists = parent::exists()))
00079     {
00080       return $exists;
00081     }
00082 
00083     $rowData = $this->_fetchMinimal();
00084 
00085     // Falls ID vorhanden und Objekt nicht schreib geschützt
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     // Falls Objekt nicht snychron oder noch nicht geladen wurde
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     // In Datenbank einfügen
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     // Falls Objekt mit Datenbank synchron oder Änderungen ignoriert werden
00138     // sollen, vorhandene Zeile aktualisieren
00139     if (true === $this->isSynchronous()
00140       || (false === $this->isSynchronous && $override))
00141     {
00142       $this->getRow(false)->refresh();
00143     }
00144     // Ansonsten Zeile laden
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     // Falls Zeile zu einer anderen Tabelle gehört
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     // Zeile speichern
00172     $this->_row = $row;
00173 
00174     // Daten setzen
00175     $this->_data = $row->toArray();
00176 
00177     // Als synchron und gültig markieren
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 }

Erzeugt am Fri Sep 18 19:04:11 2009 für DSA online - Morgendaemmerung von  doxygen 1.5.7.1