/** * Récupère les commandes dont l'utilisateur est passé en paramètre. * * @param Utilisateur $unClient * @param bool $index * * @return Collection $lesCommandes * * @throws CollectionException * @throws ErrorSQLException */ public static function getCommandes(Utilisateur $unClient, $index = false) { $lesCommandes = new Collection(); try { $conn = MConnexion::getBdd(); $req = !$index ? $conn->prepare('SELECT * FROM commande WHERE numClt = ? ORDER BY date DESC') : $conn->prepare('SELECT * FROM commande WHERE numClt = ? ORDER BY date DESC LIMIT 2'); $req->execute(array($unClient->getId())); $req = $req->fetchAll(); foreach ($req as $tabs) { $uneCommande = new Commande($tabs['numCde'], $unClient, $tabs['date'], $tabs['pointsUtilise']); $uneCommande->setLesArticles(MCommander::getUneCommande($uneCommande)); $lesCommandes->ajouter($uneCommande); } } catch (PDOException $e) { throw new ErrorSQLException($e->getMessage()); } return $lesCommandes; }
/** * Récupère la réservation en cours du client * * @param Utilisateur $unClient * * @return Reservation * * @throws CollectionException * @throws ErrorSQLException */ public static function getReservationClient(Utilisateur $unClient) { $uneReservation = new Reservation(); try { $conn = MConnexion::getBdd(); $reqPrepare = $conn->prepare('SELECT reservation.numVol, reservation.numRes, dateRes, nbPers, montant, dateEcheance FROM reservation LEFT JOIN echeance ON reservation.numRes = echeance.numRes INNER JOIN vol ON reservation.numVol = vol.numVol WHERE NumClt = ? AND curdate() < vol.dateVol'); $reqPrepare->execute([$unClient->getId()]); $fetch = $reqPrepare->fetch(); $unVol = MVol::getUnVol($fetch['numVol']); $uneReservation->setId($fetch['numRes'])->setUnVol($unVol)->setUnClient($unClient)->setDateRes($fetch['dateRes'])->setNbPers($fetch['nbPers'])->setValid(true); $lesEcheances = MEcheance::getEcheances($uneReservation); $uneReservation->setLesEcheance($lesEcheances); $conn = null; } catch (PDOException $e) { echo $e->getMessage(); throw new ErrorSQLException('Impossible de récupérer la réservation de ' . $unClient->getMail() . ' Détails : ' . $e->getMessage()); } return $uneReservation; }
/** * Met à jour le nombre de points d'un client * * @param Utilisateur $user * @param int $points * * @throws ErrorSQLException */ public static function setPoints(Utilisateur $user, $points) { try { $conn = MConnexion::getBdd(); $reqPrepare = $conn->prepare('UPDATE client SET pointsClt = ? WHERE numClt = ?'); $reqPrepare->execute([$points, $user->getId()]); $user->setPoints($points); $conn = null; } catch (PDOException $ex) { throw new ErrorSQLException("L'utilisateur n°{$user->getId()} n'existe pas."); } }