Add files via upload

This commit is contained in:
Markines16 2021-05-10 16:46:18 +02:00 committed by GitHub
parent a1d04a6eae
commit 9da5b9310b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 44 deletions

View File

@ -1,6 +1,7 @@
<?php
include_once($prefix.'assets/php/common/hall_dao.php');
include_once('seat_dao.php');
class Hall{
//Attributes:
@ -9,14 +10,17 @@
private $_numRows; //Num rows.
private $_numCol; //Num columns.
private $_total_seats;
private $_seats_map;
//Constructor:
function __construct($number, $idcinema, $numRows, $numCol, $total_seats){
function __construct($number, $idcinema, $numRows, $numCol, $total_seats, $seats_map){
$this->_number = $number;
$this->_idcinema = $idcinema;
$this->_numRows = $numRows;
$this->_numCol = $numCol;
$this->_total_seats = $total_seats;
$_seats_map = array();
$_seats_map = $seats_map;
}
//Methods:
@ -27,11 +31,12 @@
return "";
}
public static function create_hall($hall){
public static function create_hall($number, $cinema, $rows, $cols, $seats, $seats_map){
$bd = new HallDAO('complucine');
if($bd ){
if(!$bd->searchHall($hall)){
$bd->createHall($hall);
if(!$bd->searchHall($number, $cinema)){
$bd->createHall($number, $cinema, $rows, $cols, $seats, $seats_map);
Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
return "Se ha creado la sala con exito";
} else {
return "Esta sala ya existe";
@ -39,26 +44,39 @@
} else { return "Error al conectarse a la base de datos"; }
}
public static function edit_hall($hall){
public static function edit_hall($number, $cinema, $rows, $cols, $seats, $seats_map, $og_number){
$bd = new HallDAO('complucine');
if($bd ){
if($bd->searchHall($hall)){
$bd->editHall($hall);
return "Se ha editado la sala con exito";
if($bd->searchHall($og_number, $cinema)){
if($og_number == $number){
Seat::deleteAllSeats($number, $cinema);
$bd->editHall($number, $cinema, $rows, $cols, $seats, $og_number);
Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
return "Se ha editado la sala con exito";
}else{
if(!$bd->searchHall($number, $cinema)){
Seat::deleteAllSeats($og_number, $cinema);
$bd->editHall($number, $cinema, $rows, $cols, $seats, $og_number);
Seat::createSeats($number, $cinema, $rows, $cols, $seats_map);
return "Se ha editado la sala con exito";
}else
return "El nuevo numero de sala ya existe en otra sala";
}
} else {
return "Esta sala no existe";
return "La sala a editar no existe";
}
} else { return "Error al conectarse a la base de datos"; }
}
public static function delete_hall($hall){
public static function delete_hall($number, $cinema, $rows, $cols, $seats, $seats_map, $og_number){
$bd = new HallDAO('complucine');
if($bd ){
if($bd->searchHall($hall)){
$bd->deleteHall($hall);
return "Se ha eliminado la sala con exito";
if($bd->searchHall($og_number, $cinema)){
$bd->deleteHall($og_number, $cinema);
Seat::deleteAllSeats($og_number, $cinema);
return "La sala se ha eliminado correctamente";
} else {
return "Esta sala no existe";
return "La sala a borrar no existe";
}
} else { return "Error al conectarse a la base de datos"; }
}
@ -79,7 +97,8 @@
public function setTotalSeats($totalSeat){ $this->_total_seats = $totalSeat; }
public function getTotalSeats(){ return $this->_total_seats; }
public function setSeatsmap($seats_map){ $this->_seats_map = $seats_map; }
public function getSeatsmap(){ return $this->_seats_map; }
}
?>

View File

@ -1,7 +1,7 @@
<?php
require_once($prefix.'assets/php/dao.php');
include_once('hall.php');
include_once('seat_dao.php');
class HallDAO extends DAO {
@ -13,16 +13,14 @@
//Methods:
//Create a new Hall.
public function createHall($hall){
public function createHall($number, $cinema, $rows, $cols, $seats, $seats_map){
$sql = sprintf( "INSERT INTO `hall`( `number`, `idcinema`, `numrows`, `numcolumns`, `total_seats`)
VALUES ( '%d', '%d', '%d', '%d', '%d')",
$hall['number'], $hall['cinema'], $hall['rows'], $hall['cols'], $hall['seats'] );
$number, $cinema, $rows, $cols, $seats );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createhall');
Seat::createSeats($hall);
return $sql;
}
@ -35,9 +33,8 @@
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$hall = null;
while($fila=mysqli_fetch_array($resul)){
$hall[] = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"], $fila["total_seats"]);
$hall[] = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"], $fila["total_seats"], null);
}
mysqli_free_result($resul);
@ -46,11 +43,11 @@
}
//Returns the count of the hall searched
public function searchHall($hall){
public function searchHall($number, $cinema){
$sql = sprintf( "SELECT COUNT(*) FROM hall WHERE
idcinema = '%s' AND number = '%s'",
$hall['cinema'], $hall['number']);
number = '%s' AND idcinema = '%s'",
$number, $cinema);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$hall = mysqli_fetch_array($resul);
@ -63,27 +60,28 @@
//Create a new Hall Data Transfer Object.
public function loadHall($number, $idcinema, $numrows, $numcolumns,$total_seats){
return new Hall($number, $idcinema, $numrows, $numcolumns,$total_seats);
public function loadHall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map){
return new Hall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map);
}
//Edit Hall.
public function editHall($hall){
public function editHall($number, $cinema, $rows, $cols, $seats, $og_number){
$sql = sprintf( "UPDATE `hall`
SET `numrows` = '%d' , `numcolumns` = '%d' , `total_seats` = %d
SET `number` = '%d' ,`numrows` = '%d' , `numcolumns` = '%d' , `total_seats` = %d
WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",
$hall['rows'], $hall['cols'], $hall['seats'], $hall['number'], $hall['cinema'] );
$number, $rows, $cols, $seats, $og_number, $cinema );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Delete Hall.
public function deleteHall($hall){
public function deleteHall($number, $cinema){
$sql = sprintf( "DELETE FROM `hall` WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",$hall['number'], $hall['cinema']);
$sql = sprintf( "DELETE FROM `hall` WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",$number, $cinema);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');

View File

@ -19,19 +19,28 @@
$this->_state = $state;
}
static public function createSeats($seat){
static public function createSeats($hall, $cinema, $rows, $cols, $seats_map){
$bd = new SeatDAO('complucine');
for($i = 1;$i <= $seat["rows"];$i++){
for($j = 1; $j <= $seat["cols"];$j++){
error_log("DAO ===> number ->".$seat['number']." cinema ->".$seat['cinema']." fila -> ". $i. " columna ->".$j." activa -> ".$seat[$i][$j]);
if($seat[$i][$j] == "1"){
$bd->createSeat($seat, $i, $j);
}
for($i = 1;$i <= $rows;$i++){
for($j = 1; $j <= $cols;$j++){
$bd->createSeat($hall, $cinema, $i, $j, $seats_map[$i][$j]);
}
}
}
static public function getSeatsMap($number, $cinema){
$bd = new SeatDAO('complucine');
if($bd )
return $bd->getAllSeats($number, $cinema);
}
static public function deleteAllSeats($number, $cinema){
$bd = new SeatDAO('complucine');
if($bd)
return $bd->deletemapSeats($number, $cinema);
}
//Getters && Setters:
public function setNumber($number){ $this->_number = $number; }
public function getNumber(){ return $this->_number; }

View File

@ -12,16 +12,48 @@
//Methods:
//Create a new Hall.
public function createSeat($seat, $row, $col){
public function createSeat($hall, $cinema, $row, $col, $state){
$sql = sprintf( "INSERT INTO `seat`( `idhall`, `idcinema`, `numrow`, `numcolum`, `active`)
VALUES ( '%d', '%d', '%d', '%d', '%d')",
$seat['number'], $seat['cinema'], $row, $col, $seat[$row][$col]);
$hall, $cinema, $row, $col, $state);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createSeat');
return $sql;
}
public function getAllSeats($number, $cinema){
$sql = sprintf( "SELECT * FROM seat WHERE
idhall = '%s' AND idcinema = '%s'",
$number, $cinema);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$seat_map = null;
while($fila=mysqli_fetch_array($resul)){
$seat_map[] = $this->loadSeat($fila["idhall"], $fila["idcinema"], $fila["numrow"], $fila["numcolum"], $fila["active"]);
}
mysqli_free_result($resul);
return $seat_map;
}
public function deletemapSeats($hall, $cinema){
$sql = sprintf( "DELETE FROM `seat` WHERE
idcinema = '%s' AND idhall = '%s'",
$cinema, $hall);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
public function loadSeat($idhall, $idcinema, $numRow, $numCol, $state){
return new Seat($idhall, $idcinema, $numRow, $numCol, $state);
}
}
?>