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')); } } }
/** * Gets history. * * @param integer $id * @return HistoryModel|null */ public function getHistoryById($id) { $historyRow = $this->db()->select('*')->from('history')->where(array('id' => $id))->execute()->fetchAssoc(); if (empty($historyRow)) { return null; } $historyModel = new HistoryModel(); $historyModel->setId($historyRow['id']); $historyModel->setDate($historyRow['date']); $historyModel->setTitle($historyRow['title']); $historyModel->setColor($historyRow['color']); $historyModel->setTyp($historyRow['typ']); $historyModel->setText($historyRow['text']); return $historyModel; }