Filtro de salas en sesiones

This commit is contained in:
Markines16 2021-06-03 12:53:53 +02:00 committed by GitHub
parent ade555d392
commit 0d084df6a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 183 additions and 130 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) public static function buscaTodosEventos(int $userId, $idhall)
{ {
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("1","1",null); $sessions = Session::getListSessions($idhall,"1",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) public static function buscaPorId(int $idEvento, $idhall)
{ {
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) public static function buscaEntreFechas(int $userId, string $start, string $end = null, $idhall)
{ {
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("1","1",$startDate,$endDate); $sessions = Session::getListSessionsBetween2Dates($idhall,"1",$startDate,$endDate);
foreach($sessions as $s){ foreach($sessions as $s){
$e = new Evento(); $e = new Evento();
@ -292,8 +292,11 @@ class Evento implements \JsonSerializable
private $end; private $end;
private $idfilm; private $idfilm;
/*private $idhall;
private $idcinema;
/*
private $idhall;
private $idcinema;
private $date; private $date;
private $start_time; private $start_time;
private $seat_price; private $seat_price;
@ -309,7 +312,7 @@ class Evento implements \JsonSerializable
{ {
return $this->id; return $this->id;
} }
public function getUserId() public function getUserId()
{ {
return $this->userId; return $this->userId;
@ -404,7 +407,7 @@ class Evento implements \JsonSerializable
$film = Session::getThisSessionFilm($session->getIdfilm()); $film = Session::getThisSessionFilm($session->getIdfilm());
$dur = $film["duration"]+$extraDurationBetweenFilms; $dur = $film["duration"]+$extraDurationBetweenFilms;
$tittle = "Sala: ".$session->getIdhall()." ".$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'));
@ -541,6 +544,7 @@ class Evento implements \JsonSerializable
$this->idfilm = $idfilm; $this->idfilm = $idfilm;
} }
} }
/* /*
if (array_key_exists('idhall', $diccionario)) { if (array_key_exists('idhall', $diccionario)) {
$idhall = $diccionario['idhall'] ?? null; $idhall = $diccionario['idhall'] ?? null;

View File

@ -30,11 +30,13 @@ $result = null;
switch($_SERVER['REQUEST_METHOD']) { switch($_SERVER['REQUEST_METHOD']) {
// Consulta de datos // Consulta de datos
case 'GET': case 'GET':
$hall = $_GET["hall"];
// 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); $result[] = Evento::buscaPorId((int)$idEvento,$hall);
} 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]))/")));
@ -46,11 +48,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); $result = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime, $hall);
} else { } else {
// Comprobamos si es una lista de eventos completa // Comprobamos si es una lista de eventos completa
$result = Evento::buscaTodosEventos(1); // HACK: normalmente debería de ser App::getSingleton()->idUsuario(); $result = Evento::buscaTodosEventos(1, $hall); // 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
@ -75,6 +77,7 @@ switch($_SERVER['REQUEST_METHOD']) {
// 3. Reprocesamos el cuerpo de la petición como un array PHP // 3. Reprocesamos el cuerpo de la petición como un array PHP
$dictionary = json_decode($entityBody, true); $dictionary = json_decode($entityBody, true);
$dictionary['userId'] = 1;// HACK: normalmente debería de ser App::getSingleton()->idUsuario(); $dictionary['userId'] = 1;// HACK: normalmente debería de ser App::getSingleton()->idUsuario();
$e = Evento::creaDesdeDicionario($dictionary); $e = Evento::creaDesdeDicionario($dictionary);
// 4. Guardamos el evento en BD // 4. Guardamos el evento en BD

View File

@ -23,17 +23,22 @@
$userPic = USER_PICS.strtolower($name).".jpg"; $userPic = USER_PICS.strtolower($name).".jpg";
$cinema = strtoupper( $manager->getIdcinema()); $cinema = strtoupper( $manager->getIdcinema());
$panel = '<div class="code info"> $panel = '<div class="code">
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1> <h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
<hr /> <hr />
<img src='.$userPic.' alt="user_profile_picture"/> <div class="column side"></div>
<p>Usuario: '.$name.'</p> <br> <div class="column middle">
<p>Cine: '.$c_name.'</p>
<p>Dirección: '.$c_dir.'</p> <img src='.$userPic.' alt="user_profile_picture"/>
<p>Telefono: '.$c_tel.'</p> <br> <p>Usuario: '.$name.'</p> <br>
<p>Espero que estes pasando un buen dia</p> <p>Cine: '.$c_name.'</p>
<p>Dirección: '.$c_dir.'</p>
<a href="?state=calendar"> calendario </a> <p>Telefono: '.$c_tel.'</p> <br>
<p>Espero que estes pasando un buen dia</p>
<a href="?state=calendar"> calendario </a>
</div>
<div class="column side"></div>
</div>'; </div>';
return $panel; return $panel;
@ -73,11 +78,42 @@
return $panel; return $panel;
} }
static function calendar(){ static function calendar($manager){
$panel = '
<div class="code"> $hall = $_POST['hall'] ?? $_GET['hall'] ?? "1";
<div id="calendar"></div> $halls = Hall::getListHalls($manager->getIdcinema());
</div>';
if($halls){
$panel ='
<div class="row">
<div class="column side"></div>
<div class="column middle">
<br>
<select id="hall_selector" class="button large">';
foreach(Hall::getListHalls($manager->getIdcinema()) as $hll){
if($hll->getNumber() == $hall){
$panel.= '
<option data-feed="./eventos.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
}else{
$panel.= '
<option data-feed="./eventos.php?hall='.$hll->getNumber().'" value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
}
}
$panel.='
</select>
</div>
<div class="column side"></div>
</div>
<div class="row">
<div id="calendar"></div>
</div>';
}else{
$panel ='<div class="row">
<h3> No hay ninguna sala en este cine </h3>
<a href=."/?state=new_hall"> Añadir Sala </a>
</div>';
}
return $panel; return $panel;
} }

View File

@ -1,108 +1,118 @@
$(document).ready(function() { $(document).ready(function(){
var calendar = $('#calendar').fullCalendar({
editable:true, var selectedFeed = $('#hall_selector').find(':selected').data('feed');
header:{
left:'prev,next today', var calendar = $('#calendar').fullCalendar({
center:'title', editable:true,
right:'month,agendaWeek,agendaDay' header:{
}, left:'prev,next today',
events: 'eventos.php', center:'title',
selectable:true, right:'month,agendaWeek,agendaDay'
selectHelper:true, },
timeFormat: 'H:mm', eventSources: [ selectedFeed ],
select: function(start, end, allDay) selectable:true,
{ selectHelper:true,
var title = prompt("Enter Event Title"); timeFormat: 'H:mm',
if(title) select: function(start, end, allDay)
{ {
var e = {
"start" : $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss"),
"title" : title
};
$.ajax({
url:"eventos.php",
type:"POST",
contentType: 'application/json; charset=utf-8',
dataType: "json",
data:JSON.stringify(e),
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Added Successfully");
}
})
}
},
editable:true,
eventResize:function(event)
{
var e = {
"id" : event.id,
"userId": event.userId,
"start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"),
"title" : event.title
};
$.ajax({
url:"eventos.php?idEvento="+event.id,
type:"PUT",
contentType: 'application/json; charset=utf-8',
dataType:"json",
data:JSON.stringify(e),
success:function(){
calendar.fullCalendar('refetchEvents');
alert('Event Update');
}
})
},
eventDrop:function(event) var e = {
{ "date" : $.fullCalendar.formatDate(allDay,"Y-MM-DD"),
var e = { "start" : $.fullCalendar.formatDate(start, "HH:mm"),
"id" : event.id, "end" : $.fullCalendar.formatDate(end, "HH:mm")
"userId": event.userId, };
"start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"), $.ajax({
"end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"), url:"eventos.php",
"title" : event.title type:"POST",
}; contentType: 'application/json; charset=utf-8',
$.ajax({ dataType: "json",
url:"eventos.php?idEvento="+event.id, data:JSON.stringify(e),
contentType: 'application/json; charset=utf-8', success:function()
dataType: "json", {
type:"PUT", calendar.fullCalendar('refetchEvents');
data:JSON.stringify(e), alert("Added Successfully");
success:function() }
{ })
calendar.fullCalendar('refetchEvents'); },
alert("Event Updated"); editable:true,
} eventResize:function(event)
}); {
}, var e = {
"id" : event.id,
"userId": event.userId,
"start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"),
"end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"),
"title" : event.title
};
$.ajax({
url:"eventos.php?idEvento="+event.id,
type:"PUT",
contentType: 'application/json; charset=utf-8',
dataType:"json",
data:JSON.stringify(e),
success:function(){
calendar.fullCalendar('refetchEvents');
alert('Event Update');
}
})
},
eventClick:function(event) eventDrop:function(event)
{ {
if(confirm("Are you sure you want to remove it?")) var e = {
{ "id" : event.id,
var id = event.id; "userId": event.userId,
$.ajax({ "start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"),
url:"eventos.php?idEvento="+id, "end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"),
contentType: 'application/json; charset=utf-8', "title" : event.title
dataType: "json", };
type:"DELETE", $.ajax({
success:function() url:"eventos.php?idEvento="+event.id,
{ contentType: 'application/json; charset=utf-8',
calendar.fullCalendar('refetchEvents'); dataType: "json",
alert("Event Removed"); type:"PUT",
}, data:JSON.stringify(e),
error: function(XMLHttpRequest, textStatus, errorThrown) { success:function()
alert("Status: " + textStatus); alert("Error: " + errorThrown); {
} calendar.fullCalendar('refetchEvents');
}) alert("Event Updated");
} }
}, });
},
}); eventClick:function(event)
}); {
if(confirm("Are you sure you want to remove it?"))
{
var id = event.id;
$.ajax({
url:"eventos.php?idEvento="+id,
contentType: 'application/json; charset=utf-8',
dataType: "json",
type:"DELETE",
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Removed");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
})
}
},
});
$('#hall_selector').change(onSelectChangeFeed);
function onSelectChangeFeed() {
var feed = $(this).find(':selected').data('feed');
$('#calendar').fullCalendar('removeEventSource', selectedFeed);
$('#calendar').fullCalendar('addEventSource', feed);
selectedFeed = feed;
};
});