Exemplo n.º 1
0
 /**
  * Retourne la première erreur de la chaine d'exception au format ApiProblem.
  * @param \Exception $oException
  * @return \Commun\Model\LogApiProblem
  */
 public static function tranformeExceptionToApiProblem($oException, $service)
 {
     $aReturn = ParseException::tranformeExceptionToArray($oException);
     // le code si supperieur a 599 est remplacer par 499.
     // pour plus de detail on met le code erreur original dans le type
     return new LogApiProblem($aReturn["code"], $aReturn['msg'], $aReturn['code'], $aReturn['type'], array(), $service);
 }
Exemplo n.º 2
0
 /**
  * Fetch a resource
  *
  * @param  mixed $id
  * @return LogApiProblem|mixed
  */
 public function fetch($id)
 {
     try {
         $sNom = $this->getEvent()->getRouteParam('roster_name');
         $key = $this->getRequestKey('APIRtK-roster', array($sNom));
         if ($this->cache->hasItem($key) === true) {
             return $this->cache->getItem($key);
         }
         /* @var $oTabRoster \Commun\Model\Roster  */
         $oTabRoster = $this->getTableRoster()->selectBy(array("nom" => $sNom));
         if (!$oTabRoster) {
             return new LogApiProblem(404, sprintf($this->_getServTranslator()->translate("Le roster [ %s ] demandé n'a pas été trouvé."), $sNom), $this->_getServTranslator()->translate("Not Found"), $this->_getServTranslator()->translate("Roster inconnu"), array('nomRoster' => $sNom), $this->_service);
         }
         $aRoles = $this->getTableRole()->fetchAll()->toArray();
         $oResult = new RosterEntity();
         $oResult->setNom($sNom);
         $aRoleModifie = array();
         foreach ($aRoles as $aRole) {
             $aLstPerso = $this->getTableRosterHasPersonnage()->getListePersonnage($aRole['idRole'], $oTabRoster->getIdRoster());
             $aRole["personnages"] = $aLstPerso;
             $aRoleModifie[] = $aRole;
         }
         $oResult->setRoles($aRoleModifie);
         $this->addItem($key, $oResult);
         return $oResult;
     } catch (\Exception $ex) {
         return \Core\Util\ParseException::tranformeExceptionToApiProblem($ex, $this->_service);
     }
 }
 /**
  * Action pour la création.
  *
  * @return array
  */
 public function createAction()
 {
     $oForm = new \Commun\Form\PallierAfficherForm();
     //new \Commun\Form\PallierAfficherForm($this->getServiceLocator());
     $oRequest = $this->getRequest();
     $oFiltre = new \Commun\Filter\PallierAfficherFilter();
     $oForm->setInputFilter($oFiltre->getInputFilter());
     if ($oRequest->isPost()) {
         $oEntite = new \Commun\Model\PallierAfficher();
         $oForm->setData($oRequest->getPost());
         if ($oForm->isValid()) {
             // $oEntite->exchangeArray($oForm->getData());
             $this->getTable()->beginTransaction();
             try {
                 $this->getTable()->saveOrUpdatePallier($oForm->getData());
                 $this->getTable()->commit();
                 $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Le pallier a été créé avec succès."), 'success');
                 return $this->redirect()->toRoute('backend-pallier-afficher-list');
             } catch (\Exception $ex) {
                 // on rollback en cas d'erreur
                 $this->getTable()->rollback();
                 $aAjaxEx = \Core\Util\ParseException::tranformeExceptionToArray($ex);
                 $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Une erreur est survenue lors de la création du pallier."), 'error');
                 $this->flashMessenger()->addMessage($aAjaxEx['msg'], 'error');
             }
         }
     }
     // Pour optimiser le rendu
     $oViewModel = new ViewModel();
     $oViewModel->setTemplate('backend/pallier-afficher/create');
     return $oViewModel->setVariables(array('form' => $oForm));
 }
