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;
         }
     }
 }
Esempio n. 2
0
 public function sendLostPasswordMail(Kwf_Model_Row_Interface $row, Kwf_User_Row $kwfUserRow)
 {
     if ($row->getSourceRow()->getModel() == $this->_auth->_model) {
         return $this->_auth->sendLostPasswordMail($row->getSourceRow(), $kwfUserRow);
     } else {
         return false;
     }
 }
Esempio n. 3
0
 public function getRowsByParentRow(Kwf_Model_Row_Interface $parentRow, $select = array())
 {
     $select = $this->select($select);
     if (!$parentRow instanceof Kwf_Util_Model_Feed_Row_Feed) {
         throw new Kwf_Exception('Only possible with feed row');
     }
     return $parentRow->getEntries($select);
 }
 public function validateAutoLoginToken(Kwf_Model_Row_Interface $row, $token)
 {
     if ($row->getSourceRow()->getModel() == $this->_auth->_model) {
         return $this->_auth->validateAutoLoginToken($row->getSourceRow(), $token);
     } else {
         return false;
     }
 }
 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;
 }
Esempio n. 6
0
 public function save(Kwf_Model_Row_Interface $row, $data)
 {
     if ($data) {
         $parentRow = $row->getParentRow('ComponentToTag');
         $row->status = 'denied';
         $row->tags_to_components_id = null;
         $row->save();
         $parentRow->delete();
     }
 }
Esempio n. 7
0
 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 (!is_object($select)) {
         $select = $this->select($select);
     }
     if ($select->getParts()) {
         throw new Kwf_Exception_NotYetImplemented('Custom select is not yet implemented');
     }
     if (!$parentRow instanceof Kwf_Util_Model_Amazon_Products_Row) {
         throw new Kwf_Exception('Only possible with amazon product row');
     }
     $pId = $parentRow->getInternalId();
     $item = $parentRow->getItem();
     $this->_data[$pId] = array();
     foreach ($item->BrowseNodes as $n) {
         $this->_data[$pId][] = array('node_id' => $n);
     }
     return new $this->_rowsetClass(array('model' => $this, 'dataKeys' => array_keys($this->_data[$pId]), 'parentRow' => $parentRow));
 }
Esempio n. 9
0
 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 getRowsByParentRow(Kwf_Model_Row_Interface $parentRow, $select = array())
 {
     $this->_data[$parentRow->getInternalId()] = array();
     $v = $parentRow->{$this->_fieldName};
     if (substr($v, 0, 13) == 'kwfSerialized') {
         $v = substr($v, 13);
     }
     $v = unserialize($v);
     if ($v) {
         $this->_autoId[$parentRow->getInternalId()] = $v['autoId'];
         foreach ($v['data'] as $i) {
             $this->_data[$parentRow->getInternalId()][] = $i;
         }
     } else {
         $this->_autoId[$parentRow->getInternalId()] = 0;
     }
     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 getRowsByParentRow(Kwf_Model_Row_Interface $parentRow, $select = array())
 {
     $this->_data[$parentRow->getInternalId()] = array();
     $v = $parentRow->{$this->_fieldName};
     if ($v) {
         if (!is_array($v)) {
             throw new Kwf_Exception("value is not an array but a " . gettype($v));
         }
         //TODO: _data nicht duplizieren, sondern in getRowByDataKey erst machen (performance)
         $i = 0;
         foreach (array_keys($v) as $k) {
             $v[$k]['intern_id'] = ++$i;
             //TODO ist das eindeutig genug (ist nur eindeutig PRO parentRow)
             // aber nachdem man hierher eh nur per getRowsByParentRow kommt müsste es passen
         }
         $this->_data[$parentRow->getInternalId()] = $v;
     } else {
         $this->_data[$parentRow->getInternalId()] = array();
     }
     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));
 }
