Example #1
0
 public function save($parentRow, $postData)
 {
     if ($this->getSave() === false) {
         return array();
     }
     $row = $this->_getRowByParentRow($parentRow);
     if (!$row) {
         throw new Kwf_Exception('Can\'t find row.');
     } else {
         if (!$row instanceof Kwf_Model_Row_Interface) {
             throw new Kwf_Exception('Row must be a Kwf_Model_Row_Interface.');
         }
     }
     if ($this->getIdTemplate()) {
         $field = $this->getIdTemplateField() ? $this->getIdTemplateField() : $this->getPrimaryKey();
         if (!$row->{$field} && $this->getIdTemplate()) {
             $row->{$field} = $this->_getIdByParentRow($parentRow);
         }
     }
     if (!$this->getId()) {
         $this->_beforeInsert($row);
     } else {
         $this->_beforeUpdate($row);
     }
     $this->_beforeSave($row);
     if (!$this->_rowIsParentRow($parentRow)) {
         //speichern *vor* parent::save wegen:
         //- verschachtelten forms, beim hinzufügen brauchen die kinder die neue id
         //- MultiFields auch beim hinzufügen ohne Model Relation brauchen wir die neue id
         $row->save();
     }
     parent::save($parentRow, $postData);
     if (!$this->getId()) {
         $this->_afterInsert($row);
     } else {
         $this->_afterUpdate($row);
     }
     $this->_afterSave($row);
     if (!$this->getId()) {
         $primaryKey = $this->getPrimaryKey();
         if (is_array($primaryKey)) {
             $addedId = array();
             foreach ($primaryKey as $key) {
                 $addedId[$key] = $row->{$key};
             }
         } else {
             $addedId = $row->{$primaryKey};
         }
         return array('addedId' => $addedId);
     }
     return array();
 }