Exemplo n.º 4
0
 /**
  * Fetch a resource
  * Paramètre supplémentaire :
  * ?withids=<code>0</code> pas d'id superflus,<code>1</code> ajout des differents ID.
  * ?spe=<code>-1</code> toutes les spés,<code>0</code> spé 1, <code>1</code> spé 2, <code>2</code> spé 3,<code>3</code> spé 4  .
  * @param  mixed $id nom du personnage dont on veut le loot
  * @return ApiProblem|mixed
  */
 public function fetch($id)
 {
     try {
         $sRoster = $this->getEvent()->getRouteParam('roster_name');
         $bWithId = $this->getEvent()->getQueryParam('withids', 0);
         $iSpe = $this->getEvent()->getQueryParam('spe', -1);
         $key = $this->getRequestKey('APIRtK-loot', array($sRoster, $bWithId, $iSpe));
         if ($this->cache->hasItem($key) === true) {
             return $this->cache->getItem($key);
         }
         $oTabRoster = $this->getTableRoster()->selectBy(array("nom" => $sRoster));
         if (!$oTabRoster) {
             return new LogApiProblem(404, sprintf($this->_getServTranslator()->translate("Le roster [ %s ] n'a pas été trouvé."), $sRoster), $this->_getServTranslator()->translate("Not Found"), $this->_getServTranslator()->translate("Personnage / Serveur inconnu"), array(), $this->_service);
         }
         $oResult = new LootRosterEntity();
         $oResult->setId($oTabRoster->getIdRoster());
         $oResult->setNom($sRoster);
         $aItemsPersonnage = $this->getTableItemPersonnageRaid()->getLootStatDuRoster($sRoster, $bWithId, $iSpe);
         $oResult->setItems($aItemsPersonnage);
         $this->addItem($key, $oResult);
         return $oResult;
     } catch (\Exception $ex) {
         return \Core\Util\ParseException::tranformeExceptionToApiProblem($ex, $this->_service);
     }
 }
Exemplo n.º 5
0
 /**
  * Fetch a resource
  * Paramètre supplémentaire :
  * ?withids=<code>0</code> pas d'id superflus,<code>1</code> ajout des differents ID.
  * ?spe=<code>-1</code> toutes les spés,<code>0</code> spé 1, <code>1</code> spé 2, <code>2</code> spé 3,<code>3</code> spé 4  .
  * @param  mixed $id nom du personnage dont on veut le loot
  * @return ApiProblem|mixed
  */
 public function fetch($sRoster)
 {
     try {
         $sRoster = $this->getEvent()->getRouteParam('nom_roster');
         $iSpe = $this->getEvent()->getQueryParam('spe', -1);
         $key = $this->getRequestKey('APIRtK-loot', array($sRoster, $iSpe));
         if ($this->cache->hasItem($key) === true) {
             return $this->cache->getItem($key);
         }
         $oResult = $this->getTableRoster()->getStatRoster($sRoster, $iSpe);
         $this->addItem($key, $oResult);
         return $oResult;
     } catch (\Exception $ex) {
         return \Core\Util\ParseException::tranformeExceptionToApiProblem($ex, $this->_service);
     }
 }
Exemplo n.º 6
0
 /**
  * Action pour la mise à jour.
  *
  * @return array
  */
 public function updateAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     try {
         $oEntite = $this->getTableRoster()->findRow($id);
         if (!$oEntite) {
             $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Identifiant de roster inconnu."), 'error');
             return $this->redirect()->toRoute('backend-roster-list');
         }
     } catch (\Exception $ex) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Une erreur est survenue lors de la récupération du roster."), 'error');
         return $this->redirect()->toRoute('backend-roster-list');
     }
     $oForm = new \Commun\Form\RosterForm();
     //new \Commun\Form\RosterForm($this->getServiceLocator());
     $oFiltre = new \Commun\Filter\RosterFilter();
     $oEntite->setInputFilter($oFiltre->getInputFilter());
     $oForm->bind($oEntite);
     $aOptRoster = array('nom' => $oEntite->getNom(), 'roles' => $this->getTableRole()->fetchAll()->toArray(), 'key' => $oEntite->getKey());
     $oRequest = $this->getRequest();
     if ($oRequest->isPost()) {
         $oForm->setInputFilter($oFiltre->getInputFilter());
         $oForm->setData($oRequest->getPost());
         if ($oForm->isValid()) {
             try {
                 $this->getTableRoster()->beginTransaction();
                 $oEntite = $this->getTableRoster()->saveOrUpdateRoster($oEntite);
                 $this->getTableRoster()->commit();
                 $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Le roster a été modifié avec succès."), 'success');
                 return $this->redirect()->toRoute('backend-roster-list');
             } catch (\Exception $ex) {
                 // on rollback en cas d'erreur
                 $this->getTableRoster()->rollback();
                 $aAjaxEx = \Core\Util\ParseException::tranformeExceptionToArray($ex);
                 $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("La modification du roster a échoué."), 'error');
                 $this->flashMessenger()->addMessage($this->_getServTranslator()->translate($aAjaxEx['msg']), 'error');
             }
         }
     }
     // Pour optimiser le rendu
     $oViewModel = new ViewModel();
     $oViewModel->setTemplate('backend/roster/update');
     $oViewModel->setVariables(array('id' => $id, 'form' => $oForm, "roster" => $aOptRoster));
     return $oViewModel;
 }
