Example #1
0
 /**
  * Permet de valider la réservation en paramètre. Gère le paiement en plusieurs
  * échéances
  *
  * @param Utilisateur $unClient
  * @param Vol         $unVol
  * @param Reservation $uneReservation
  *
  * @throws CollectionException
  * @throws ErrorSQLException
  */
 public static function validerReservation(Utilisateur $unClient, Vol $unVol, Reservation $uneReservation)
 {
     $conn = MConnexion::getBdd();
     try {
         $conn->beginTransaction();
         $reqPrepare = $conn->prepare('INSERT INTO reservation (numClt,numVol,dateRes,nbPers) VALUES (?,?,?,?)');
         $reqPrepare->execute([$unClient->getId(), $unVol->getNumVol(), $uneReservation->getDateRes()->format('Y-m-d H:i:s'), $uneReservation->getNbPers()]);
         $conn->commit();
         $uneReservation->setValid(true);
         $conn->beginTransaction();
         $lesEcheances = new Collection();
         $uneAutreReservation = self::getReservationClient($unClient);
         if (array_key_exists('type', $_GET)) {
             if ($_GET['type'] === '3fois') {
                 $echeance = new Echeance($uneAutreReservation, $uneAutreReservation->getFirstEcheancePrice(), new \DateTime());
                 MEcheance::addEcheance($echeance);
                 $lesEcheances->ajouter($echeance);
                 $echeance = new Echeance($uneAutreReservation, $uneAutreReservation->getOtherEcheancePrice(), new \DateTime('+1 months +1 days'));
                 MEcheance::addEcheance($echeance);
                 $lesEcheances->ajouter($echeance);
                 $echeance = new Echeance($uneAutreReservation, $uneAutreReservation->getOtherEcheancePrice(), new \DateTime('+2 months +1 days'));
                 MEcheance::addEcheance($echeance);
                 $lesEcheances->ajouter($echeance);
             } else {
                 $echeance = new Echeance($uneAutreReservation, $uneAutreReservation->getPriceReservation(), new \DateTime());
                 MEcheance::addEcheance($echeance);
                 $lesEcheances->ajouter($echeance);
             }
         }
         $conn->commit();
         $uneReservation->setLesEcheance($lesEcheances);
         $points = MUtilisateur::getPoints($unClient) - $uneReservation->getReduction();
         MUtilisateur::setPoints($unClient, $points + Build::newPoints($uneReservation->getPriceReservation()));
         $conn = null;
     } catch (PDOException $e) {
         $conn->rollBack();
         $uneReservation->setValid(false);
         throw new ErrorSQLException('Vous avez déjà une réservation.
             Veuillez contacter Nostromo pour annuler votre réservation.');
     }
 }
Example #2
0
 /**
  * Récupère le temps avant qu'un vol ne parte
  *
  * @param Vol $unVol
  *
  * @return string
  *
  * @throws ErrorSQLException
  * @throws InvalidArgumentException
  */
 public static function getTimer(Vol $unVol)
 {
     if (null === $unVol) {
         throw new InvalidArgumentException('Le vol ne peut pas être null');
     }
     try {
         $conn = MConnexion::getBdd();
         $req = $conn->prepare('SELECT * FROM vol WHERE dateVol = ?');
         $req->execute([$unVol->getNonFormatDate()]);
         $fetch = $req->fetch();
         $tmp = new \DateTime($fetch['dateVol'] . ' ' . $fetch['heureVol']);
         $tmp->modify('-1 months');
         return $tmp->format('Y, m, d, H, i, s');
     } catch (PDOException $e) {
         throw new ErrorSQLException($e->getMessage());
     }
 }