Example #1
0
 public function treatAction()
 {
     $enemyMapper = new EnemyMapper();
     if ($this->getRequest()->getParam('id')) {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('manageEnemy'), array('action' => 'index'))->add($this->getTranslator()->trans('treatEnemy'), array('action' => 'treat'));
         $enemy = $enemyMapper->getEnemyById($this->getRequest()->getParam('id'));
         $this->getView()->set('enemy', $enemy);
     } else {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('manageEnemy'), array('action' => 'index'))->add($this->getTranslator()->trans('manageNewEnemy'), array('action' => 'treat'));
     }
     if ($this->getRequest()->isPost()) {
         $enemyModel = new EnemyModel();
         if ($this->getRequest()->getParam('id')) {
             $enemyModel->setId($this->getRequest()->getParam('id'));
         }
         $enemyName = trim($this->getRequest()->getPost('enemyName'));
         $enemyTag = trim($this->getRequest()->getPost('enemyTag'));
         $enemyImage = trim($this->getRequest()->getPost('enemyImage'));
         $enemyHomepage = $this->getRequest()->getPost('enemyHomepage');
         $enemyContactName = $this->getRequest()->getPost('enemyContactName');
         $enemyContactEmail = $this->getRequest()->getPost('enemyContactEmail');
         if (empty($enemyName)) {
             $this->addMessage('missingEnemyName', 'danger');
         } elseif (empty($enemyTag)) {
             $this->addMessage('missingEnemyTag', 'danger');
         } elseif (empty($enemyImage)) {
             $this->addMessage('missingEnemyImage', 'danger');
         } elseif (empty($enemyHomepage)) {
             $this->addMessage('missingEnemyHomepage', 'danger');
         } elseif (empty($enemyContactName)) {
             $this->addMessage('missingContactName', 'danger');
         } elseif (empty($enemyContactEmail)) {
             $this->addMessage('missingContactEmail', 'danger');
         } else {
             $enemyModel->setEnemyName($enemyName);
             $enemyModel->setEnemyTag($enemyTag);
             $enemyModel->setEnemyImage($enemyImage);
             $enemyModel->setEnemyHomepage($enemyHomepage);
             $enemyModel->setEnemyContactName($enemyContactName);
             $enemyModel->setEnemyContactEmail($enemyContactEmail);
             $enemyMapper->save($enemyModel);
             $this->addMessage('saveSuccess');
             $this->redirect(array('action' => 'index'));
         }
     }
 }
Example #2
0
 /**
  * Gets Enemy by id.
  *
  * @param integer $id
  * @return EnemyModel|null
  */
 public function getEnemyById($id)
 {
     $enemyRow = $this->db()->select('*')->from('war_enemy')->where(array('id' => $id))->execute()->fetchAssoc();
     if (empty($enemyRow)) {
         return null;
     }
     $enemyModel = new EnemyModel();
     $enemyModel->setId($enemyRow['id']);
     $enemyModel->setEnemyName($enemyRow['name']);
     $enemyModel->setEnemyTag($enemyRow['tag']);
     $enemyModel->setEnemyImage($enemyRow['image']);
     $enemyModel->setEnemyHomepage($enemyRow['homepage']);
     $enemyModel->setEnemyContactName($enemyRow['contact_name']);
     $enemyModel->setEnemyContactEmail($enemyRow['contact_email']);
     return $enemyModel;
 }