Add files via upload

This commit is contained in:
Markines16 2021-06-07 23:16:22 +02:00 committed by GitHub
parent 3ee19f4c5f
commit d78ef81c3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 62 deletions

View File

@ -22,25 +22,20 @@ class Event implements \JsonSerializable
public static function searchEventsBetween2dates(string $start, string $end = null, $idhall, $cinema) public static function searchEventsBetween2dates(string $start, string $end = null, $idhall, $cinema)
{ {
$startDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $start);
$endDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $end);
$result = []; $result = [];
$sessions = Session::getListSessionsBetween2Dates($idhall,$cinema,$start,$end);
$sessions = Session::getListSessionsBetween2Dates($idhall,$cinema,$startDate,$endDate); if($sessions){
foreach($sessions as $s){
foreach($sessions as $s){ $e = new Event();
$e = new Event(); $dictionary = self::session2dictionary($s);
$dictionary = self::session2dictionary($s); $e = $e->dictionary2event($dictionary);
$e = $e->dictionary2event($dictionary); $result[] = $e;
$result[] = $e; }
} }
return $result; return $result;
} }
const MYSQL_DATE_TIME_FORMAT= 'Y-m-d H:i:s';
private $id; private $id;
private $title; private $title;
private $start; private $start;
@ -70,16 +65,43 @@ class Event implements \JsonSerializable
//Return an object that allows Event object to be serialized as json because private atributes cant be serialized //Return an object that allows Event object to be serialized as json because private atributes cant be serialized
public function jsonSerialize() public function jsonSerialize()
{ {
$film = Session::getThisSessionFilm($this->idfilm);
$undesirable = array(
'á','À','Á','Â','Ã','Ä','Å',
'ß','Ç',
'È','É','Ê','Ë',
'Ì','Í','Î','Ï','Ñ',
'Ò','Ó','Ô','Õ','Ö',
'Ù','Ú','Û','Ü',
'ñ'
);
$good = array(
'a','A','A','A','A','A','A',
'B','C',
'E','E','E','E',
'I','I','I','I','N',
'O','O','O','O','O',
'U','U','U','U',
'n'
);
$lan = str_replace($undesirable, $good, $film["language"]);
$o = new \stdClass(); $o = new \stdClass();
$o->id = $this->id; $o->id = $this->id;
$o->title = $this->title; $o->title = $this->title;
$o->start = $this->start->format(self::MYSQL_DATE_TIME_FORMAT); $o->start = $this->start;
$o->end = $this->end->format(self::MYSQL_DATE_TIME_FORMAT); $o->end = $this->end;
$o->start_time = $this->start_time; $o->start_time = $this->start_time;
$o->seat_price = $this->seat_price; $o->seat_price = $this->seat_price;
$o->format = $this->format; $o->format = $this->format;
$o->film = Session::getThisSessionFilm($this->idfilm); $o->film_dur = $film["duration"];
$o->date = $this->start->format("Y-m-d"); $o->film_id = $film["idfilm"];
$o->film_lan = $lan;
$o->film_img = $film["img"];
$o->date = $this->start;
return $o; return $o;
} }
@ -90,10 +112,9 @@ class Event implements \JsonSerializable
$film = Session::getThisSessionFilm($session->getIdfilm()); $film = Session::getThisSessionFilm($session->getIdfilm());
$dur = $film["duration"]+$extraDurationBetweenFilms; $dur = $film["duration"]+$extraDurationBetweenFilms;
$tittle = str_replace('_', ' ', $film["tittle"]) ; $tittle = \str_replace('_', ' ', $film["tittle"]) ;
$start = $session->getDate()." ".$session->getStartTime(); $start = $session->getDate()." ".$session->getStartTime();
$end = \date('Y-m-d H:i:s', \strtotime( $start . ' +'.$dur.' minute'));
$end = date('Y-m-d H:i:s', strtotime( $start . ' +'.$dur.' minute'));
$dictionary = array( $dictionary = array(
"id" => $session->getId(), "id" => $session->getId(),
@ -124,17 +145,16 @@ class Event implements \JsonSerializable
if (array_key_exists('start', $dictionary)) { if (array_key_exists('start', $dictionary)) {
$start = $dictionary['start']; $start = $dictionary['start'];
$startDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $start); //$start = DateTime::createFromFormat("y-m-d H:i:s", $start);
$this->start = $startDate; $this->start = $start;
} }
if (array_key_exists('end', $dictionary)) { if (array_key_exists('end', $dictionary)) {
$end = $dictionary['end'] ?? null; $end = $dictionary['end'] ?? null;
$endDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $end); $this->end = $end;
$this->end = $endDate;
} }
if (array_key_exists('idfilm', $dictionary)) { if (array_key_exists('idfilm', $dictionary)) {
$idfilm = $dictionary['idfilm'] ?? null; $idfilm = $dictionary['idfilm'] ?? null;
$this->idfilm = $idfilm; $this->idfilm = $idfilm;

View File

@ -41,11 +41,7 @@
return $bd->getAllSessions($hall, $cinema, $start, $end); return $bd->getAllSessions($hall, $cinema, $start, $end);
} }
} }
public static function searchSessionActivesAtStartTimeAndFilmDuration(){
$bd = new SessionDAO('complucine');
$bd->searchSessionActivesAtStartTimeAndFilmDuration(1, 1, 1, 1, 1);
}
public static function create_session($cinema, $hall, $start, $date, $film, $price, $format){ public static function create_session($cinema, $hall, $start, $date, $film, $price, $format){
$bd = new SessionDAO('complucine'); $bd = new SessionDAO('complucine');
if($bd ){ if($bd ){
@ -75,7 +71,6 @@
}else{ }else{
return "Ya existe una sesion con los parametros nuevos"; return "Ya existe una sesion con los parametros nuevos";
} }
} else } else
return "La session a editar no existe"; return "La session a editar no existe";
@ -91,8 +86,6 @@
} else } else
return "Esta session no existe"; return "Esta session no existe";
} else return "Error al conectarse a la base de datos"; } else return "Error al conectarse a la base de datos";
return "Se ha eliminado la session con exito";
} }
//Esto deberia estar en film.php? seguramente //Esto deberia estar en film.php? seguramente

