public function prepareSave(Kwf_Model_Row_Interface $row, $postData) { //TODO remove in later branches? if ($this->getSave() === false || $this->getInternalSave() === false) { return; } $new = $this->_getIdsFromPostData($postData); // $avaliableKeys = array(6,20,17); //foreach ($this->_getFields() as $field) { // $avaliableKeys[] = $field->getKey(); // } $relModel = $row->getModel()->getDependentModel($this->getRelModel()); $ref = $relModel->getReference($this->getRelationToValuesRule()); $valueKey = $ref['column']; $s = $this->getChildRowsSelect(); if (!$s) { $s = array(); } foreach ($row->getChildRows($this->getRelModel(), $s) as $savedRow) { $id = $savedRow->{$valueKey}; if (true || in_array($id, $avaliableKeys)) { if (!in_array($id, $new)) { $savedRow->delete(); } else { unset($new[array_search($id, $new)]); } } } foreach ($new as $id) { if (true || in_array($id, $avaliableKeys)) { $i = $row->createChildRow($this->getRelModel()); $i->{$valueKey} = $id; } } }
protected function _getRowsByRow(Kwf_Model_Row_Interface $row) { $pk = $row->getModel()->getPrimaryKey(); if (!$row->{$pk}) { //neuer eintrag (noch keine id) return array(); } if ($this->getReferenceName()) { if ($this->getSelect()) { $select = $this->getSelect(); } else { $select = new Kwf_Model_Select(); } if ($row->getModel()->getDependentModel($this->getReferenceName())->hasColumn('pos')) { $select->order('pos'); } $rows = $row->getChildRows($this->getReferenceName(), $select); } else { $ref = $this->_getReferences($row); $where = array(); foreach (array_keys($ref['columns']) as $k) { $where["{$ref['columns'][$k]} = ?"] = $row->{$ref['refColumns'][$k]}; } if ($this->getModel()->hasColumn('pos')) { $where['order'] = 'pos'; } $rows = $this->getModel()->fetchAll($where); } return $rows; }