/**
  * Action pour la création.
  *
  * @return array
  */
 public function createAction()
 {
     $oForm = new \Commun\Form\ZoneHasBossesForm();
     //new \Commun\Form\ZoneHasBossesForm($this->getServiceLocator());
     $oRequest = $this->getRequest();
     $oFiltre = new \Commun\Filter\ZoneHasBossesFilter();
     $oForm->setInputFilter($oFiltre->getInputFilter());
     if ($oRequest->isPost()) {
         $oEntite = new \Commun\Model\ZoneHasBosses();
         $oForm->setData($oRequest->getPost());
         if ($oForm->isValid()) {
             $oEntite->exchangeArray($oForm->getData());
             $this->getTable()->insert($oEntite);
             $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("La zone-has-bosses a été créé avec succès."), 'success');
             return $this->redirect()->toRoute('backend-zone-has-bosses-list');
         }
     }
     // Pour optimiser le rendu
     $oViewModel = new ViewModel();
     $oViewModel->setTemplate('backend/zone-has-bosses/create');
     return $oViewModel->setVariables(array('form' => $oForm));
 }
Example #2
0
 public function importZone($aPost)
 {
     try {
         $zone = $this->_getServBnet()->warcraft(new Region(Region::EUROPE, "en_GB"))->zones();
         $aZoneBnet = $zone->find($aPost['idZone']);
         if (!$aZoneBnet) {
             throw new BnetException(499, $this->_getServiceLocator(), $aPost);
         }
         $oZone = \Core\Util\ParserWow::extraitZoneDepuisBnetZone($aZoneBnet);
         $oZone = $this->saveOrUpdateZone($oZone);
         //mode de difficulté
         //supprime toutes les clé correpsondnat au boss dans la table BossesHasModeDifficulté
         $oTabZoneHasDifficulte = $this->_getTableZoneHasModeDiffculte()->selectBy(array("idZone" => $oZone->getIdZone()));
         if ($oTabZoneHasDifficulte) {
             if (is_array($oTabZoneHasDifficulte)) {
                 foreach ($oTabZoneHasDifficulte as $oDiff) {
                     $this->_getTableZoneHasModeDiffculte()->delete($oDiff);
                 }
             } else {
                 $this->_getTableZoneHasModeDiffculte()->delete($oTabZoneHasDifficulte);
             }
         }
         foreach ($oZone->getModeDifficulte() as $oDiff) {
             $oTabModeDifficulte = $this->_getTableModeDifficulte()->selectBy(array("nom_bnet" => $oDiff));
             $oZoneHasModeDiff = new \Commun\Model\ZoneHasModeDiffculte();
             $oZoneHasModeDiff->setIdZone($oZone->getIdZone());
             $oZoneHasModeDiff->setIdMode($oTabModeDifficulte->getIdMode());
             $this->_getTableZoneHasModeDiffculte()->insert($oZoneHasModeDiff);
         }
         if ($aPost['imp-boss'] == "Oui") {
             $aBossZone = \Core\Util\ParserWow::extraitBossDepuisBnetZone($aZoneBnet, $oZone);
         } else {
             $aBossZone = array();
         }
         //supprime toutes les clé correpsondnat au zone dans la table ZoneHasBosses
         //            $oTabZoneHasBoss = $this->_getTableZoneHasBosses()->selectBy(
         //                    array("idZone" => $oZone->getIdZone()));
         //            if ($oTabZoneHasBoss) {
         //                if (is_array($oTabZoneHasBoss)) {
         //                    foreach ($oTabZoneHasBoss as $oZoneHasBoss) {
         //                        $this->_getTableZoneHasBosses()->delete($oZoneHasBoss);
         //                    }
         //                } else {
         //                    $this->_getTableZoneHasBosses()->delete($oTabZoneHasBoss);
         //                }
         //            }
         foreach ($aBossZone as $oBoss) {
             // table boss
             $oTabBoss = $this->_getTableBoss()->selectBy(array("idBosses" => $oBoss->getIdBosses()));
             // si n'existe pas on insert
             if (!$oTabBoss) {
                 $this->_getTableBoss()->insert($oBoss);
             } else {
                 // sinon on update
                 $this->_getTableBoss()->update($oBoss);
             }
             // table npc
             //                //supprime toutes les clé correspondant au boss dans la table BossesHasNpc
             //                $oTabBossHasNpc = $this->_getTableBossesHasNpc()->selectBy(
             //                        array("idBosses" => $oBoss->getIdBosses()));
             //                if ($oTabBossHasNpc) {
             //                    if (is_array($oTabBossHasNpc)) {
             //                        foreach ($oTabBossHasNpc as $oNpc) {
             //                            $this->_getTableBossesHasNpc()->delete($oNpc);
             //                        }
             //                    } else {
             //                        $this->_getTableBossesHasNpc()->delete($oTabBossHasNpc);
             //                    }
             //                }
             foreach ($oBoss->getNpc() as $oNpc) {
                 $oTabNpc = $this->_getTableNpc()->selectBy(array("idNpc" => $oNpc->getIdNpc()));
                 // si n'existe pas on insert
                 if (!$oTabNpc) {
                     $this->_getTableNpc()->insert($oNpc);
                 } else {
                     // sinon on update
                     $this->_getTableNpc()->update($oNpc);
                 }
                 $oBossHasNpc = new \Commun\Model\BossesHasNpc();
                 $oBossHasNpc->setIdBosses($oBoss->getIdBosses());
                 $oBossHasNpc->setIdNpc($oNpc->getIdNpc());
                 $oTabBossANpc = $this->_getTableBossesHasNpc()->selectBy(array("idNpc" => $oBossHasNpc->getIdNpc(), 'idBosses' => $oBossHasNpc->getIdBosses()));
                 // si le lien boss / npc n'existe pas on le cree
                 if (!$oTabBossANpc) {
                     $this->_getTableBossesHasNpc()->insert($oBossHasNpc);
                 }
             }
             $oZoneHasBoss = new \Commun\Model\ZoneHasBosses();
             $oZoneHasBoss->setIdBosses($oBoss->getIdBosses());
             $oZoneHasBoss->setIdZone($oZone->getIdZone());
             $oTabZoneABoss = $this->_getTableZoneHasBosses()->selectBy(array("idZone" => $oZoneHasBoss->getIdZone(), 'idBosses' => $oZoneHasBoss->getIdBosses()));
             // si le lien zone / boss n'existe pas on le cree
             if (!$oTabZoneABoss) {
                 $this->_getTableZoneHasBosses()->insert($oZoneHasBoss);
             }
         }
     } catch (\Exception $ex) {
         throw new \Commun\Exception\LogException("Erreur lors de l'import de zone", 0, $this->_getServiceLocator(), $ex, $aPost);
     }
 }