mmi-correction-tp03/tests/test.php
2015-04-07 21:25:31 +02:00

200 lines
6.2 KiB
PHP

<?php
require __DIR__.'/autoload.php';
/**
* Catégories de films
*/
$categorieAction = new Categorie('Action');
$categorieScienceFiction = new Categorie('Science Fiction');
$categorieHumour = new Categorie('Humour');
/**
* Format de films
*/
$formatDvd = new Format('DVD');
$formatBlueray = new Format('Blue Ray');
$formatVHS = new Format('VHS');
/**
* Pays
*/
$paysUSA = new Pays('USA');
/**
* Films
*/
$filmMatrix = new Video();
$filmMatrix
->setTitre('The Matrix')
->setDuree(2 * 60 + 15) // 2h15 en minutes
->setSynopsis("Programmeur anonyme dans un service administratif le jour, Thomas Anderson devient Neo la nuit venue. Sous ce pseudonyme, il est l'un des pirates les plus recherchés du cyber-espace. A cheval entre deux mondes, Neo est assailli par d'étranges songes et des messages cryptés provenant d'un certain Morpheus. Celui-ci l'exhorte à aller au-delà des apparences et à trouver la réponse à la question qui hante constamment ses pensées : qu'est-ce que la Matrice ? Nul ne le sait, et aucun homme n'est encore parvenu à en percer les defenses. Mais Morpheus est persuadé que Neo est l'Elu, le libérateur mythique de l'humanité annoncé selon la prophétie. Ensemble, ils se lancent dans une lutte sans retour contre la Matrice et ses terribles agents...");
$paysUSA->addVideo($filmMatrix);
$filmScaryMovie = new Video();
$filmScaryMovie->setTitre('Scary Movie');
$filmScaryMovie->setDuree(1 * 60 + 24); // 1h24
$filmScaryMovie->addPays($paysUSA);
$filmScaryMovie->setSynopsis("Un soir, Drew Becker recoit un appel anonyme d'un maniaque. Traquée dans sa maison, puis dans son jardin, elle finit par se faire tuer. Sa mort plonge ses camarades de lycée en plein cauchemar, d'autant qu'ils doivent désormais faire face à un tueur en série, caché parmi eux. Flairant le scoop, la journaliste Gail Hailstorn débarque en ville, bien décidée à harceler Cindy Campbell et ses amis à propos de cette histoire...");
/**
* Réalisateurs
*/
$realisateurScaryMovie = new Participant('Wayans', 'Keenen Ivory');
$realisateurMatrix1 = new Participant('Wachowski', 'Lana');
$realisateurMatrix2 = new Participant('Wachowski', 'Andy');
/**
* Acteurs
*/
$acteurScaryMovie1 = new Participant('Anna', 'Faris');
$acteurScaryMovie2 = new Participant('Shawn', 'Wayans');
$acteurScaryMovie3 = new Participant('Marlon', 'Wayans');
$acteurMatrix1 = new Participant('Keanu', 'Reeves');
$acteurMatrix2 = new Participant('Laurence', 'Wayans');
$acteurMatrix3 = new Participant('Carrie-Anne', 'Wayans');
/**
* Et on associe tout le monde...
*/
// Films <-> Categorie
$filmMatrix->addCategorie($categorieAction);
$filmMatrix->addCategorie($categorieScienceFiction);
$categorieHumour->addVideo($filmScaryMovie);
// Participants <-> Pays
$acteurMatrix1->setPays($paysUSA);
$acteurMatrix2->setPays($paysUSA);
// une autre manière de la faire
$paysUSA->addParticipant($acteurMatrix3);
$acteurScaryMovie1->setPays($paysUSA);
$acteurScaryMovie2->setPays($paysUSA);
$acteurScaryMovie3->setPays($paysUSA);
// Acteurs <-> films
$acteurMatrix1->addVideoJouee($filmMatrix);
$filmMatrix->addActeur($acteurMatrix2);
$filmMatrix->addActeur($acteurMatrix3);
$filmMatrix
->addRealisateur($realisateurMatrix1)
->addRealisateur($realisateurMatrix2);
$filmScaryMovie
->setActeurs([
$acteurScaryMovie1,
$acteurScaryMovie2,
$acteurScaryMovie3,
]);
$realisateurScaryMovie->addVideoRealisee($filmScaryMovie);
// Les formats
$formatBlueray->addVideo($filmMatrix);
$filmMatrix->addFormat($formatVHS);
$filmMatrix->addFormat($formatDvd);
$formatDvd->addVideo($filmScaryMovie);
$formatVHS->addVideo($filmScaryMovie);
/**
* On affiche les résultats par différents moyens...
*/
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>J'aime les pommes</title>
</head>
<body>
<h1>Pays</h1>
<?php foreach([$paysUSA] as $pays): ?>
<h2><?php echo $pays->getNom(); ?></h2>
<h3>Participants</h3>
<ul>
<?php foreach($pays->getParticipants() as $participant): ?>
<li>
<?php echo $participant->getPrenom(); ?> <?php echo $participant->getNom(); ?>
</li>
<?php endforeach; ?>
</ul>
<h3>Vidéos</h3>
<ul>
<?php foreach($pays->getVideos() as $video): ?>
<li>
<h4><?php echo $video->getTitre(); ?> (Durée : <?php echo $video->getDuree(); ?> minutes)</h4>
<h5>Catégorie(s)</h5>
<ul>
<?php foreach($video->getCategories() as $categorie): ?>
<li><?php echo $categorie->getLib(); ?></li>
<?php endforeach; ?>
</ul>
<h5>Type(s)</h5>
<ul>
<?php foreach($video->getTypes() as $type): ?>
<li><?php echo $type->getLib(); ?></li>
<?php endforeach; ?>
</ul>
<blockquote><?php echo $video->getSynopsis(); ?></blockquote>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
<h1>Vidéos</h1>
<?php foreach([$filmScaryMovie, $filmMatrix] as $video): ?>
<h2><?php echo $video->getTitre(); ?></h2>
<p><?php echo $video->getSynopsis(); ?></p>
<p><em><?php echo $video->getDuree(); ?> minutes</em></p>
<h3>Réalisateur(s)</h3>
<ul>
<?php foreach($video->getRealisateurs() as $realisateur): ?>
<li>
<?php echo $realisateur->getPrenom(); ?> <?php echo $realisateur->getNom(); ?>
</li>
<?php endforeach; ?>
</ul>
<h3>Acteurs</h3>
<ul>
<?php foreach($video->getActeurs() as $acteur): ?>
<li>
<?php echo $acteur->getPrenom(); ?> <?php echo $acteur->getNom(); ?>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
<h1>Formats</h1>
<?php foreach([$formatVHS, $formatDvd, $formatBlueray] as $format): ?>
<h2><?php echo $format->getLib(); ?></h2>
<h3>Films(s)</h3>
<ul>
<?php foreach($format->getVideos() as $video): ?>
<li>
<?php echo $video->getTitre(); ?>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
</body>
</html>