Esempio n. 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'));
         }
     }
 }
Esempio n. 2
0
 /**
  * Inserts or updates enemy entry.
  *
  * @param EnemyModel $model
  */
 public function save(EnemyModel $model)
 {
     $fields = array('name' => $model->getEnemyName(), 'tag' => $model->getEnemyTag(), 'image' => $model->getEnemyImage(), 'homepage' => $model->getEnemyHomepage(), 'contact_name' => $model->getEnemyContactName(), 'contact_email' => $model->getEnemyContactEmail());
     if ($model->getId()) {
         $this->db()->update('war_enemy')->values($fields)->where(array('id' => $model->getId()))->execute();
     } else {
         $this->db()->insert('war_enemy')->values($fields)->execute();
     }
 }