/** * Inserts or updates rule model. * * @param RuleModel $rule */ public function save(RuleModel $rule) { $fields = array('paragraph' => $rule->getParagraph(), 'title' => $rule->getTitle(), 'text' => $rule->getText()); if ($rule->getId()) { $this->db()->update('rules')->values($fields)->where(array('id' => $rule->getId()))->execute(); } else { $this->db()->insert('rules')->values($fields)->execute(); } }
public function treatAction() { $ruleMapper = new RuleMapper(); if ($this->getRequest()->getParam('id')) { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuRules'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat')); $this->getView()->set('rule', $ruleMapper->getRuleById($this->getRequest()->getParam('id'))); } else { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuRules'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat')); } if ($this->getRequest()->isPost()) { $model = new RuleModel(); if ($this->getRequest()->getParam('id')) { $model->setId($this->getRequest()->getParam('id')); } $title = trim($this->getRequest()->getPost('title')); $text = trim($this->getRequest()->getPost('text')); if (empty($title)) { $this->addMessage('missingTitle', 'danger'); } elseif (empty($text)) { $this->addMessage('missingText', 'danger'); } else { $model->setParagraph($this->getRequest()->getPost('paragraph')); $model->setTitle($title); $model->setText($text); $ruleMapper->save($model); $this->addMessage('saveSuccess'); $this->redirect(array('action' => 'index')); } } }