Muchas conexiones con la base de datos.

Ahora se pueden añadir sesiones (para una sala, cine y fecha predeterminada en el codigo). El "escoger" la pelicula es simplemente meter el id de la pelicula en cuestion.
La lista de sesiones en la vista de las sesiones hace recibe un array desde la base de datos (para una sala,cine y fecha predeterminada en el codigo). Lo que muestra la tabla tambien es solo la id de la pelicula.
This commit is contained in:
Markines16
2021-04-10 20:54:56 +02:00
committed by GitHub
parent d8184c40b3
commit a7575ba942
10 changed files with 337 additions and 68 deletions

View File

@ -0,0 +1,66 @@
<?php
include_once('session_dao.php');
include_once('../assets/php/form.php');
class FormSession extends Form {
//Atributes:
private $correct; // Indicates if the session is correct.
private $reply; // Validation response
//Constructor:
public function __construct() {
parent::__construct('formSession');
$this->reply = array();
}
//Methods:
//Returns validation response:
public function getReply() {
//Habria que comprobar si realmente se ha validado la respuesta antes de escribir una respuesta correcta
if($this->correct){
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
<p> Se ha añadido la sesion correctamente en la base de datos.</p>
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
} else {
$this->reply = "<h1> ERROR </h1><hr />
<p> Ha habido un error en la operacion. Revisa los datos introducidos o ponte en contacto con el administrador de la base de datos.</p>
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
}
return $this->reply;
}
//Process form:
public function processesForm($price, $film, $format, $start) {
$this->correct = true;
$hall = 2;
$cinema = 1;
$date = "2021-04-10";
//Habria que validar todo para que encaje en la base de datos
$start = date('H:i:s', strtotime( $start ) );
$date = date('Y-m-d', strtotime( $date ) );
$bd = new sessionDAO('complucine');
if($bd){
$selectSession = $bd->selectSession($cinema, $hall, $start, $date);
if($selectSession && $selectSession->num_rows >= 1) {
$this->correct = false;
} else{
$bd->createSession(null, $film, $hall,$cinema, $date, $start, $price, $format);
}
mysqli_free_result($selectSession);
}
}
}
?>

View File

@ -0,0 +1,67 @@
<?php
include_once('session_dao.php');
class ListSessions{
//Atributes:
private $array;
private $size;
private $cinema;
private $hall;
private $date;
//Constructor:
public function __construct($cinema,$hall,$date) {
$this->array = array();
$this->cinema = $cinema;
$this->hall = $hall;
$this->date = $date;
}
//Methods:
//Returns the whole session array
public function getArray() {
return $this->array;
}
//Returns the value i from the array
public function getiArray($i) {
if($i < $size){
return $this->array($i);
} else {
return null;
}
}
//Change the patterns of the filter
public function setCinema($cinema){$this->cinema = $cinema;}
public function setHall($hall){$this->hall = $hall;}
public function setDate($date){$this->date = $date;}
//Update the array with current filter values
public function filterList() {
$this->date = date('Y-m-d', strtotime( $this->date ) );
$bd = new sessionDAO('complucine');
if($bd){
$selectSession = $bd->selectSession($this->cinema, $this->hall, null, $this->date);
$selectSession->data_seek(0);
$this->size = 0;
while ($fila = $selectSession->fetch_assoc()) {
$this->array[]= new SessionDTO($fila['id'], $fila['idfilm'], $fila['idhall'], $fila['idcinema'], $fila['date'], date('h:i', strtotime( $fila['start_time'])) , $fila['seat_price'], $fila['format']);
$this->size++;
}
mysqli_free_result($selectSession);
}
}
}
?>

View File

@ -12,12 +12,14 @@
//Methods:
//Create a new Session.
public function createSession($id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format){
$sql = sprintf( "INSERT INTO sessions( $id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format)
VALUES ( '%s', '%s', '%s', '%date', '%time', '%d', '%s')",
$id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format );
public function createSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$sql = sprintf( "INSERT INTO `session` (`id`, `idfilm`, `idhall`, `idcinema`, `date`, `start_time`, `seat_price`, `format`)
VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s')",
$id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $sql;
}
@ -28,7 +30,25 @@
return $resul;
}
//Returns a query to check if the session in this cinema, hall and scheudle exists.
public function selectSession($cinema, $hall, $start, $date){
if($start == null){
$sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s'",
$cinema, $hall, $date);
}else{
$sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
$cinema, $hall, $date, $start);
}
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new Session Data Transfer Object.
public function loadSession( $id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format){
return new SessionDTO( $id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format);
@ -36,4 +56,4 @@
}
?>
?>

View File

@ -5,18 +5,20 @@
//Attributes:
private $_id; //Session Id.
private $_idfilm; //Film Id
private $_idhall //Hall id
private $_idfilm; //Film Id -> deberia ser un objeto tipo pelicula? para poder sacar el nombre de la pelicula en cuestion
private $_idhall; //Hall id -> deberia ser un objeto tipo room/hall/sala de cine por lo mismo
private $_idcinema;
private $_date; //Session date.
private $_startTime; //Session start time.
private $_seatPrice; //Seat price.
private $_format; //Type of film: 3D | 4D | normal | subtitle | mute.
//Constructor:
function __construct($id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format){
function __construct($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$this->_id = $id;
$this->_idfilm = $idfilm;
$this->_idhall = $idhall;
$this->_idcinema = $idcinema;
$this->_date = $date;
$this->_startTime = $startTime;
$this->_seatPrice = $seatPrice;
@ -32,8 +34,11 @@
public function setIdfilm($idfilm){ $this->_idfilm = $idfilm; }
public function getIdfilm(){ return $this->_idfilm; }
public function setIdhall($film){ $this->_idhall = $idhall; }
public function setIdhall($idhall){ $this->_idhall = $idhall; }
public function getIdhall(){ return $this->_idhall; }
public function setIdcinema($cinema){ $this->_idcinema = $idcinema; }
public function getIdcinema(){ return $this->_idcinema; }
public function setDate($date){ $this->_date = $date; }
public function getDate(){ return $this->_date; }