This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addMovie.php
102 lines (83 loc) · 2.58 KB
/
addMovie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
include 'vendor/autoload.php';
require_once 'models/MoviesManager.php';
require_once 'models/DirectorsManager.php';
require_once 'classes/Director.php';
require_once 'classes/Movie.php';
if($_SERVER['REQUEST_METHOD'] == "GET"){
try {
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);
$template = $twig->loadTemplate('AdditionPage.html');
$genres = ["Action", "Animation", "Aventure", "Catastrophe", "Comedie", "Documentaire", "Drame", "Fantaisie", "Horreur", "Science-fiction", "Western"];
echo $template->render(array(
'genres' => $genres
));
} catch (Exception $e) {
die('ERROR: ' . $e->getMessage());
}
} else {
$name = null;
$realizationYear = null;
$genre = null;
$studio = null;
$synopsis = null;
$directorName = null;
$posterUrl = null; // TODO
$useApi = null;
$moviesManager = new MoviesManager();
$directorsManager = new DirectorsManager();
if(!empty($_POST['movieName']) && strlen($_POST['movieName'])<=100) {
$name = $_POST['movieName'];
} else {
showError();
return;
}
if(!empty($_POST['movieYear']) && $_POST['movieYear'] > 1800) {
$realizationYear = $_POST['movieYear'];
} else {
showError();
return;
}
if(!empty($_POST['movieDirector']) && strlen($_POST['movieDirector'])<=100) {
$directorName = $_POST['movieDirector'];
} else {
showError();
return;
}
if(!empty($_POST['movieStudio']) && strlen($_POST['movieStudio'])<=100) {
$studio = $_POST['movieStudio'];
} else {
showError();
return;
}
if(!empty($_POST['movieGenre'])) {
$genre = $_POST['movieGenre'];
} else {
showError();
return;
}
if(strlen($_POST['movieSynopsis'])<=300) {
$synopsis = $_POST['movieSynopsis'];
} else {
showError();
return;
}
// if(!isset($_POST['useAPI']) || $_POST['useAPI'] != "on") {
// $useApi = false;
// } else {
// $useApi = true;
// }
$useApi = true;
if(is_null($directorsManager->getDirector($directorName))) {
$director = new Director($directorName);
$directorsManager->addDirector($director);
}
$movie = new Movie($name, $realizationYear, $genre, $studio, $synopsis, $directorName, $synopsis, $useApi);
$moviesManager->addMovie($movie);
header('Location: yourCollection.php');
exit();
}
function showError() {
echo "Une erreur est survenue lors de l'ajout du film.";
}