示例#1
0
 public function indexAction()
 {
     $awayModel = new AwayModel();
     $awayMapper = new AwayMapper();
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuAway'), array('action' => 'index'));
     if ($this->getRequest()->getPost('saveAway')) {
         $reason = trim($this->getRequest()->getPost('reason'));
         $start = new \Ilch\Date(trim($this->getRequest()->getPost('start')));
         $end = new \Ilch\Date(trim($this->getRequest()->getPost('end')));
         $text = trim($this->getRequest()->getPost('text'));
         if (empty($reason)) {
             $this->addMessage('missingReason', 'danger');
         } elseif (empty($start)) {
             $this->addMessage('missingStart', 'danger');
         } elseif (empty($end)) {
             $this->addMessage('missingEnd', 'danger');
         } elseif (empty($text)) {
             $this->addMessage('missingText', 'danger');
         } else {
             $awayModel->setUserId($this->getUser()->getId());
             $awayModel->setReason($reason);
             $awayModel->setStart($start);
             $awayModel->setEnd($end);
             $awayModel->setText($text);
             $awayMapper->save($awayModel);
             $this->addMessage('saveSuccess');
         }
     }
     $this->getView()->set('aways', $awayMapper->getAway());
 }
示例#2
0
 /**
  * Gets the Away.
  *
  * @param array $where
  * @return AwayModel[]|array
  */
 public function getAway($where = array())
 {
     $entryArray = $this->db()->select('*')->from('away')->where($where)->order(array('start' => 'ASC'))->execute()->fetchRows();
     if (empty($entryArray)) {
         return null;
     }
     $away = array();
     foreach ($entryArray as $entries) {
         $entryModel = new AwayModel();
         $entryModel->setId($entries['id']);
         $entryModel->setUserId($entries['user_id']);
         $entryModel->setReason($entries['reason']);
         $entryModel->setStart($entries['start']);
         $entryModel->setEnd($entries['end']);
         $entryModel->setText($entries['text']);
         $entryModel->setStatus($entries['status']);
         $away[] = $entryModel;
     }
     return $away;
 }