Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
ajout du genre refs#1
Browse files Browse the repository at this point in the history
  • Loading branch information
lduboeuf committed Jun 28, 2017
1 parent a58dd60 commit d0a317a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 51 deletions.
2 changes: 2 additions & 0 deletions film-form-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
$auteur = filter_input(INPUT_POST, 'auteur', FILTER_SANITIZE_STRING);
$acteurs = filter_input(INPUT_POST, 'acteurs', FILTER_SANITIZE_STRING);
$date_sortie = filter_input(INPUT_POST, 'date_sortie', FILTER_SANITIZE_STRING);
$genre = filter_input(INPUT_POST, 'genre', FILTER_VALIDATE_INT);

if ($titre && $auteur && $acteurs ){

$film['titre'] = $titre;
$film['auteur'] = $auteur;
$film['acteurs'] = $acteurs;
$film['date_sortie'] = $date_sortie;
$film['genre'] = $genre;
$res = FilmDAO::save($film);

if ($res){
Expand Down
23 changes: 22 additions & 1 deletion film-form.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@

<style>
#film-form label{
display: block;
width: 150px;
float: left;
}

</style>
<form id="film-form" action="index.php?page=film-form-handler" method="post">
<fieldset>
<legend>Nouveau film</legend>
<p>
<label for="titre">titre :</label>
<input type="text" name="titre" placeholder="titre du film" required/>
</p>
<p>
<label for="titre">auteur :</label>
<input type="text" name="auteur" placeholder="auteur" required/>
</p>
<p>
<label for="titre">acteurs :</label>
<input type="text" name="acteurs" placeholder="acteurs required"/>
</p>
<p>
<label for="titre">année de sortie :</label>
<input name="date_sortie" placeholder="date de sortie" required/>
</p>
<p>
<label for="genre">genre :</label>
<?php include('view/genre-list.php'); ?>
</p>
<p>
<input type="submit" name="ok" value="ok"/>
<input type="reset" name="reset" value="effacer"/>
</p>
</fieldset>
</form>

Expand Down
1 change: 1 addition & 0 deletions film-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
$film['thumbnail'] = "http://via.placeholder.com/300x400";
}
echo '<li film-id="'.$film['id'].'"><div><img src="'.$film['thumbnail'].'"/><h3>'.$film['titre'].'</h3><p class="auteur">réalisé par:'.$film['auteur'].'</p>';
echo '<p>Genre: '.$film['genre'].'</p>';
if (in_array($film['id'], $vus)){
echo '<a class="bookmark seen" href="javascript:void();"></a>';
}else{
Expand Down
13 changes: 8 additions & 5 deletions model/dao/FilmDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class FilmDAO {
* @return type tableau de film
*/
public static function findAll(){
$bdd = connectDB();
$stmt = $bdd->query('SELECT * from film');
return $stmt->fetchAll(PDO::FETCH_ASSOC);
$bdd = connectDB();
$stmt = $bdd->query('SELECT film.id, film.titre, film.auteur, film.acteurs, film.date_sortie,film.thumbnail, genre.nom as genre from film INNER JOIN genre ON film.genre_id = genre.id');
$res = $stmt->fetchAll(PDO::FETCH_ASSOC);
//var_dump($res);
return $res;

}

Expand Down Expand Up @@ -57,12 +59,13 @@ public static function findByBookMarked($userId){
public static function save($film){
$bdd = connectDB();
$stmt = $bdd->prepare('
INSERT INTO film ( titre, auteur, acteurs, date_sortie)
VALUES (:titre, :auteur, :acteurs, :date_sortie)');
INSERT INTO film ( titre, auteur, acteurs, date_sortie, genre_id)
VALUES (:titre, :auteur, :acteurs, :date_sortie, :genre)');
$stmt->bindValue(':titre', $film['titre'], PDO::PARAM_STR);
$stmt->bindValue(':auteur', $film['auteur'], PDO::PARAM_STR);
$stmt->bindValue(':acteurs', $film['acteurs'], PDO::PARAM_STR);
$stmt->bindValue(':date_sortie', $film['date_sortie'], PDO::PARAM_STR);
$stmt->bindValue(':genre', $film['genre'], PDO::PARAM_INT);

$res = $stmt->execute();
if ($res){
Expand Down
22 changes: 22 additions & 0 deletions model/dao/GenreDAO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
include('DBConnect.php');
/**
* Description of Genre
*
* @author lionel
*/
class GenreDAO {



/**
*
* @return type tableau de genre
*/
public static function findAll(){
$bdd = connectDB();
$stmt = $bdd->query('SELECT * from genre');
return $stmt->fetchAll(PDO::FETCH_ASSOC);

}
}
73 changes: 28 additions & 45 deletions resources/film.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Jun 22, 2017 at 11:32 AM
-- Generation Time: Jun 28, 2017 at 09:15 AM
-- Server version: 5.7.18-0ubuntu0.17.04.1
-- PHP Version: 7.0.18-0ubuntu0.17.04.1

Expand Down Expand Up @@ -32,44 +32,27 @@ CREATE TABLE `film` (
`auteur` varchar(256) NOT NULL,
`acteurs` varchar(1024) NOT NULL,
`date_sortie` year(4) NOT NULL,
`thumbnail` varchar(256) DEFAULT NULL
`thumbnail` varchar(256) DEFAULT NULL,
`genre_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `film`
--

INSERT INTO `film` (`id`, `titre`, `auteur`, `acteurs`, `date_sortie`, `thumbnail`) VALUES
(1, 'Bernie', 'Dupontel Albert', 'Dupontel Albert', 1996, 'http://fr.web.img6.acsta.net/medias/nmedia/18/64/13/46/18754633.jpg'),
(2, 'sdf', 'sdf', 'sdf', 2011, NULL),
(3, 'sdcsd', 'sdc', 'sdc', 2015, NULL),
(4, 'sdcsd', 'sdc', 'sdc', 2015, NULL),
(5, 'rturtu', 'rtutru', 'rtutr', 2005, NULL),
(6, 'kikou des bois', 'zonote', 'talui', 2005, NULL),
(7, 'sdcsdsdcsd', 'sdcsdcsdc', 'sdcsdcsdcdc', 2004, NULL),
(8, 'taliu', 'zonote', 'pikatchou', 2005, NULL),
(9, 'hgfj', 'gfj', 'fgjf', 2014, NULL),
(10, 'ddg', 'dfgdfg', 'dfgdfg', 1986, NULL);

-- --------------------------------------------------------

--
-- Table structure for table `utilisateur`
--

CREATE TABLE `utilisateur` (
`id` int(11) NOT NULL,
`login` varchar(20) NOT NULL,
`mdp` varchar(256) NOT NULL,
`email` varchar(256) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `utilisateur`
--

INSERT INTO `utilisateur` (`id`, `login`, `mdp`, `email`) VALUES
(1, 'lionel', '$2y$10$jd3m6moA6rQ.p8OUuwO.UO3XAxml/Z6GW/.WxK1qzTnnK6py38sbS', '[email protected]');
INSERT INTO `film` (`id`, `titre`, `auteur`, `acteurs`, `date_sortie`, `thumbnail`, `genre_id`) VALUES
(1, 'Bernie', 'Dupontel Albert', 'Dupontel Albert', 1996, 'http://fr.web.img6.acsta.net/medias/nmedia/18/64/13/46/18754633.jpg', 2),
(2, 'sdf', 'sdf', 'sdf', 2011, NULL, 2),
(3, 'sdcsd', 'sdc', 'sdc', 2015, NULL, 2),
(4, 'sdcsd', 'sdc', 'sdc', 2015, NULL, 2),
(5, 'rturtu', 'rtutru', 'rtutr', 2005, NULL, 2),
(6, 'kikou des bois', 'zonote', 'talui', 2005, NULL, 2),
(7, 'sdcsdsdcsd', 'sdcsdcsdc', 'sdcsdcsdcdc', 2004, NULL, 2),
(8, 'taliu', 'zonote', 'pikatchou', 2005, NULL, 2),
(9, 'hgfj', 'gfj', 'fgjf', 2014, NULL, 2),
(10, 'ddg', 'dfgdfg', 'dfgdfg', 1986, NULL, 2),
(11, 'aaaaaa', 'fgj', 'gfjfgj', 2015, NULL, 2),
(12, 'testouille des prés', 'kikou', 'olala', 2004, NULL, 2);

--
-- Indexes for dumped tables
Expand All @@ -79,13 +62,8 @@ INSERT INTO `utilisateur` (`id`, `login`, `mdp`, `email`) VALUES
-- Indexes for table `film`
--
ALTER TABLE `film`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `utilisateur`
--
ALTER TABLE `utilisateur`
ADD PRIMARY KEY (`id`);
ADD PRIMARY KEY (`id`),
ADD KEY `genre_id` (`genre_id`);

--
-- AUTO_INCREMENT for dumped tables
Expand All @@ -95,12 +73,17 @@ ALTER TABLE `utilisateur`
-- AUTO_INCREMENT for table `film`
--
ALTER TABLE `film`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
--
-- AUTO_INCREMENT for table `utilisateur`
-- Constraints for dumped tables
--
ALTER TABLE `utilisateur`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- Constraints for table `film`
--
ALTER TABLE `film`
ADD CONSTRAINT `film_ibfk_1` FOREIGN KEY (`genre_id`) REFERENCES `genre` (`id`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
14 changes: 14 additions & 0 deletions view/genre-list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<select name="genre">
<?php
include('model/dao/GenreDAO.php');
$genres = GenreDAO::findAll();
foreach ($genres as $genre) {
echo '<option value="'.$genre['id'].'">'.$genre['nom'].'</option>';
}

?>
</select>




0 comments on commit d0a317a

Please sign in to comment.