Add files via upload

This commit is contained in:
Fernando Méndez 2021-06-03 11:32:27 +02:00 committed by GitHub
parent 8a65fdb574
commit 3dc56e4618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 145 additions and 121 deletions

View File

@ -28,7 +28,16 @@
public static function getListSessions($hall,$cinema,$date){ public static function getListSessions($hall,$cinema,$date){
$bd = new SessionDAO('complucine'); $bd = new SessionDAO('complucine');
if($bd ) { if($bd ) {
return $bd->getAllSessions($hall, $cinema, $date); if($date)
return $bd->getAllSessions($hall, $cinema, $date, null);
else
return $bd->getAllSessions($hall, $cinema, null, null);
}
}
public static function getListSessionsBetween2Dates($hall,$cinema,$start,$end){
$bd = new SessionDAO('complucine');
if($bd ) {
return $bd->getAllSessions($hall, $cinema, $start, $end);
} }
} }

View File

@ -62,24 +62,43 @@
} }
//Returns a query to get all the session's data. //Returns a query to get all the session's data.
public function getAllSessions($hall, $cinema, $date){ public function getAllSessions($hall, $cinema, $date, $end){
$date = date('Y-m-d', strtotime( $date ) ); if($end){
$date = $date->format("Y-m-d");
$end = $end->format("Y-m-d");
// su output es date: 2021-05-30 end: 2021-07-11
$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){
$date = date('Y-m-d', strtotime( $date ) );
$sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' ORDER BY start_time ASC;",
$cinema, $hall, $date);
}else{
$sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' ORDER BY start_time ASC;",
$cinema, $hall);
}
$sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' ORDER BY start_time ASC;",
$cinema, $hall, $date);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$sessions = null; $sessions = null;
while($fila=mysqli_fetch_array($resul)){ 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"]);
} }
mysqli_free_result($resul); mysqli_free_result($resul);
return $sessions; return $sessions;
} }
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 into query database');

View File

