Esempio n. 1
0
 /**
  * Récupère les articles d'un commande via la commande.
  *
  * @param Commande $uneCommande numéro d'une commande
  * @param bool $index
  *
  * @return Collection
  *
  * @throws CollectionException
  * @throws ErrorSQLException
  */
 public static function getUneCommande(Commande $uneCommande, $index = false)
 {
     $lesArticles = new Collection();
     try {
         $conn = MConnexion::getBdd();
         $conn->beginTransaction();
         $req = !$index ? $conn->prepare('SELECT * FROM commander INNER JOIN article ON commander.numArt = article.numArt WHERE numCde = ? ORDER BY pu DESC') : $conn->prepare('SELECT * FROM commander INNER JOIN article ON commander.numArt = article.numArt WHERE numCde = ? ORDER BY pu DESC LIMIT 2');
         $req->execute(array($uneCommande->getId()));
         $req = $req->fetchAll();
         foreach ($req as $tabs) {
             $unArticle = MArticle::getArticle($tabs['numArt']);
             $unArticle->setQte($tabs['qte']);
             $lesArticles->ajouter($unArticle);
         }
         $conn->commit();
     } catch (PDOException $e) {
         throw new ErrorSQLException('Impossible de récupérer la commande n°' . $uneCommande->getId() . ' Détails : ' . $e->getMessage());
     }
     return $lesArticles;
 }