예제 #1
0
 public function eventAction()
 {
     $eventMapper = new EventMapper();
     $entrantsMapper = new EntrantsMapper();
     $entrantsModel = new EntrantsModel();
     $commentMapper = new CommentMapper();
     $commentModel = new CommentModel();
     $event = $eventMapper->getEventById($this->getRequest()->getParam('id'));
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuEvents'), array('controller' => 'index', 'action' => 'index'))->add($event->getTitle(), array('controller' => 'show', 'action' => 'event', 'id' => $event->getId()));
     if ($this->getRequest()->isPost()) {
         if ($this->getRequest()->getPost('save')) {
             $entrantsModel->setEventId(trim($this->getRequest()->getPost('id')));
             $entrantsModel->setUserId($this->getUser()->getId());
             $entrantsModel->setStatus(trim($this->getRequest()->getPost('save')));
             $entrantsMapper->saveUserOnEvent($entrantsModel);
             $this->addMessage('saveSuccess');
         }
         if ($this->getRequest()->getPost('commentEvent')) {
             $date = new \Ilch\Date();
             $commentModel->setKey('events/show/event/id/' . $this->getRequest()->getParam('id'));
             $commentModel->setText($this->getRequest()->getPost('commentEvent'));
             $commentModel->setDateCreated($date);
             $commentModel->setUserId($this->getUser()->getId());
             $commentMapper->save($commentModel);
             $this->addMessage('saveSuccess');
         }
         if ($this->getRequest()->getPost('deleteUser')) {
             $entrantsMapper->deleteUserFromEvent($this->getRequest()->getParam('id'), $this->getUser()->getId());
             $this->addMessage('deleteSuccess');
         }
         if ($this->getRequest()->getPost('deleteEvent')) {
             $eventMapper->delete($this->getRequest()->getParam('id'));
             $this->addMessage('deleteSuccess');
             $this->redirect(array('controller' => 'index', 'action' => 'index'));
         }
     }
     if ($this->getUser()) {
         $this->getView()->set('eventEntrants', $entrantsMapper->getEventEntrants($this->getRequest()->getParam('id'), $this->getUser()->getId()));
     }
     $this->getView()->set('event', $eventMapper->getEventById($this->getRequest()->getParam('id')));
     $this->getView()->set('eventEntrantsUser', $entrantsMapper->getEventEntrantsById($this->getRequest()->getParam('id')));
     $this->getView()->set('eventEntrantsCount', count($entrantsMapper->getEventEntrantsById($this->getRequest()->getParam('id'))));
     $this->getView()->set('eventComments', $commentMapper->getCommentsByKey('events/show/event/id/' . $this->getRequest()->getParam('id')));
 }
예제 #2
0
 /**
  * Inserts user on event model.
  *
  * @param EntrantsModel $event
  */
 public function saveUserOnEvent(EntrantsModel $event)
 {
     $fields = array('event_id' => $event->getEventId(), 'user_id' => $event->getUserId(), 'status' => $event->getStatus());
     $userId = (int) $this->db()->select('*')->from('events_entrants')->where(array('user_id' => $event->getUserId(), 'event_id' => $event->getEventId()))->execute()->fetchCell();
     if ($userId) {
         /*
          * User does exist already, update.
          */
         $this->db()->update('events_entrants')->values(array('status' => $event->getStatus()))->where(array('event_id' => $event->getEventId(), 'user_id' => $event->getUserId()))->execute();
     } else {
         /*
          * User does not exist yet, insert.
          */
         $userId = $this->db()->insert('events_entrants')->values($fields)->execute();
     }
 }