Exemplo n.º 7
0
 /**
  * Traitement de l'import Bnet.
  *
  * @return array
  */
 public function importTraitementAction()
 {
     $aOptGuilde = array('guilde' => '', 'serveur' => '', 'lvlMin' => '', 'imp-membre' => 'Oui');
     $this->layout('layout/ajax');
     $oRequest = $this->getRequest();
     if ($oRequest->isPost()) {
         $aPost = $oRequest->getPost();
         try {
             $this->getTableGuilde()->beginTransaction();
             $this->getTableGuilde()->importGuilde($aPost);
             $this->getTableGuilde()->commit();
             $msg = $this->_getServTranslator()->translate("La guilde a été importé avec succès.");
             $this->getLogService()->log(LogService::INFO, $msg, LogService::USER, $aPost);
             // $this->flashMessenger()->addMessage($msg, 'success');
         } catch (\Exception $exc) {
             // on rollback en cas d'erreur
             $this->getTableGuilde()->rollback();
             $this->_getLogService()->log(LogService::ERR, $exc->getMessage(), LogService::USER, $aPost);
             $aAjaxEx = \Core\Util\ParseException::tranformeExceptionToArray($exc);
             $result = new JsonModel(array('error' => $aAjaxEx));
             return $result;
         }
     }
     $result = new JsonModel(array('success' => array('msg' => $this->_getServTranslator()->translate('guilde importée avec succès'))));
     return $result;
 }
Exemplo n.º 8
0
 /**
  * Traitement de l'import Bnet.
  *
  * @return array
  */
 public function importTraitementAction()
 {
     $aOptItem = array('id' => '');
     $this->layout('layout/ajax');
     //$this->layout('backend/layout');
     $oRequest = $this->getRequest();
     if ($oRequest->isPost()) {
         $aPost = $oRequest->getPost();
         $this->getTable()->beginTransaction();
         try {
             $this->getTable()->importItem($aPost);
             $this->getTable()->commit();
         } catch (\Exception $ex) {
             // on rollback en cas d'erreur
             $this->getTable()->rollback();
             $aAjaxEx = \Core\Util\ParseException::tranformeExceptionToArray($ex);
             $result = new JsonModel(array('error' => $aAjaxEx));
             return $result;
         }
     }
     $result = new JsonModel(array('success' => array('msg' => $this->_getServTranslator()->translate('Item importé avec succès'))));
     return $result;
 }
Exemplo n.º 9
0
 /**
  * Traitement de l'import Bnet.
  *
  * @return array
  */
 public function importTraitementAction()
 {
     $aOptPersonnage = array('nom' => '', 'serveur' => '');
     $this->layout('layout/ajax');
     //$this->layout('backend/layout');
     $oRequest = $this->getRequest();
     if ($oRequest->isPost()) {
         $aPost = $oRequest->getPost();
         $this->getTablePersonnage()->beginTransaction();
         try {
             $aPersoBnet = $this->getTablePersonnage()->importPersonnage($aPost);
             $oPersonnage = \Core\Util\ParserWow::extraitPersonnageDepuisBnet($aPersoBnet);
             $this->getTablePersonnage()->saveOrUpdatePersonnage($oPersonnage);
             $this->getTablePersonnage()->commit();
             $msg = $this->_getServTranslator()->translate("Le personnage a été importé avec succès.");
             $this->_getLogService()->log(LogService::INFO, $msg, LogService::USER, $aPost);
         } catch (\Exception $exc) {
             // on rollback en cas d'erreur
             $this->getTablePersonnage()->rollback();
             $this->_getLogService()->log(LogService::ERR, $exc->getMessage(), LogService::USER, $aPost);
             $aAjaxEx = \Core\Util\ParseException::tranformeExceptionToArray($exc);
             $result = new JsonModel(array('error' => $aAjaxEx));
             return $result;
         }
     }
     $result = new JsonModel(array('success' => array('msg' => $this->_getServTranslator()->translate('Personnage importé avec succès'))));
     return $result;
 }
Exemplo n.º 10
0
 /**
  * Traitement de l'import eqdkp.
  *
  * @return array
  */
 public function importTraitementAction()
 {
     $aOptImpRaid = array('serveur' => '', 'eqdkp' => '', 'nomRoster' => '', 'idRoster' => '');
     $this->layout('layout/ajax');
     $oRequest = $this->getRequest();
     if ($oRequest->isPost()) {
         try {
             $aPost = $oRequest->getPost();
             $this->getTableRaid()->beginTransaction();
             if (!isset($aPost['idRoster']) || empty($aPost['idRoster'])) {
                 $result = new JsonModel(array('error' => array('code' => 500, 'msg' => 'roster inconnu')));
                 return $result;
             }
             $aRaid = $this->importEqdkp($aPost['txtImport']);
             if (!isset($aRaid['head']['export']['name']) || $aRaid['head']['export']['name'] !== "EQdkp Plus XML") {
                 $result = new JsonModel(array('error' => array('code' => 500, 'msg' => 'format XML non reconnu')));
                 return $result;
             } else {
                 $this->saveImport($aRaid, $aPost);
             }
             $aRaid = $this->importEqdkp($aPost['txtImport']);
             $this->getTableRaid()->commit();
         } catch (\Exception $ex) {
             // on rollback en cas d'erreur
             $this->getTableRaid()->rollback();
             $aAjaxEx = \Core\Util\ParseException::tranformeExceptionToArray($ex);
             $result = new JsonModel(array('error' => $aAjaxEx));
             return $result;
         }
     }
     $result = new JsonModel(array('success' => array('msg' => $this->_getServTranslator()->translate('Raid importée avec succès'))));
     return $result;
 }
