Exemplo n.º 1
0
 public function showAction()
 {
     $trainingMapper = new TrainingMapper();
     $entrantsMapper = new EntrantsMapper();
     $entrantsModel = new EntrantsModel();
     $training = $trainingMapper->getTrainingById($this->getRequest()->getParam('id'));
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuTraining'), array('controller' => 'index', 'action' => 'index'))->add($training->getTitle(), array('controller' => 'index', 'action' => 'show', 'id' => $training->getId()));
     if ($this->getRequest()->isPost()) {
         if ($this->getRequest()->getPost('save')) {
             $entrantsModel->setTrainId($this->getRequest()->getParam('id'));
             $entrantsModel->setUserId($this->getUser()->getId());
             $entrantsModel->setNote($this->getRequest()->getPost('train_textarea'));
             $entrantsMapper->saveUserOnTrain($entrantsModel);
             $this->addMessage('saveSuccess');
         }
         if ($this->getRequest()->getPost('del')) {
             $entrantsMapper->deleteUserFromTrain($this->getRequest()->getParam('id'), $this->getUser()->getId());
             $this->addMessage('deleteSuccess');
         }
     }
     if ($this->getUser()) {
         $this->getView()->set('trainEntrantUser', $entrantsMapper->getEntrants($this->getRequest()->getParam('id'), $this->getUser()->getId()));
     }
     $this->getView()->set('training', $trainingMapper->getTrainingById($this->getRequest()->getParam('id')));
     $this->getView()->set('trainEntrantsUserCount', count($entrantsMapper->getEntrantsById($this->getRequest()->getParam('id'))));
     $this->getView()->set('trainEntrantsUser', $entrantsMapper->getEntrantsById($this->getRequest()->getParam('id')));
 }
Exemplo n.º 2
0
 /**
  * Gets the Event entrants.
  *
  * @param integer $id
  * @return EntrantsModel|null
  */
 public function getEntrantsById($trainId)
 {
     $entryArray = $this->db()->select('*')->from('training_entrants')->where(array('train_id' => $trainId))->execute()->fetchRows();
     if (empty($entryArray)) {
         return null;
     }
     $entry = array();
     foreach ($entryArray as $entries) {
         $entryModel = new EntrantsModel();
         $entryModel->setUserId($entries['user_id']);
         $entryModel->setNote($entries['note']);
         $entry[] = $entryModel;
     }
     return $entry;
 }