コード例 #1
0
ファイル: Abstract.php プロジェクト: hettema/Stages
 /**
  * Save the object data
  *
  * @param Core_Model_Abstract $object
  * @return Core_Model_Resource_Abstract 
  */
 public function save(Core_Model_Abstract $object)
 {
     if ($object->isDeleted()) {
         return $this->delete($object);
     }
     $this->_beforeSave($object);
     $this->_checkUnique($object);
     if (!is_null($object->getId())) {
         // Not auto increment primary key support
         if ($this->_isPkAutoIncrement) {
             $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $this->getIdFieldName());
         } else {
             if ($this->_getWriteAdapter()->fetchOne("SELECT * FROM " . $this->getMainTable() . " WHERE " . $this->getIdFieldName() . "=" . $object->getId()) !== false) {
                 $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $this->getIdFieldName());
             } else {
                 $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object, true));
             }
         }
     } else {
         $id = $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object, true), $this->getIdFieldName());
         $object->setId($id);
     }
     $this->_afterSave($object);
     return $this;
 }