예제 #1
0
 /**
  * Gets awards.
  *
  * @param integer $id
  * @return AwardsModel|null
  */
 public function getAwardsById($id)
 {
     $awardsRow = $this->db()->select('*')->from('awards')->where(array('id' => $id))->execute()->fetchAssoc();
     if (empty($awardsRow)) {
         return null;
     }
     $awardsModel = new AwardsModel();
     $awardsModel->setId($awardsRow['id']);
     $awardsModel->setDate($awardsRow['date']);
     $awardsModel->setRank($awardsRow['rank']);
     $awardsModel->setEvent($awardsRow['event']);
     $awardsModel->setURL($awardsRow['url']);
     $awardsModel->setUTId($awardsRow['ut_id']);
     $awardsModel->setTyp($awardsRow['typ']);
     return $awardsModel;
 }
예제 #2
0
 public function treatAction()
 {
     $awardsMapper = new AwardsMapper();
     $userMapper = new UserMapper();
     if ($this->getRequest()->getParam('id')) {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuAwards'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat'));
         $this->getView()->set('awards', $awardsMapper->getAwardsById($this->getRequest()->getParam('id')));
     } else {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuAwards'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat'));
     }
     if ($this->getRequest()->isPost()) {
         $model = new AwardsModel();
         if ($this->getRequest()->getParam('id')) {
             $model->setId($this->getRequest()->getParam('id'));
         }
         $date = new \Ilch\Date(trim($this->getRequest()->getPost('date')));
         $rank = trim($this->getRequest()->getPost('rank'));
         $utId = trim($this->getRequest()->getPost('utId'));
         $typ = trim($this->getRequest()->getPost('typ'));
         if (empty($date)) {
             $this->addMessage('missingDate', 'danger');
         } elseif (empty($rank)) {
             $this->addMessage('missingRank', 'danger');
         } elseif (empty($typ)) {
             $this->addMessage('missingTyp', 'danger');
         } elseif (empty($utId)) {
             $this->addMessage('missingUTId', 'danger');
         } else {
             $model->setDate($date);
             $model->setRank($rank);
             $model->setEvent($this->getRequest()->getPost('event'));
             $model->setURL($this->getRequest()->getPost('url'));
             $model->setUTId($utId);
             $model->setTyp($typ);
             $awardsMapper->save($model);
             $this->addMessage('saveSuccess');
             $this->redirect(array('action' => 'index'));
         }
     }
     $this->getView()->set('users', $userMapper->getUserList(array('confirmed' => 1)));
 }