@ -1,17 +1,12 @@
<?php <?php
require_once __DIR__.'/includes/config.php';
use es\ucm\fdi\aw\eventos\Evento; require_once('../assets/php/config.php');
use es\ucm\fdi\aw\Aplicacion as App; require_once('./Evento.php');
use es\ucm\fdi\aw\http\ContentTypeNoSoportadoException;
use es\ucm\fdi\aw\http\ParametroNoValidoException;
// Procesamos la cabecera Content-Type // Procesamos la cabecera Content-Type
$contentType= $_SERVER['CONTENT_TYPE'] ?? 'application/json'; $contentType= $_SERVER['CONTENT_TYPE'] ?? 'application/json';
$contentType = strtolower(str_replace(' ', '', $contentType)); $contentType = strtolower(str_replace(' ', '', $contentType));
// Verificamos corresponde con uno de los tipos soportados // Verificamos corresponde con uno de los tipos soportados
$acceptedContentTypes = array('application/json;charset=utf-8', 'application/json'); $acceptedContentTypes = array('application/json;charset=utf-8', 'application/json');
$found = false; $found = false;
@ -23,7 +18,7 @@ foreach ($acceptedContentTypes as $acceptedContentType) {
} }
if (!$found) { if (!$found) {
throw new ContentTypeNoSoportadoException('Este servicio REST sólo soporta el content-type application/json'); // throw new ContentTypeNoSoportadoException('Este servicio REST sólo soporta el content-type application/json');
} }
$result = null; $result = null;
@ -44,7 +39,8 @@ switch($_SERVER['REQUEST_METHOD']) {
// 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]))/")));
$end = filter_input(INPUT_GET, 'end', FILTER_VALIDATE_REGEXP, array("options" => array("default" => null, "regexp"=>"/\d{4}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))/"))); $end = filter_input(INPUT_GET, 'end', FILTER_VALIDATE_REGEXP, array("options" => array("default" => null, "regexp"=>"/\d{4}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))/")));
if ($start) { if ($start) {
$startDateTime = $start . ' 00:00:00'; $startDateTime = $start . ' 00:00:00';
$endDateTime = $end; $endDateTime = $end;
if ($end) { if ($end) {
@ -52,14 +48,14 @@ switch($_SERVER['REQUEST_METHOD']) {
} }
$result = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime); $result = Evento::buscaEntreFechas(1, $startDateTime, $endDateTime);
} 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); // 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
$json = json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK); $json = json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
http_response_code(200); // 200 OK http_response_code(200); // 200 OK
header('Content-Type: application/json; charset=utf-8'); header('Content-Type: application/json; charset=utf-8');
header('Content-Length: ' . mb_strlen($json)); header('Content-Length: ' . mb_strlen($json));
@ -70,18 +66,17 @@ switch($_SERVER['REQUEST_METHOD']) {
case 'POST': case 'POST':
// 1. Leemos el contenido que nos envían // 1. Leemos el contenido que nos envían
$entityBody = file_get_contents('php://input'); $entityBody = file_get_contents('php://input');
// 2. Verificamos que nos envían un objeto // 2. Verificamos que nos envían un objeto
$dictionary = json_decode($entityBody); $dictionary = json_decode($entityBody);
if (!is_object($dictionary)) { if (!is_object($dictionary)) {
throw new ParametroNoValidoException('El cuerpo de la petición no es valido'); //throw new ParametroNoValidoException('El cuerpo de la petición no es valido');
} }
// 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);
error_log("hmmm");
// 4. Guardamos el evento en BD // 4. Guardamos el evento en BD
$result = Evento::guardaOActualiza($e); $result = Evento::guardaOActualiza($e);
@ -96,6 +91,7 @@ switch($_SERVER['REQUEST_METHOD']) {
break; break;
case 'PUT': case 'PUT':
error_log("PUT");
// 1. Comprobamos si es una consulta de un evento concreto -> eventos.php?idEvento=XXXXX // 1. 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);
// 2. Leemos el contenido que nos envían // 2. Leemos el contenido que nos envían
@ -103,9 +99,10 @@ switch($_SERVER['REQUEST_METHOD']) {
// 3. Verificamos que nos envían un objeto // 3. Verificamos que nos envían un objeto
$dictionary = json_decode($entityBody); $dictionary = json_decode($entityBody);
if (!is_object($dictionary)) { if (!is_object($dictionary)) {
throw new ParametroNoValidoException('El cuerpo de la petición no es valido'); //throw new ParametroNoValidoException('El cuerpo de la petición no es valido');
} }
// 4. Reprocesamos el cuerpo de la petición como un array PHP // 4. Reprocesamos el cuerpo de la petición como un array PHP
$dictionary = json_decode($entityBody, true); $dictionary = json_decode($entityBody, true);
$e = Evento::buscaPorId($idEvento); $e = Evento::buscaPorId($idEvento);
@ -132,8 +129,6 @@ switch($_SERVER['REQUEST_METHOD']) {
header('Content-Length: 0'); header('Content-Length: 0');
break; break;
default: default:
throw new MetodoNoSoportadoException($_SERVER['REQUEST_METHOD']. ' no está soportado'); //throw new MetodoNoSoportadoException($_SERVER['REQUEST_METHOD']. ' no está soportado');
break; break;
}
}

View File

@ -1,107 +1,108 @@
$(document).ready(function() { $(document).ready(function() {
var calendar = $('#calendar').fullCalendar({ var calendar = $('#calendar').fullCalendar({
editable:true, editable:true,
header:{ header:{
left:'prev,next today', left:'prev,next today',
center:'title', center:'title',
right:'' right:'month,agendaWeek,agendaDay'
}, },
events: 'eventos.php', events: 'eventos.php',
selectable:true, selectable:true,
selectHelper:true, selectHelper:true,
select: function(start, end, allDay) timeFormat: 'H:mm',
{ select: function(start, end, allDay)
var title = confirm("¿Estas son las fechas correctas?"); {
if(title) 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"),
};
$.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 = { var e = {
"id" : event.id, "start" : $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss"),
"userId": event.userId, "end" : $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss"),
"start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"), "title" : title
"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 = {
"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({ $.ajax({
url:"eventos.php?idEvento="+event.id, url:"eventos.php",
type:"POST",
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8',
dataType: "json", dataType: "json",
type:"PUT",
data:JSON.stringify(e), data:JSON.stringify(e),
success:function() success:function()
{ {
calendar.fullCalendar('refetchEvents'); calendar.fullCalendar('refetchEvents');
alert("Event Updated"); alert("Added Successfully");
} }
}); })
}, }
},
eventClick:function(event) editable:true,
{ eventResize:function(event)
if(confirm("Are you sure you want to remove it?")) {
{ var e = {
var id = event.id; "id" : event.id,
$.ajax({ "userId": event.userId,
url:"eventos.php?idEvento="+id, "start" : $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss"),
contentType: 'application/json; charset=utf-8', "end" : $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss"),
dataType: "json", "title" : event.title
type:"DELETE", };
success:function()
{ $.ajax({
calendar.fullCalendar('refetchEvents'); url:"eventos.php?idEvento="+event.id,
alert("Event Removed"); type:"PUT",
}, contentType: 'application/json; charset=utf-8',
error: function(XMLHttpRequest, textStatus, errorThrown) { dataType:"json",
alert("Status: " + textStatus); alert("Error: " + errorThrown); data:JSON.stringify(e),
} success:function(){
}) calendar.fullCalendar('refetchEvents');
alert('Event Update');
} }
}, })
},
});
}); 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);
}
})
}
},
});
});