diff --git a/assets/php/includes/event.php b/assets/php/includes/event.php index 641595e..bb9faa4 100644 --- a/assets/php/includes/event.php +++ b/assets/php/includes/event.php @@ -22,24 +22,19 @@ class Event implements \JsonSerializable 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 = []; - - $sessions = Session::getListSessionsBetween2Dates($idhall,$cinema,$startDate,$endDate); - - foreach($sessions as $s){ - $e = new Event(); - $dictionary = self::session2dictionary($s); - $e = $e->dictionary2event($dictionary); - $result[] = $e; - } - + $sessions = Session::getListSessionsBetween2Dates($idhall,$cinema,$start,$end); + if($sessions){ + foreach($sessions as $s){ + $e = new Event(); + $dictionary = self::session2dictionary($s); + $e = $e->dictionary2event($dictionary); + $result[] = $e; + } + } return $result; } - - const MYSQL_DATE_TIME_FORMAT= 'Y-m-d H:i:s'; private $id; private $title; @@ -70,17 +65,44 @@ class Event implements \JsonSerializable //Return an object that allows Event object to be serialized as json because private atributes cant be serialized 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->id = $this->id; $o->title = $this->title; - $o->start = $this->start->format(self::MYSQL_DATE_TIME_FORMAT); - $o->end = $this->end->format(self::MYSQL_DATE_TIME_FORMAT); + $o->start = $this->start; + $o->end = $this->end; $o->start_time = $this->start_time; $o->seat_price = $this->seat_price; $o->format = $this->format; - $o->film = Session::getThisSessionFilm($this->idfilm); - $o->date = $this->start->format("Y-m-d"); - + $o->film_dur = $film["duration"]; + $o->film_id = $film["idfilm"]; + $o->film_lan = $lan; + $o->film_img = $film["img"]; + $o->date = $this->start; + return $o; } @@ -90,10 +112,9 @@ class Event implements \JsonSerializable $film = Session::getThisSessionFilm($session->getIdfilm()); $dur = $film["duration"]+$extraDurationBetweenFilms; - $tittle = str_replace('_', ' ', $film["tittle"]) ; + $tittle = \str_replace('_', ' ', $film["tittle"]) ; $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( "id" => $session->getId(), @@ -124,17 +145,16 @@ class Event implements \JsonSerializable if (array_key_exists('start', $dictionary)) { $start = $dictionary['start']; - $startDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $start); - $this->start = $startDate; + //$start = DateTime::createFromFormat("y-m-d H:i:s", $start); + $this->start = $start; } - if (array_key_exists('end', $dictionary)) { $end = $dictionary['end'] ?? null; - $endDate = \DateTime::createFromFormat(self::MYSQL_DATE_TIME_FORMAT, $end); - $this->end = $endDate; + $this->end = $end; } + if (array_key_exists('idfilm', $dictionary)) { $idfilm = $dictionary['idfilm'] ?? null; $this->idfilm = $idfilm; diff --git a/assets/php/includes/session.php b/assets/php/includes/session.php index f698b04..07f5a78 100644 --- a/assets/php/includes/session.php +++ b/assets/php/includes/session.php @@ -41,11 +41,7 @@ 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){ $bd = new SessionDAO('complucine'); if($bd ){ @@ -75,7 +71,6 @@ }else{ return "Ya existe una sesion con los parametros nuevos"; } - } else return "La session a editar no existe"; @@ -90,9 +85,7 @@ return "Se ha eliminado la session con exito"; } else return "Esta session no existe"; - } else return "Error al conectarse a la base de datos"; - - return "Se ha eliminado la session con exito"; + } else return "Error al conectarse a la base de datos"; } //Esto deberia estar en film.php? seguramente diff --git a/assets/php/includes/session_dao.php b/assets/php/includes/session_dao.php index c162f54..5830885 100644 --- a/assets/php/includes/session_dao.php +++ b/assets/php/includes/session_dao.php @@ -6,7 +6,6 @@ function __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 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')", $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; } @@ -26,7 +25,7 @@ //Returns a query to get the session's data. public function sessionData($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()){ $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 public function filmTittle($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); @@ -55,7 +54,7 @@ $sql = sprintf( "SELECT * FROM session WHERE idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'", $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); @@ -70,17 +69,16 @@ $sessions = []; $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; - $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 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); - - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error looking for sessions between start time and start time + film duration'); 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"]); @@ -94,17 +92,11 @@ //Returns a query to get all the session's data. public function getAllSessions($hall, $cinema, $date, $end){ if($end){ - - $date = $date->format("Y-m-d"); - $end = $end->format("Y-m-d"); - + $sql = sprintf( "SELECT * FROM session WHERE idcinema = '%s' AND idhall = '%s' AND date BETWEEN '%s' AND '%s' ORDER BY start_time ASC;", - $cinema, $hall, $date, $end); - } - - - if($date && !$end){ + $cinema, $hall, $date, $end); + }else if($date && !$end){ $date = date('Y-m-d', strtotime( $date ) ); $sql = sprintf( "SELECT * FROM session WHERE @@ -116,10 +108,9 @@ $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; - 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"]); } @@ -131,7 +122,7 @@ //Look for a title and cinema public function getSessions_Film_Cinema($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; while($fila = $resul->fetch_assoc()){ @@ -146,18 +137,19 @@ public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $origin){ $format = $this->mysqli->real_escape_string($format); $date = date('Y-m-d', strtotime( $date ) ); + $origin["date"] = date('Y-m-d', strtotime( $origin["date"] ) ); $startTime = date('H:i:s', strtotime( $startTime ) ); + $origin["start"] = date('H:i:s', strtotime( $origin["start"] ) ); $sql = sprintf( "UPDATE `session` SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s', `start_time` = '%s', `seat_price` = '%d', `format` = '%s' 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"]); - $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'", $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; }