Exemplo n.º 1
0
 /**
  * Met les Unites de la collection dans le UniteStore
  * Vérifie si le Unite était déjà storé, dans ce cas, remplace le Unite concerné par celui du UniteStore
  */
 public function store()
 {
     $replaces = array();
     foreach ($this as $offset => $unite) {
         /** @var Unite $unite */
         if (UniteStore::exists($unite->getId())) {
             $replaces[$offset] = $unite;
         } else {
             UniteStore::store($unite);
         }
     }
     unset($offset);
     foreach ($replaces as $offset => $unite) {
         $this->offsetSet($offset, UniteStore::getById($unite->getId()));
     }
 }
Exemplo n.º 2
0
 /**
  * @return void
  */
 public function main()
 {
     $ret = array('error' => 0, 'errorMsg' => '', 'debug' => '');
     while (true) {
         if (is_null($this->getHttp()->getGet('idUnite'))) {
             $ret['error'] = 1;
             $ret['errorMsg'] = "Données manquantes (idUnite)";
             break;
         }
         $idUnite = $this->getHttp()->getGet('idUnite');
         $token = null;
         if (!is_null($this->getHttp()->getCookie('token'))) {
             $token = $this->getHttp()->getCookie('token');
         } elseif ($this->getHttp()->getGet('token')) {
             $token = $this->getHttp()->getGet('token');
         } elseif ($this->getHttp()->getPost('token')) {
             $token = $this->getHttp()->getPost('token');
         }
         if (is_null($token)) {
             $ret['error'] = 2;
             $ret['errorMsg'] = "Pas de token de session";
             break;
         }
         $session = SessionStore::getByToken($token);
         $unite = UniteStore::getById($idUnite);
         if (is_null($unite)) {
             $ret['error'] = 2;
             $ret['errorMsg'] = "Unite inconnue";
             break;
         }
         if ($unite->getQg()->getIdJoueur() != $session->getIdJoueur()) {
             $ret['error'] = 3;
             $ret['errorMsg'] = "Unite inconnue";
             break;
         }
         $nlleUnite = UniteBusiness::getById($idUnite);
         $unite->setIdQgTransfert($nlleUnite->getIdQgTransfert());
         $unite->resetJson();
         CacheCarte::$infosVisibles = array();
         break;
     }
     $this->output('rienDuTout(' . json_encode($ret) . ');');
 }
Exemplo n.º 3
0
 /**
  * Renvoie le Qg lié
  * @return Qg
  */
 public function getQg()
 {
     return QgStore::getById(UniteStore::getById($this->getIdUnite())->getIdQg());
 }
Exemplo n.º 4
0
 /**
  * Renvoie le Unite lié
  * @return Unite
  */
 public function getUnite()
 {
     return UniteStore::getById($this->getIdUnite());
 }
Exemplo n.º 5
0
 public function annulTransfertUnite()
 {
     $ret = array('error' => 0, 'errorMsg' => '');
     if (!isset($_POST['idUnite'])) {
         $ret['error'] = 1;
         $ret['errorMsg'] = 'Champs manquants';
         echo json_encode($ret);
         exit;
     }
     if (!$this->checkDroit(Droit::LOGGE_PARTIE)) {
         $ret['error'] = 2;
         $ret['errorMsg'] = 'Pas le droit';
         echo json_encode($ret);
         exit;
     }
     $unite = UniteStore::getById($_POST['idUnite']);
     if (is_null($unite)) {
         $ret['error'] = 3;
         $ret['errorMsg'] = 'Unité inexistante';
         echo json_encode($ret);
         exit;
     }
     $ret['idUnite'] = $unite->getId();
     $ret['idQg'] = $unite->getQg()->getId();
     if ($unite->getQg()->getIdJoueur() != SessionBusiness::getCookieSession()->getIdJoueur()) {
         $ret['error'] = 4;
         $ret['errorMsg'] = 'Le qg de l\'unité doit appartenir au joueur connecté';
         echo json_encode($ret);
         exit;
     }
     /*
      * Annulation du transfert de l'unité
      */
     $unite->setIdQgTransfert(0);
     $unite->save();
     echo json_encode($ret);
 }