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;
         }
     }
 }
 public function sendLostPasswordMail(Kwf_Model_Row_Interface $row, Kwf_User_Row $kwfUserRow)
 {
     $mail = new Kwf_User_Mail_LostPassword($kwfUserRow);
     $mail->send($this->_mailTransport);
     if ($row instanceof Kwf_User_EditRow) {
         $row->getModel()->writeLog(array('user_id' => $row->id, 'message_type' => 'user_mail_UserLostPassword'));
     }
     return true;
 }
 public function getComponentsDependingOnRow(Kwf_Model_Row_Interface $row)
 {
     // nur bei pageModel
     if ($row->getModel() instanceof Kwc_Root_Category_GeneratorModel) {
         $linkModel = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting($this->_class, 'ownModel'));
         $linkingRows = $linkModel->getRows($linkModel->select()->whereEquals('target', $row->{$row->getModel()->getPrimaryKey()}));
         if (count($linkingRows)) {
             $ret = array();
             foreach ($linkingRows as $linkingRow) {
                 $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($linkingRow->component_id);
                 //$c kann null sein wenn es nicht online ist
                 if ($c) {
                     $ret[] = $c;
                 }
             }
             return $ret;
         }
     }
     return array();
 }
 public function getComponentsDependingOnRow(Kwf_Model_Row_Interface $row)
 {
     //siehe PagesModel
     $map = array(2 => 10, 20 => 20, 30 => 31);
     if ($row->getModel() instanceof Kwf_Component_DependingOnRows_PagesModel) {
         if (isset($map[$row->id])) {
             return array(Kwf_Component_Data_Root::getInstance()->getComponentById($map[$row->id]));
         }
     }
     return array();
 }
 public function getRowsByParentRow(Kwf_Model_Row_Interface $parentRow, $select = array())
 {
     if (!isset($this->_data[$parentRow->getInternalId()])) {
         $this->_data[$parentRow->getInternalId()] = array();
         $fields = $parentRow->getModel()->getDb()->fetchAssoc("SHOW FIELDS FROM {$parentRow->table}");
         foreach ($fields as $i) {
             $this->_data[$parentRow->getInternalId()][] = array('field' => $i['Field'], 'type' => $i['Type'], 'null' => $i['Null'] == 'YES' ? 1 : 0, 'key' => $i['Key'], 'default' => $i['Default'], 'extra' => $i['Extra']);
         }
     }
     if (!is_object($select)) {
         $select = $this->select($select);
     }
     return new $this->_rowsetClass(array('model' => $this, 'dataKeys' => $this->_selectDataKeys($select, $this->_data[$parentRow->getInternalId()]), 'parentRow' => $parentRow));
 }
 public function getRowBySourceRow(Kwf_Model_Row_Interface $row)
 {
     foreach ($this->getUnionModels() as $k => $m) {
         if ($row->getModel() == $m) {
             return $this->getRow($k . $row->{$m->getPrimaryKey()});
         }
     }
     throw new Kwf_Exception("Model '" . get_class($row->getModel()) . "' doesn't exist as unionModel in '" . get_class($this) . "'");
 }
 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;
 }
 protected function _beforeInsert(Kwf_Model_Row_Interface $row)
 {
     if ($row->getModel()->hasColumn('component_id')) {
         $row->component_id = $this->getData()->parent->getComponent()->getPostsDirectory()->dbId;
     }
 }
 public function prepareSave(Kwf_Model_Row_Interface $row, $postData)
 {
     if ($this->getSave() === false) {
         return;
     }
     $ref = $row->getModel()->getReference($this->getName());
     if (array_key_exists($this->getFieldName(), $postData)) {
         $row->{$ref['column']} = $postData[$this->getFieldName()];
     }
 }