Exemplo n.º 11
0
 public function ajaxProgressAction()
 {
     $oRoster = $this->valideKey();
     $oRequest = $this->getRequest();
     if (!$oRoster) {
         $this->flashMessenger()->addMessage('La clé Roster renseignée est incorrecte.', 'error');
         return $this->redirect()->toRoute('home');
     }
     if ($oRequest->isPost()) {
         $aPost = $oRequest->getPost();
         $aPallier = json_decode($aPost['value']);
         try {
         } catch (Exception $exc) {
             $ex = \Core\Util\ParseException::getCause($exc);
             $this->_getLogService()->log(LogService::ERR, $exc->getMessage(), LogService::USER, $this->getRequest()->getPost());
             $this->flashMessenger()->addMessage($exc->getMessage(), 'error');
         }
     }
     return new JsonModel(array('Garosh' => 5, 'Thrall' => 22));
 }
 /**
  * Action pour la majour des personnage du roster.
  *
  * @return array
  */
 public function majAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     try {
         $oEntite = $this->getTableRoster()->findRow($id);
         if (!$oEntite) {
             $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Identifiant de roster inconnu."), 'error');
             return $this->redirect()->toRoute('backend-roster-list');
         }
     } catch (\Exception $ex) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Une erreur est survenue lors de la récupération du roster."), 'error');
         return $this->redirect()->toRoute('backend-roster-list');
     }
     $this->layout('layout/ajax');
     $oRequest = $this->getRequest();
     try {
         $oTabRosterHasPersonnage = $this->getTableRosterHasPersonnage()->select(array('idRoster' => $id));
         if (isset($oTabRosterHasPersonnage)) {
             foreach ($oTabRosterHasPersonnage as $aCharacter) {
                 $oPerso = $this->getTablePersonnage()->findRow($aCharacter['idPersonnage']);
                 $aPersonnage = array('serveur' => $oPerso->getRoyaume(), 'nom' => $oPerso->getNom());
                 $aPersoBnet = $this->getTablePersonnage()->importPersonnage($aPersonnage);
                 $oPersonnage = \Core\Util\ParserWow::extraitPersonnageDepuisBnet($aPersoBnet);
                 $this->getTablePersonnage()->saveOrUpdatePersonnage($oPersonnage);
             }
         }
         return new JsonModel(array('success' => array('msg' => $this->_getServTranslator()->translate('Personnage mis à jour avec succès'))));
     } catch (\Exception $ex) {
         $aAjaxEx = \Core\Util\ParseException::tranformeExceptionToArray($ex);
         $result = new JsonModel(array('error' => $aAjaxEx));
         return $result;
     }
 }
Exemplo n.º 13
0
 /**
  * Fetch a resource
  *
  * @param  mixed $id
  * @return LogApiProblem|mixed
  */
 public function fetch($id)
 {
     try {
         $sNom = $this->getEvent()->getRouteParam('character_id');
         $sServer = $this->getEvent()->getRouteParam('api-character-server');
         $key = $this->getRequestKey('APIBlizzard-character', array($sNom, $sServer));
         if ($this->cache->hasItem($key) === true) {
             return $this->cache->getItem($key);
         }
         $aPost = array('serveur' => $sServer, 'nom' => $sNom);
         $aOptionBnet = array();
         $oPersonnage = $this->getTablePersonnage()->importPersonnage($aPost, null, $aOptionBnet);
         $oReturn = $oPersonnage->jsonSerialize();
         $oReturn['race'] = $this->_tableRace->findRow($oReturn['race'])->getNom();
         $oReturn['class'] = $this->_tableClasses->findRow($oReturn['class'])->getNom();
         $oReturn['gender'] = $oReturn['gender'] == 0 ? "Male" : "Female";
         $this->addItem($key, $oReturn);
         return $oReturn;
     } catch (\Exception $ex) {
         return \Core\Util\ParseException::tranformeExceptionToApiProblem($ex, $this->_service);
     }
 }