2021-04-28 21:46:10 +02:00
< ? php
2021-05-06 07:32:24 +02:00
include_once ( 'film.php' );
$template = new Template ();
2021-05-06 18:55:59 +02:00
$prefix = $template -> get_prefix ();
2021-04-28 21:46:10 +02:00
include_once ( $prefix . 'assets/php/dao.php' );
2021-05-06 07:32:24 +02:00
2021-04-28 21:46:10 +02:00
class Film_DAO extends DAO {
//Constructor:
function __construct ( $bd_name ){
parent :: __construct ( $bd_name );
}
//Methods:
//Create a new Session.
2021-05-13 20:06:05 +02:00
public function createFilm ( $id , $tittle , $duration , $language , $description , $img ){
$sql = sprintf ( " INSERT INTO `film`( `id`, `tittle`, `duration`, `language`,`description`, `img`)
VALUES ( '%d' , '%s' , '%d' , '%s' , '%s' , '%s' ) " ,
$id , $tittle , $duration , $language , $description , $img );
2021-04-28 21:46:10 +02:00
$resul = mysqli_query ( $this -> mysqli , $sql ) or die ( 'Error into query database' );
return $resul ;
}
//Returns a film data .
public function GetFilm ( $tittle , $language ){
$sql = sprintf ( " SELECT * FROM film WHERE film.tittle = '%s'AND film.language='%s' " , $tittle , $language );
$resul = mysqli_query ( $this -> mysqli , $sql ) or die ( 'Error into query database' );
return $resul ;
}
//Returns a query to get the film's data.
public function FilmData ( $id ){
$sql = sprintf ( " SELECT * FROM film WHERE id = '%d' " , $id );
$resul = mysqli_query ( $this -> mysqli , $sql ) or die ( 'Error into query database' );
return $resul ;
}
//Returns a query to get All the films.
public function allFilmData (){
$sql = sprintf ( " SELECT * FROM film " );
$resul = mysqli_query ( $this -> mysqli , $sql ) or die ( 'Error into query database' );
while ( $fila = $resul -> fetch_assoc ()){
2021-05-13 20:06:05 +02:00
$films [] = $this -> loadFilm ( $fila [ " id " ], $fila [ " tittle " ], $fila [ " duration " ], $fila [ " language " ], $fila [ " description " ], $fila [ " img " ]);
2021-04-28 21:46:10 +02:00
}
$resul -> free ();
return $films ;
}
//Returns a query to get all films tittles.
public function tittleFilmData (){
$sql = sprintf ( " SELECT DISTINCT tittle FROM film " );
$resul = mysqli_query ( $this -> mysqli , $sql ) or die ( 'Error into query database' );
return $resul ;
}
//Returns a query to get all films descriptions.
public function descriptionFilmData (){
$sql = sprintf ( " SELECT description FROM film " );
$resul = mysqli_query ( $this -> mysqli , $sql ) or die ( 'Error into query database' );
return $resul ;
}
/*
public function addFilm ( $films ) {
$resul = mysqli_query ( $this -> mysqli , $this -> createFilm ( $film . getId (), $film . getTittle (), $film . getDuration (), $film . getLanguage (), $film . getDescription ())) or die ( 'Error into query database' );
return $resul ;
}
*/
//Deleted film by "id".
public function deleteFilm ( $id ){
$sql = sprintf ( " DELETE FROM film WHERE film.id = '%d' ; " , $id );
$resul = mysqli_query ( $this -> mysqli , $sql ) or die ( 'Error into query database' );
return $resul ;
}
//Edit a film.
2021-05-13 20:06:05 +02:00
public function editFilm ( $id , $tittle , $duration , $language , $description , $img ){
$sql = sprintf ( " UPDATE film SET tittle = '%s' , duration = '%d', language ='%s' , description ='%s', img ='%s'
2021-04-28 21:46:10 +02:00
WHERE film . id = '%d' ; " ,
2021-05-13 20:06:05 +02:00
$tittle , $duration , $language , $description , $img , $id );
2021-04-28 21:46:10 +02:00
$resul = mysqli_query ( $this -> mysqli , $sql ) or die ( 'Error into query database' );
return $resul ;
}
//Create a new film Data Transfer Object.
2021-05-13 20:06:05 +02:00
public function loadFilm ( $id , $tittle , $duration , $language , $description , $img ){
return new Film ( $id , $tittle , $duration , $language , $description , $img );
2021-04-28 21:46:10 +02:00
}
}
?>