View File

@ -6,7 +6,6 @@
function __construct($bd_name){ function __construct($bd_name){
parent::__construct($bd_name); parent::__construct($bd_name);
} }
//Methods:
//Create a new Session taking the new id,film, hall, cinema, date, start time, seat price and format saving in the database //Create a new Session taking the new id,film, hall, cinema, date, start time, seat price and format saving in the database
public function createSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){ public function createSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
@ -18,7 +17,7 @@
VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s', '%d')", VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s', '%d')",
$id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, "0"); $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, "0");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error createSession');
return $sql; return $sql;
} }
@ -26,7 +25,7 @@
//Returns a query to get the session's data. //Returns a query to get the session's data.
public function sessionData($id){ public function sessionData($id){
$sql = sprintf( "SELECT * FROM `session` WHERE id = '%d'", $id ); $sql = sprintf( "SELECT * FROM `session` WHERE id = '%d'", $id );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $id); $resul = mysqli_query($this->mysqli, $sql) or die ('Error accessing to the session with id '. $id);
while($fila=$resul->fetch_assoc()){ while($fila=$resul->fetch_assoc()){
$session = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]); $session = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
@ -39,7 +38,7 @@
//Look for a film with the id film //Look for a film with the id film
public function filmTittle($idfilm){ public function filmTittle($idfilm){
$sql = sprintf("SELECT * FROM film JOIN session ON film.id = session.idfilm WHERE session.idfilm = '%d' ", $idfilm ); $sql = sprintf("SELECT * FROM film JOIN session ON film.id = session.idfilm WHERE session.idfilm = '%d' ", $idfilm );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $idfilm); $resul = mysqli_query($this->mysqli, $sql) or die ('Error accessing to the film with id '. $idfilm);
$resul = mysqli_fetch_array($resul); $resul = mysqli_fetch_array($resul);
@ -55,7 +54,7 @@
$sql = sprintf( "SELECT * FROM session WHERE $sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'", idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
$cinema, $hall, $date, $startTime); $cinema, $hall, $date, $startTime);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error searching for a session');
$session = mysqli_fetch_array($resul); $session = mysqli_fetch_array($resul);
@ -70,17 +69,16 @@
$sessions = []; $sessions = [];
$sql = sprintf("SELECT duration FROM film WHERE id='%s'", $idfilm ); $sql = sprintf("SELECT duration FROM film WHERE id='%s'", $idfilm );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $idfilm); $resul = mysqli_query($this->mysqli, $sql) or die ('Error looking for the film duration of id '. $idfilm);
$duration = ($resul->fetch_assoc())["duration"]+10; $duration = ($resul->fetch_assoc())["duration"]+10;
$endHour = date('Y-m-d H:i:s', strtotime( $startTime . ' +'.$duration.' minute')); $endHour = date('H:i:s', strtotime( $startTime . ' +'.$duration.' minute'));
$sql = sprintf( "SELECT * FROM session WHERE $sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time BETWEEN '%s' AND '%s' ORDER BY start_time ASC;", idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time BETWEEN '%s' AND '%s' ORDER BY start_time ASC;",
$cinema, $hall, $date, $startTime, $endHour); $cinema, $hall, $date, $startTime, $endHour);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error looking for sessions between start time and start time + film duration');
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
while($fila=$resul->fetch_assoc()){ while($fila=$resul->fetch_assoc()){
$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]); $sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
@ -95,16 +93,10 @@
public function getAllSessions($hall, $cinema, $date, $end){ public function getAllSessions($hall, $cinema, $date, $end){
if($end){ if($end){
$date = $date->format("Y-m-d");
$end = $end->format("Y-m-d");
$sql = sprintf( "SELECT * FROM session WHERE $sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date BETWEEN '%s' AND '%s' ORDER BY start_time ASC;", idcinema = '%s' AND idhall = '%s' AND date BETWEEN '%s' AND '%s' ORDER BY start_time ASC;",
$cinema, $hall, $date, $end); $cinema, $hall, $date, $end);
} }else if($date && !$end){
if($date && !$end){
$date = date('Y-m-d', strtotime( $date ) ); $date = date('Y-m-d', strtotime( $date ) );
$sql = sprintf( "SELECT * FROM session WHERE $sql = sprintf( "SELECT * FROM session WHERE
@ -116,10 +108,9 @@
$cinema, $hall); $cinema, $hall);
} }
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error geting all sessions');
$sessions = null; $sessions = null;
while($fila=$resul->fetch_assoc()){ while($fila=$resul->fetch_assoc()){
$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]); $sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]);
} }
@ -131,7 +122,7 @@
//Look for a title and cinema //Look for a title and cinema
public function getSessions_Film_Cinema($idFiml, $idCinema){ public function getSessions_Film_Cinema($idFiml, $idCinema){
$sql = sprintf( "SELECT * FROM session WHERE session.idfilm = '%d' AND session.idcinema = '%d' ", $idFiml, $idCinema); $sql = sprintf( "SELECT * FROM session WHERE session.idfilm = '%d' AND session.idcinema = '%d' ", $idFiml, $idCinema);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error geting sessions with a idfilm and cinema');
$sessions = null; $sessions = null;
while($fila = $resul->fetch_assoc()){ while($fila = $resul->fetch_assoc()){
@ -146,18 +137,19 @@
public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin){ public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin){
$format = $this->mysqli->real_escape_string($format); $format = $this->mysqli->real_escape_string($format);
$date = date('Y-m-d', strtotime( $date ) ); $date = date('Y-m-d', strtotime( $date ) );
$origin["date"] = date('Y-m-d', strtotime( $origin["date"] ) );
$startTime = date('H:i:s', strtotime( $startTime ) ); $startTime = date('H:i:s', strtotime( $startTime ) );
$origin["start"] = date('H:i:s', strtotime( $origin["start"] ) );
$sql = sprintf( "UPDATE `session` $sql = sprintf( "UPDATE `session`
SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s', SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s',
`start_time` = '%s', `seat_price` = '%d', `format` = '%s' `start_time` = '%s', `seat_price` = '%d', `format` = '%s'
WHERE WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'", idcinema = '%s' AND idhall = '%s' AND session.date = '%s' AND start_time = '%s'",
$idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin["cinema"],$origin["hall"],$origin["date"],$origin["start"]); $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin["cinema"],$origin["hall"],$origin["date"],$origin["start"]);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul; mysqli_query($this->mysqli, $sql) or die ('Error editing a session');
} }
@ -168,7 +160,7 @@
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'", idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
$cinema, $hall, $date, $startTime); $cinema, $hall, $date, $startTime);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error deleting a session');
return $resul; return $resul;
} }