Esempio n. 12
0
 protected function _afterSave(Kwf_Model_Row_Interface $row)
 {
     $flightLandpointSelect = new Kwf_Model_Select();
     $flightLandpointSelect->whereEquals('flightId', $row->id)->order('pos');
     $landpointsModel = Kwf_Model_Abstract::getInstance('Landpoints');
     $landpointsSelect = $landpointsModel->select()->where(new Kwf_Model_Select_Expr_Child_Contains('FlightLandpoints', $flightLandpointSelect));
     $landpoints = $landpointsModel->getRows($landpointsSelect);
     $row->routeName = '';
     foreach ($landpoints as $landpoint) {
         $row->routeName = $row->routeName . $landpoint->name . '. ';
     }
     if (strlen($row->routeName) < 2) {
         $row->routeName = 'Обеспечение ПСО/АСР';
     }
     $row->save();
 }
 protected function _beforeSave(Kwf_Model_Row_Interface $row)
 {
     $row->addTo('*****@*****.**');
     $row->setFrom($row->email);
     $row->subject = 'Anfrage von FormStatic test';
 }
 private function _checkRowIndependence(Kwf_Model_Row_Interface $row, $msgMethod)
 {
     if (!$row instanceof Kwc_Root_Category_GeneratorRow) {
         return;
     }
     $m = Kwf_Model_Abstract::getInstance('Kwc_Root_Category_GeneratorModel');
     $pageRow = $m->getRow($row->getData()->row->id);
     $r = $pageRow;
     while ($r) {
         if (!$r->visible) {
             //wenn seite offline ist ignorieren
             //  ist nicht natürlich nicht korrekt, wir *müssten* die überprüfung
             //  nachholen, sobald die seite online gestellt wird
             return;
         }
         $r = $r->getParentNode();
     }
     $components = $pageRow->getComponentsDependingOnRow();
     if ($components) {
         $msg = trlKwf("You can not {0} this entry as it is used on the following pages:", $msgMethod);
         $msg .= Kwf_Util_Component::getHtmlLocations($components);
         throw new Kwf_ClientException($msg);
     }
 }
 protected function _beforeSave(Kwf_Model_Row_Interface $row)
 {
     $row->addTo(Kwc_Abstract::getSetting($this->getClass(), 'reportMail'));
     $row->setFrom('Report-Component');
     $row->subject = trlKwfStatic('A post has been reported');
 }
 public function logLogin(Kwf_Model_Row_Interface $row)
 {
     if (!$row->logins) {
         $row->logins = 0;
     }
     $row->logins = $row->logins + 1;
     $row->last_login = date('Y-m-d H:i:s');
     $row->save();
 }
 public function allowPasswordForUser(Kwf_Model_Row_Interface $user)
 {
     foreach ($this->_auths as $auth) {
         if (!$auth->allowPasswordForUser($user->getSourceRow())) {
             return false;
         }
     }
     return true;
 }
Esempio n. 18
0
 protected function _deleteRow(Kwf_Model_Row_Interface $row)
 {
     $row->delete();
 }
Esempio n. 19
0
 public function logLogin(Kwf_Model_Row_Interface $row)
 {
     $proxyRow = $row->getSourceRow();
     $proxyRow->getModel()->logLogin($proxyRow);
 }
Esempio n. 20
0
 public function update(Kwf_Model_Row_Interface $row, $rowData)
 {
     $pk = $this->getPrimaryKey();
     if (isset($row->{$pk})) {
         $rowData = $this->_client->rowSave($row->getCleanDataPrimary(), $rowData);
         $this->_data[$row->{$pk}] = $rowData;
         foreach ($rowData as $k => $v) {
             $row->{$k} = $v;
         }
         return $rowData[$pk];
     }
     throw new Kwf_Exception("Can't find entry");
 }
 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;
 }
 public function clearActivationToken(Kwf_Model_Row_Interface $row)
 {
     $row->activate_token = null;
     $row->save();
     return true;
 }
