Esempio n. 1
0
 public function treatAction()
 {
     $historyMapper = new HistoryMapper();
     if ($this->getRequest()->getParam('id')) {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuHistorys'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat'));
         $this->getView()->set('history', $historyMapper->getHistoryById($this->getRequest()->getParam('id')));
     } else {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuHistorys'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat'));
     }
     if ($this->getRequest()->isPost()) {
         $model = new HistoryModel();
         if ($this->getRequest()->getParam('id')) {
             $model->setId($this->getRequest()->getParam('id'));
         }
         $date = new \Ilch\Date(trim($this->getRequest()->getPost('date')));
         $title = trim($this->getRequest()->getPost('title'));
         $text = trim($this->getRequest()->getPost('text'));
         if (empty($date)) {
             $this->addMessage('missingDate', 'danger');
         } elseif (empty($title)) {
             $this->addMessage('missingTitle', 'danger');
         } elseif (empty($text)) {
             $this->addMessage('missingText', 'danger');
         } else {
             $model->setDate(new \Ilch\Date(trim($this->getRequest()->getPost('date'))));
             $model->setTitle($this->getRequest()->getPost('title'));
             $model->setText($this->getRequest()->getPost('text'));
             $historyMapper->save($model);
             $this->addMessage('saveSuccess');
             $this->redirect(array('action' => 'index'));
         }
     }
 }
Esempio n. 2
0
 /**
  * Inserts or updates history model.
  *
  * @param HistoryModel $history
  */
 public function save(HistoryModel $history)
 {
     $fields = array('date' => $history->getDate(), 'title' => $history->getTitle(), 'text' => $history->getText());
     if ($history->getId()) {
         $this->db()->update('history')->values($fields)->where(array('id' => $history->getId()))->execute();
     } else {
         $this->db()->insert('history')->values($fields)->execute();
     }
 }