CALENDAR Sala y cine filtro

This commit is contained in:
Markines16 2021-06-03 14:09:25 +02:00 committed by GitHub
parent 7ffb4662bf
commit 91177751b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 103 additions and 92 deletions

View File

@ -15,14 +15,14 @@ class Evento implements \JsonSerializable
* *
* @return array[Evento] Lista de eventos del usuario con id $userId. * @return array[Evento] Lista de eventos del usuario con id $userId.
*/ */
public static function buscaTodosEventos(int $userId, $idhall) public static function buscaTodosEventos(int $userId, $idhall, $cinema)
{ {
if (!$userId) { if (!$userId) {
// throw new \BadMethodCallException('$userId no puede ser nulo.'); // throw new \BadMethodCallException('$userId no puede ser nulo.');
} }
$result = []; $result = [];
$sessions = Session::getListSessions($idhall,"1",null); $sessions = Session::getListSessions($idhall,$cinema,null);
foreach($sessions as $s){ foreach($sessions as $s){
$e = new Evento(); $e = new Evento();
@ -41,7 +41,7 @@ class Evento implements \JsonSerializable
* *
* @return Evento Evento encontrado. * @return Evento Evento encontrado.
*/ */
public static function buscaPorId(int $idEvento, $idhall) public static function buscaPorId(int $idEvento, $idhall, $cinema)
{ {
if (!$idEvento) { if (!$idEvento) {
throw new \BadMethodCallException('$idEvento no puede ser nulo.'); throw new \BadMethodCallException('$idEvento no puede ser nulo.');
@ -76,7 +76,7 @@ class Evento implements \JsonSerializable
* *
* @return array[Evento] Lista de eventos encontrados. * @return array[Evento] Lista de eventos encontrados.
*/ */
public static function buscaEntreFechas(int $userId, string $start, string $end = null, $idhall) public static function buscaEntreFechas(int $userId, string $start, string $end = null, $idhall, $cinema)
{ {
if (!$userId) { if (!$userId) {
//throw new \BadMethodCallException('$userId no puede ser nulo.'); //throw new \BadMethodCallException('$userId no puede ser nulo.');
@ -101,7 +101,7 @@ class Evento implements \JsonSerializable
$result = []; $result = [];
$sessions = Session::getListSessionsBetween2Dates($idhall,"1",$startDate,$endDate); $sessions = Session::getListSessionsBetween2Dates($idhall,$cinema,$startDate,$endDate);
foreach($sessions as $s){ foreach($sessions as $s){
$e = new Evento(); $e = new Evento();

View File

@ -31,12 +31,13 @@ switch($_SERVER['REQUEST_METHOD']) {
// Consulta de datos // Consulta de datos
case 'GET': case 'GET':
$hall = $_GET["hall"]; $hall = $_GET["hall"];
$cinema = $_SESSION["cinema"];
// Comprobamos si es una consulta de un evento concreto -> eventos.php?idEvento=XXXXX // Comprobamos si es una consulta de un evento concreto -> eventos.php?idEvento=XXXXX
$idEvento = filter_input(INPUT_GET, 'idEvento', FILTER_VALIDATE_INT); $idEvento = filter_input(INPUT_GET, 'idEvento', FILTER_VALIDATE_INT);
if ($idEvento) { if ($idEvento) {
$result = []; $result = [];
$result[] = Evento::buscaPorId((int)$idEvento,$hall); $result[] = Evento::buscaPorId((int)$idEvento,$hall,$cinema);
} else { } else {
// Comprobamos si es una lista de eventos entre dos fechas -> eventos.php?start=XXXXX&end=YYYYY // Comprobamos si es una lista de eventos entre dos fechas -> eventos.php?start=XXXXX&end=YYYYY
$start = filter_input(INPUT_GET, 'start', FILTER_VALIDATE_REGEXP, array("options" => array("regexp"=>"/\d{4}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))/"))); $start = filter_input(INPUT_GET, 'start', FILTER_VALIDATE_REGEXP, array("options" => array("regexp"=>"/\d{4}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))/")));
@ -48,11 +49,11 @@ switch($_SERVER['REQUEST_METHOD']) {
if ($end) { if ($end) {
$endDateTime = $end. ' 00:00:00'; $endDateTime = $end. ' 00:00:00';
} }
$result = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime, $hall); $result = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime, $hall,$cinema);
} else { } else {
// Comprobamos si es una lista de eventos completa // Comprobamos si es una lista de eventos completa
$result = Evento::buscaTodosEventos(1, $hall); // HACK: normalmente debería de ser App::getSingleton()->idUsuario(); $result = Evento::buscaTodosEventos(1, $hall,$cinema); // HACK: normalmente debería de ser App::getSingleton()->idUsuario();
} }
} }
// Generamos un array de eventos en formato JSON // Generamos un array de eventos en formato JSON

View File

@ -10,14 +10,13 @@
if($_SESSION["login"] && isset($_SESSION["lastRol"]) && ($_SESSION["lastRol"] === "admin" || $_SESSION["rol"] === "manager")) { if($_SESSION["login"] && isset($_SESSION["lastRol"]) && ($_SESSION["lastRol"] === "admin" || $_SESSION["rol"] === "manager")) {
$manager = new Manager(null, null, null, null, null); $manager = new Manager(null, null, null, null, null);
if(isset($_POST['changecinema']))$_SESSION['cinema'] = $_POST['cinema']; if(isset($_POST['changecinema']))$_SESSION['cinema'] = $_POST['cinema'];
if(!is_null($_SESSION['cinema'])) $manager->setIdcinema($_SESSION['cinema']);
$state = isset($_GET['state']) ? $_GET['state'] : ''; $state = isset($_GET['state']) ? $_GET['state'] : '';
switch($state){ switch($state){
case "view_user": case "view_user":
$_SESSION["rol"] = null; $_SESSION["rol"] = null;
$panel .= "<div class='row'> $panel .= "<div class='row'>
<div class='column side'></div> <div class='column side'></div>
<div class='column middle'> <div class='column middle'>
@ -33,6 +32,7 @@
break; break;
case "view_ruser": case "view_ruser":
$_SESSION["rol"] = "user"; $_SESSION["rol"] = "user";
unset($_SESSION["cinema"]);
$panel .= "<div class='row'> $panel .= "<div class='row'>
<div class='column side'></div> <div class='column side'></div>
<div class='column middle'> <div class='column middle'>
@ -47,25 +47,28 @@
"; ";
break; break;
case "manage_halls": case "manage_halls":
$panel = Manager_panel::manage_halls($manager); $panel = Manager_panel::manage_halls();
break; break;
case "new_hall": case "new_hall":
$panel = Manager_panel::new_hall($manager); $panel = Manager_panel::new_hall();
break; break;
case "edit_hall": case "edit_hall":
$panel = Manager_panel::edit_hall($manager); $panel = Manager_panel::edit_hall();
break; break;
case "manage_sessions": case "manage_sessions":
$panel = Manager_panel::manage_sessions($manager); $panel = Manager_panel::manage_sessions();
break; break;
case "new_session": case "new_session":
$panel = Manager_panel::new_session($manager); $panel = Manager_panel::new_session();
break; break;
case "edit_session": case "edit_session":
$panel = Manager_panel::edit_session($manager); $panel = Manager_panel::edit_session();
break; break;
case "select_film": case "select_film":
$panel = Manager_panel::select_film($template,$manager); $panel = Manager_panel::select_film($template);
break;
case "calendar":
$panel = Manager_panel::calendar();
break; break;
case "success": case "success":
$panel = Manager_panel::success(); $panel = Manager_panel::success();
@ -76,24 +79,25 @@
} }
} }
else if($_SESSION["login"] && $_SESSION["rol"] === "manager"){ else if($_SESSION["login"] && $_SESSION["rol"] === "manager"){
if(!isset($_SESSION['cinema'])){
$bd = new Manager_DAO('complucine'); $bd = new Manager_DAO('complucine');
$manager = false; if($bd){
if($bd && !$manager){
$user = unserialize($_SESSION["user"]); $user = unserialize($_SESSION["user"]);
$manager = $bd->GetManager($user->getId()); $manager = $bd->GetManager($user->getId());
$manager = $manager->fetch_assoc();
if($manager){ $_SESSION['cinema'] = $manager["idcinema"];
if($manager->num_rows == 1){
$fila = $manager->fetch_assoc();
$manager = new Manager($fila["id"], $fila["idcinema"], null, null, null);
}
} }
} }
$state = isset($_GET['state']) ? $_GET['state'] : ''; $state = isset($_GET['state']) ? $_GET['state'] : '';
switch($state){ switch($state){
case "view_user": case "view_user":
$_SESSION["lastRol"] = $_SESSION["rol"]; $_SESSION["lastRol"] = $_SESSION["rol"];
$_SESSION["rol"] = null; $_SESSION["rol"] = null;
unset($_SESSION["cinema"]);
$panel = "<div class='row'> $panel = "<div class='row'>
<div class='column side'></div> <div class='column side'></div>
<div class='column middle'> <div class='column middle'>
@ -110,6 +114,7 @@
case "view_ruser": case "view_ruser":
$_SESSION["lastRol"] = $_SESSION["rol"]; $_SESSION["lastRol"] = $_SESSION["rol"];
$_SESSION["rol"] = "user"; $_SESSION["rol"] = "user";
unset($_SESSION["cinema"]);
$panel = "<div class='row'> $panel = "<div class='row'>
<div class='column side'></div> <div class='column side'></div>
<div class='column middle'> <div class='column middle'>
@ -124,34 +129,34 @@
"; ";
break; break;
case "manage_halls": case "manage_halls":
$panel = Manager_panel::manage_halls($manager); $panel = Manager_panel::manage_halls();
break; break;
case "new_hall": case "new_hall":
$panel = Manager_panel::new_hall($manager); $panel = Manager_panel::new_hall();
break; break;
case "edit_hall": case "edit_hall":
$panel = Manager_panel::edit_hall($manager); $panel = Manager_panel::edit_hall();
break; break;
case "manage_sessions": case "manage_sessions":
$panel = Manager_panel::manage_sessions($manager); $panel = Manager_panel::manage_sessions();
break; break;
case "new_session": case "new_session":
$panel = Manager_panel::new_session($manager); $panel = Manager_panel::new_session();
break; break;
case "edit_session": case "edit_session":
$panel = Manager_panel::edit_session($manager); $panel = Manager_panel::edit_session();
break; break;
case "select_film": case "select_film":
$panel = Manager_panel::select_film($template,$manager); $panel = Manager_panel::select_film($template);
break; break;
case "success": case "success":
$panel = Manager_panel::success(); $panel = Manager_panel::success();
break; break;
case "calendar": case "calendar":
$panel = Manager_panel::calendar($manager); $panel = Manager_panel::calendar();
break; break;
default: default:
$panel = Manager_panel::welcome($manager); $panel = Manager_panel::welcome();
break; break;
} }
} }
@ -175,7 +180,6 @@
<section id="manager_panel"> <section id="manager_panel">
<!-- Contents --> <!-- Contents -->
<div class="row"> <div class="row">
'.$panel.' '.$panel.'
</div> </div>
</section>'; </section>';

View File

@ -11,54 +11,60 @@
function __construct(){} function __construct(){}
static function welcome($manager){ static function welcome(){
$bd = new Cinema_DAO('complucine'); $bd = new Cinema_DAO('complucine');
if($bd){ if($bd){
$cinema = $bd->cinemaData($manager->getIdcinema());
$cinema = $bd->cinemaData($_SESSION["cinema"]);
$c_name = $cinema->getName(); $c_name = $cinema->getName();
$c_dir = $cinema->getDirection(); $c_dir = $cinema->getDirection();
$c_tel = $cinema->getPhone();
} }
$name = strtoupper($_SESSION["nombre"]); $name = strtoupper($_SESSION["nombre"]);
$userPic = USER_PICS.strtolower($name).".jpg"; $userPic = USER_PICS.strtolower($name).".jpg";
$cinema = strtoupper( $manager->getIdcinema());
$panel = '<div class="code"> $panel= '<div class="code welcome">
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1> <h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
<hr /> <hr />
<div class="column side"></div>
<div class="column middle">
<img src='.$userPic.' alt="user_profile_picture"/> <img src='.$userPic.' alt="user_profile_picture"/>
<h3>'.strftime("%A %e de %B de %Y | %H:%M").'</h3>
<p>Usuario: '.$name.'</p> <br> <p>Usuario: '.$name.'</p> <br>
<p>Cine: '.$c_name.'</p> <p>Cine: '.$c_name.'</p>
<p>Dirección: '.$c_dir.'</p> <p>Dirección: '.$c_dir.'</p>
<p>Telefono: '.$c_tel.'</p> <br> <a href="?state=calendar"> <p> Hack para entrar al calendario <p> </a>
<p>Espero que estes pasando un buen dia</p> </div>'."\n";
<a href="?state=calendar"> calendario </a>
</div>
<div class="column side"></div>
</div>';
return $panel; return $panel;
} }
static function welcomeAdmin($manager) { static function welcomeAdmin() {
$cinemaList = new Cinema_DAO('complucine'); $cinemaList = new Cinema_DAO('complucine');
$cinemas = $cinemaList->allCinemaData(); $cinemas = $cinemaList->allCinemaData();
$cinema;
$bd = new Cinema_DAO('complucine');
$c_name = "Aun no se ha escogido un cine";
if($bd && $_SESSION["cinema"] ){
$cinema = $bd->cinemaData($_SESSION["cinema"]);
$c_name = $cinema->getName();
$cinema = $cinema->getId();
}
$name = strtoupper($_SESSION["nombre"]); $name = strtoupper($_SESSION["nombre"]);
$userPic = USER_PICS.strtolower($name).".jpg";
if($manager->getIdcinema() != null) $cinema = strtoupper( $manager->getIdcinema()); $panel= '<div class="code welcome">
$panel = '<div class="code info">
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1> <h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
<hr /> <hr />
<p>Usuario: '.$name.'</p> <img src='.$userPic.' alt="user_profile_picture"/>
<p>Cine: '.$cinema.'</p> <h3>'.strftime("%A %e de %B de %Y | %H:%M").'</h3>
<p>Espero que estes pasando un buen dia</p> <p>Usuario: '.$name.'</p> <br>
<h3>Como administrador puedes escoger el cine que gestionar</h3>
<p>Cine: '.$c_name.'</p>
<a href="?state=calendar"> <p> Hack para entrar al calendario <p> </a>
<form method="post" id="changecinema" action="index.php"> <form method="post" id="changecinema" action="index.php">
<select name="cinema" class="button large"> <select name="cinema" class="button large">
'; ';
@ -78,10 +84,10 @@
return $panel; return $panel;
} }
static function calendar($manager){ static function calendar(){
$hall = $_POST['hall'] ?? $_GET['hall'] ?? "1"; $hall = $_POST['hall'] ?? $_GET['hall'] ?? "1";
$halls = Hall::getListHalls($manager->getIdcinema()); $halls = Hall::getListHalls($_SESSION["cinema"]);
if($halls){ if($halls){
$panel =' $panel ='
@ -90,7 +96,7 @@
<div class="column middle"> <div class="column middle">
<br> <br>
<select id="hall_selector" class="button large">'; <select id="hall_selector" class="button large">';
foreach(Hall::getListHalls($manager->getIdcinema()) as $hll){ foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
if($hll->getNumber() == $hall){ if($hll->getNumber() == $hall){
$panel.= ' $panel.= '
<option data-feed="./eventos.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> '; <option data-feed="./eventos.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
@ -128,11 +134,11 @@
return $panel; return $panel;
} }
static function manage_halls($manager){ static function manage_halls(){
$panel = '<div class="column side"></div> $panel = '<div class="column side"></div>
<div class="column middle">'; <div class="column middle">';
$listhall = Hall::getListHalls($manager->getIdcinema()); $listhall = Hall::getListHalls($_SESSION["cinema"]);
if(!$listhall){ if(!$listhall){
$panel .= "<h2> No hay ninguna sala en este cine"; $panel .= "<h2> No hay ninguna sala en este cine";
}else{ }else{
@ -149,7 +155,7 @@
<li> '. $hall->getNumber().'</li> <li> '. $hall->getNumber().'</li>
<li> '.$hall->getTotalSeats().' </li> <li> '.$hall->getTotalSeats().' </li>
</a> </a>
<a href="?state=manage_sessions&hall='. $hall->getNumber().'"> <a href="?state=calendar&hall='. $hall->getNumber().'">
<li> Sesiones </li> <li> Sesiones </li>
</a> </a>
</div> </div>
@ -168,30 +174,30 @@
return $panel; return $panel;
} }
static function new_hall($manager){ static function new_hall(){
$formHall = new FormHall("new_hall",$manager->getIdcinema(),new Hall(null, null, null, null, null, null)); $formHall = new FormHall("new_hall",$_SESSION["cinema"],new Hall(null, null, null, null, null, null));
$panel = '<h1>Crear una sala.</h1><hr/></br> $panel = '<h1>Crear una sala.</h1><hr/></br>
'.$formHall->gestiona(); '.$formHall->gestiona();
return $panel; return $panel;
} }
static function edit_hall($manager){ static function edit_hall(){
$hall = Hall::search_hall($_GET["number"], $manager->getIdcinema()); $hall = Hall::search_hall($_GET["number"], $_SESSION["cinema"]);
if($hall || isset($_POST["restart"]) || isset($_POST["filter"]) || isset($_POST["sumbit"]) ){ if($hall || isset($_POST["restart"]) || isset($_POST["filter"]) || isset($_POST["sumbit"]) ){
$formHall = new FormHall("edit_hall",$manager->getIdcinema(), $hall); $formHall = new FormHall("edit_hall",$_SESSION["cinema"], $hall);
$panel = '<h1>Editar una sala.</h1><hr/></br> $panel = '<h1>Editar una sala.</h1><hr/></br>
'.$formHall->gestiona(); '.$formHall->gestiona();
return $panel; return $panel;
} else{ } else{
return Manager_panel::warning($manager); return Manager_panel::warning();
} }
} }
static function manage_sessions($manager){ static function manage_sessions(){
//Base filtering values //Base filtering values
$date = $_POST['date'] ?? $_GET['date'] ?? date("Y-m-d"); $date = $_POST['date'] ?? $_GET['date'] ?? date("Y-m-d");
$hall = $_POST['hall'] ?? $_GET['hall'] ?? "1"; $hall = $_POST['hall'] ?? $_GET['hall'] ?? "1";
@ -202,7 +208,7 @@
<input type="date" name="date" value="'.$date.'" min="2021-01-01" max="2031-12-31"> <input type="date" name="date" value="'.$date.'" min="2021-01-01" max="2031-12-31">
<select name="hall" class="button large">'; <select name="hall" class="button large">';
foreach(Hall::getListHalls($manager->getIdcinema()) as $hll){ foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
if($hll->getNumber() == $hall){ if($hll->getNumber() == $hall){
$panel.= ' $panel.= '
<option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> '; <option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
@ -219,7 +225,7 @@
'; ';
//Session list //Session list
$panel .=' <div class = "column right">'; $panel .=' <div class = "column right">';
$sessions = Session::getListSessions($hall,$manager->getIdcinema(),$date); $sessions = Session::getListSessions($hall,$_SESSION["cinema"],$date);
if($sessions) { if($sessions) {
$panel .=' $panel .='
@ -273,16 +279,16 @@
return $panel; return $panel;
} }
static function new_session($manager){ static function new_session(){
$formSession = new FormSession("new_session", $manager->getIdcinema() ); $formSession = new FormSession("new_session", $_SESSION["cinema"] );
$panel = '<h1>Crear una sesion.</h1> <hr/> </br> $panel = '<h1>Crear una sesion.</h1> <hr/> </br>
'.$formSession->gestiona(); '.$formSession->gestiona();
return $panel; return $panel;
} }
static function edit_session($manager){ static function edit_session(){
$formSession = new FormSession("edit_session", $manager->getIdcinema() ); $formSession = new FormSession("edit_session", $_SESSION["cinema"] );
$panel = '<h1>Editar una sesion.</h1><hr/></br> $panel = '<h1>Editar una sesion.</h1><hr/></br>
'.$formSession->gestiona(); '.$formSession->gestiona();
@ -290,19 +296,19 @@
} }
//TODO: estado al modificar sesiones para la seleccion de peliculas usando el template->print films //TODO: estado al modificar sesiones para la seleccion de peliculas usando el template->print films
static function select_film($template,$manager){ static function select_film($template){
if(isset($_POST["select_film"]) && isset($_POST["option"])){ if(isset($_POST["select_film"]) && isset($_POST["option"])){
$_SESSION["option"] = $_POST["option"]; $_SESSION["option"] = $_POST["option"];
$panel = '<h1>Seleccionar Pelicula.</h1><hr /></br>'; $panel = '<h1>Seleccionar Pelicula.</h1><hr /></br>';
$panel .= $template->print_fimls(); $panel .= $template->print_fimls();
$_SESSION["option"] = ""; $_SESSION["option"] = "";
} else $panel = self::warning($manager); } else $panel = self::warning();
return $panel; return $panel;
} }
//Funcion que se envia cuando hay inconsistencia en el panel manager, principalmente por tocar cosas con la ulr //Funcion que se envia cuando hay inconsistencia en el panel manager, principalmente por tocar cosas con la ulr
static function warning($manager){ static function warning(){
$panel = '<div class="code info"> $panel = '<div class="code info">
<h1>Ha habido un error.</h1> <h1>Ha habido un error.</h1>
<hr /> <hr />