/** * Récupère les séances du spectacle $spectacle * @param Spectacle $spectacle * @return Collection * @throws \Exception */ public static function getSeancesBySpec(Spectacle $spectacle) { try { $conn = Main::bdd(); $reqPrepare = $conn->prepare("SELECT * FROM seance WHERE idSpectacle = ?"); $reqPrepare->execute(array($spectacle->getId())); $tabs = $reqPrepare->fetchAll(); $coll = new Collection(); foreach ($tabs as $tab) { $lieu = MLieu::getLieuById($tab['idLieu']); $seance = new Seance($tab['idSeance'], $spectacle, new \DateTime($tab['date_heure']), $lieu); $coll->ajouter($seance); } return $coll; } catch (\PDOException $e) { throw new \Exception("Il n'y a aucune séance pour le spectacle " . $spectacle->getNom()); } catch (KeyHasUseException $ex) { throw new \Exception($ex->getMessage()); } }
/** * Ajoute un spectacle * @param Spectacle $spectacle * @throws \Exception */ public static function addSpectacle(Spectacle $spectacle) { $conn = Main::bdd(); try { $conn->beginTransaction(); $reqPrepare = $conn->prepare("INSERT INTO spectacle (nomSpectacle, nbPlaceSpectacle, typeClasse, typeSpectacle) VALUES (?,?,?,?)"); $reqPrepare->execute(array($spectacle->getNom(), $spectacle->getNbPlace(), $spectacle->getTypeClasse(), $spectacle->getTypeSpectacle())); $conn->commit(); } catch (\PDOException $e) { $conn->rollBack(); throw new \Exception("L'ajout du spectacle " . $spectacle->getId() . " a échoué. Détails : <p>" . $e->getMessage() . "</p>"); } }