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.
*/
public static function buscaTodosEventos(int $userId)
public static function buscaTodosEventos(int $userId, $idhall)
{
if (!$userId) {
// throw new \BadMethodCallException('$userId no puede ser nulo.');
}
$result = [];
$sessions = Session::getListSessions("1","1",null);
$sessions = Session::getListSessions($idhall,"1",null);
foreach($sessions as $s){
$e = new Evento();
@ -41,7 +41,7 @@ class Evento implements \JsonSerializable
*
* @return Evento Evento encontrado.
*/
public static function buscaPorId(int $idEvento)
public static function buscaPorId(int $idEvento, $idhall)
{
if (!$idEvento) {
throw new \BadMethodCallException('$idEvento no puede ser nulo.');
@ -76,7 +76,7 @@ class Evento implements \JsonSerializable
*
* @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) {
//throw new \BadMethodCallException('$userId no puede ser nulo.');
@ -101,7 +101,7 @@ class Evento implements \JsonSerializable
$result = [];
$sessions = Session::getListSessionsBetween2Dates("1","1",$startDate,$endDate);
$sessions = Session::getListSessionsBetween2Dates($idhall,"1",$startDate,$endDate);
foreach($sessions as $s){
$e = new Evento();
@ -292,8 +292,11 @@ class Evento implements \JsonSerializable
private $end;
private $idfilm;
/*private $idhall;
private $idcinema;
/*
private $idhall;
private $idcinema;
private $date;
private $start_time;
private $seat_price;
@ -309,7 +312,7 @@ class Evento implements \JsonSerializable
{
return $this->id;
}
public function getUserId()
{
return $this->userId;
@ -404,7 +407,7 @@ class Evento implements \JsonSerializable
$film = Session::getThisSessionFilm($session->getIdfilm());
$dur = $film["duration"]+$extraDurationBetweenFilms;
$tittle = "Sala: ".$session->getIdhall()." ".$film["tittle"];
$tittle = str_replace('_', ' ', $film["tittle"]) ;
$start = $session->getDate()." ".$session->getStartTime();
$end = date('Y-m-d H:i:s', strtotime( $start . ' +'.$dur.' minute'));
@ -541,6 +544,7 @@ class Evento implements \JsonSerializable
$this->idfilm = $idfilm;
}
}
/*
if (array_key_exists('idhall', $diccionario)) {
$idhall = $diccionario['idhall'] ?? null;

View File

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

View File

@ -23,17 +23,22 @@
$userPic = USER_PICS.strtolower($name).".jpg";
$cinema = strtoupper( $manager->getIdcinema());
$panel = '<div class="code info">
$panel = '<div class="code">
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
<hr />
<img src='.$userPic.' alt="user_profile_picture"/>
<p>Usuario: '.$name.'</p> <br>
<p>Cine: '.$c_name.'</p>
<p>Dirección: '.$c_dir.'</p>
<p>Telefono: '.$c_tel.'</p> <br>
<p>Espero que estes pasando un buen dia</p>
<a href="?state=calendar"> calendario </a>
<div class="column side"></div>
<div class="column middle">
<img src='.$userPic.' alt="user_profile_picture"/>
<p>Usuario: '.$name.'</p> <br>
<p>Cine: '.$c_name.'</p>
<p>Dirección: '.$c_dir.'</p>
<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>';
return $panel;
@ -73,11 +78,42 @@
return $panel;
}
static function calendar(){
$panel = '
<div class="code">
<div id="calendar"></div>
</div>';
static function calendar($manager){
$hall = $_POST['hall'] ?? $_GET['hall'] ?? "1";
$halls = Hall::getListHalls($manager->getIdcinema());
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;
}

View File

@ -1,108 +1,118 @@
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
editable:true,
header:{
left:'prev,next today',
center:'title',
right:'month,agendaWeek,agendaDay'
},
events: 'eventos.php',
selectable:true,
selectHelper:true,
timeFormat: 'H:mm',
select: function(start, end, allDay)
{
var title = prompt("Enter Event Title");
if(title)
{
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');
}
})
},
$(document).ready(function(){
var selectedFeed = $('#hall_selector').find(':selected').data('feed');
var calendar = $('#calendar').fullCalendar({
editable:true,
header:{
left:'prev,next today',
center:'title',
right:'month,agendaWeek,agendaDay'
},
eventSources: [ selectedFeed ],
selectable:true,
selectHelper:true,
timeFormat: 'H:mm',
select: function(start, end, allDay)
{
eventDrop: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,
contentType: 'application/json; charset=utf-8',
dataType: "json",
type:"PUT",
data:JSON.stringify(e),
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Updated");
}
});
},
var e = {
"date" : $.fullCalendar.formatDate(allDay,"Y-MM-DD"),
"start" : $.fullCalendar.formatDate(start, "HH:mm"),
"end" : $.fullCalendar.formatDate(end, "HH:mm")
};
$.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');
}
})
},
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);
}
})
}
},
eventDrop: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,
contentType: 'application/json; charset=utf-8',
dataType: "json",
type:"PUT",
data:JSON.stringify(e),
success:function()
{
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;
};
});