Esempio n. 23
0
 protected function _afterSave(Kwf_Model_Row_Interface $row, $submitRow)
 {
     $question = $row->getParentRow('TrainingContentQuestion');
     $result = $question->getParentRow('TrainingResult');
     $group = $result->getParentRow('TrainingGroup');
     $questionsModel = Kwf_Model_Abstract::getInstance('TrainingContentQuestions');
     $questionsSelect = $questionsModel->select()->whereEquals('resultId', $result->id);
     $questions = $questionsModel->getRows($questionsSelect);
     $totalScore = 0;
     $numberOfPassedQuestions = 0;
     foreach ($questions as $question) {
         $answersModel = Kwf_Model_Abstract::getInstance('TrainingContentAnswers');
         $answersSelect = $answersModel->select()->whereEquals('contentQuestionId', $question->id);
         $answers = $answersModel->getRows($answersSelect);
         $questionIsAnswered = 0;
         foreach ($answers as $answer) {
             if ($answer->isSelected) {
                 if ($answer->isCorrect) {
                     $totalScore += 1;
                 } else {
                     $totalScore -= 1;
                 }
                 $questionIsAnswered += 1;
             } else {
                 if ($answer->isCorrect) {
                     $totalScore -= 1;
                 }
             }
         }
         if ($questionIsAnswered > 0) {
             $numberOfPassedQuestions += 1;
         }
     }
     if ($numberOfPassedQuestions == count($questions)) {
         $scoreInPercents = $totalScore * 100.0 / $result->totalScore;
         $typeModel = Kwf_Model_Abstract::getInstance('Linkdata');
         if ($group->isDifGrade == 0) {
             if ($scoreInPercents >= 51) {
                 $typeSelect = $typeModel->select()->where(new Kwf_Model_Select_Expr_Sql("name = 'Оценки' AND value = 'зачет'"));
                 $gradeRow = $typeModel->getRow($typeSelect);
                 if ($gradeRow != NULL) {
                     $result->gradeId = $gradeRow->id;
                     $result->gradeName = $gradeRow->value;
                 }
             }
         } else {
             if ($scoreInPercents >= 90) {
                 $typeSelect = $typeModel->select()->where(new Kwf_Model_Select_Expr_Sql("name = 'Оценки' AND value = 'пять'"));
                 $gradeRow = $typeModel->getRow($typeSelect);
                 if ($gradeRow != NULL) {
                     $result->gradeId = $gradeRow->id;
                     $result->gradeName = $gradeRow->value;
                 }
             } else {
                 if ($scoreInPercents >= 80) {
                     $typeSelect = $typeModel->select()->where(new Kwf_Model_Select_Expr_Sql("name = 'Оценки' AND value = 'четыре'"));
                     $gradeRow = $typeModel->getRow($typeSelect);
                     if ($gradeRow != NULL) {
                         $result->gradeId = $gradeRow->id;
                         $result->gradeName = $gradeRow->value;
                     }
                 } else {
                     if ($scoreInPercents >= 75) {
                         $typeSelect = $typeModel->select()->where(new Kwf_Model_Select_Expr_Sql("name = 'Оценки' AND value = 'три'"));
                         $gradeRow = $typeModel->getRow($typeSelect);
                         if ($gradeRow != NULL) {
                             $result->gradeId = $gradeRow->id;
                             $result->gradeName = $gradeRow->value;
                         }
                     } else {
                         $result->gradeId = 0;
                         $result->gradeName = trlKwf('Too bad');
                     }
                 }
             }
         }
         $task = $result->getParentRow('Task');
         if ($task != NULL) {
             $task->status = 1;
             $task->save();
         }
         if ($result->gradeId != 0) {
             $training = $group->getParentRow('Training');
             $typeSelect = NULL;
             if ($training != NULL && $training->docTypeId != 0) {
                 $typeSelect = $typeModel->select()->whereEquals('id', $training->docTypeId);
             }
             if ($typeSelect != NULL) {
                 $typeRow = $typeModel->getRow($typeSelect);
                 $m = Kwf_Model_Abstract::getInstance('Documents');
                 $row = $m->createRow();
                 $row->typeId = $typeRow->id;
                 $row->typeName = $typeRow->value;
                 $row->gradeId = $result->gradeId;
                 $row->gradeName = $result->gradeName;
                 $row->gradeVisible = 1;
                 $row->comment = $result->trainingName . ': ' . $result->trainingGroupName;
                 $row->companyId = 0;
                 $row->startDate = date('d-m-Y H:i:s');
                 $row->save();
             }
         }
         $result->currentScore = $totalScore;
         $result->save();
     }
 }
 public function delete(Kwf_Model_Row_Interface $row)
 {
     $iId = $row->getSubModelParentRow()->getInternalId();
     if (!$row->field) {
         throw new Kwf_ClientException("field is required");
     }
     $sql = "ALTER TABLE ";
     $sql .= $row->getSubModelParentRow()->table . " ";
     $sql .= "DROP {$row->field}";
     $row->getSubModelParentRow()->getModel()->getDb()->query(trim($sql));
     foreach ($this->_rows[$iId] as $k => $i) {
         if ($row === $i) {
             unset($this->_data[$iId][$k]);
             unset($this->_rows[$iId][$k]);
             return;
         }
     }
     throw new Kwf_Exception("Can't find entry");
 }
 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 clearAutoLoginToken(Kwf_Model_Row_Interface $row)
 {
     $row->autologin = null;
     $row->save();
     return true;
 }
Esempio n. 27
0
 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) . "'");
 }
Esempio n. 28
0
 public function allowPasswordForUser(Kwf_Model_Row_Interface $user)
 {
     return $this->_auth->allowPasswordForUser($user->getProxiedRow());
 }
Esempio n. 29
0
 public function validateAutoLoginToken(Kwf_Model_Row_Interface $row, $token)
 {
     return $this->_auth->validateAutoLoginToken($row->getProxiedRow(), $token);
 }
Esempio n. 30
0
 public function associateUserByParams(Kwf_Model_Row_Interface $user, $redirectBackUrl, array $params)
 {
     $userData = $this->_getUserDataByParams($redirectBackUrl, $params);
     $user->facebook_user_id = $userData->id;
     $user->save();
 }