public function treatAction() { $jobsMapper = new JobsMapper(); if ($this->getRequest()->getParam('id')) { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuJobs'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat')); $this->getView()->set('jobs', $jobsMapper->getJobsById($this->getRequest()->getParam('id'))); } else { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuJobs'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat')); } if ($this->getRequest()->isPost()) { $model = new JobsModel(); if ($this->getRequest()->getParam('id')) { $model->setId($this->getRequest()->getParam('id')); } $title = trim($this->getRequest()->getPost('title')); $text = trim($this->getRequest()->getPost('text')); $email = trim($this->getRequest()->getPost('email')); if (empty($title)) { $this->addMessage('missingTitle', 'danger'); } elseif (empty($text)) { $this->addMessage('missingText', 'danger'); } elseif (empty($email)) { $this->addMessage('missingEmail', 'danger'); } else { $model->setTitle($title); $model->setText($text); $model->setEmail($email); $model->setShow($this->getRequest()->getPost('show')); $jobsMapper->save($model); $this->addMessage('saveSuccess'); $this->redirect(array('action' => 'index')); } } }
/** * Gets jobs. * * @param integer $id * @return JobsModel|null */ public function getJobsById($id) { $jobsRow = $this->db()->select('*')->from('jobs')->where(array('id' => $id))->execute()->fetchAssoc(); if (empty($jobsRow)) { return null; } $jobsModel = new JobsModel(); $jobsModel->setId($jobsRow['id']); $jobsModel->setTitle($jobsRow['title']); $jobsModel->setText($jobsRow['text']); $jobsModel->setEmail($jobsRow['email']); $jobsModel->setShow($jobsRow['show']); return $jobsModel; }