Add files via upload
This commit is contained in:
parent
a1d04a6eae
commit
9da5b9310b
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once($prefix.'assets/php/common/hall_dao.php');
|
include_once($prefix.'assets/php/common/hall_dao.php');
|
||||||
|
include_once('seat_dao.php');
|
||||||
|
|
||||||
class Hall{
|
class Hall{
|
||||||
|
|
||||||
//Attributes:
|
//Attributes:
|
||||||
@ -9,14 +10,17 @@
|
|||||||
private $_numRows; //Num rows.
|
private $_numRows; //Num rows.
|
||||||
private $_numCol; //Num columns.
|
private $_numCol; //Num columns.
|
||||||
private $_total_seats;
|
private $_total_seats;
|
||||||
|
private $_seats_map;
|
||||||
|
|
||||||
//Constructor:
|
//Constructor:
|
||||||
function __construct($number, $idcinema, $numRows, $numCol, $total_seats){
|
function __construct($number, $idcinema, $numRows, $numCol, $total_seats, $seats_map){
|
||||||
$this->_number = $number;
|
$this->_number = $number;
|
||||||
$this->_idcinema = $idcinema;
|
$this->_idcinema = $idcinema;
|
||||||
$this->_numRows = $numRows;
|
$this->_numRows = $numRows;
|
||||||
$this->_numCol = $numCol;
|
$this->_numCol = $numCol;
|
||||||
$this->_total_seats = $total_seats;
|
$this->_total_seats = $total_seats;
|
||||||
|
$_seats_map = array();
|
||||||
|
$_seats_map = $seats_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Methods:
|
//Methods:
|
||||||
@ -27,11 +31,12 @@
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create_hall($hall){
|
public static function create_hall($number, $cinema, $rows, $cols, $seats, $seats_map){
|
||||||
$bd = new HallDAO('complucine');
|
$bd = new HallDAO('complucine');
|
||||||
if($bd ){
|
if($bd ){
|
||||||
if(!$bd->searchHall($hall)){
|
if(!$bd->searchHall($number, $cinema)){
|
||||||
$bd->createHall($hall);
|
$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";
|
return "Se ha creado la sala con exito";
|
||||||
} else {
|
} else {
|
||||||
return "Esta sala ya existe";
|
return "Esta sala ya existe";
|
||||||
@ -39,26 +44,39 @@
|
|||||||
} else { return "Error al conectarse a la base de datos"; }
|
} 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');
|
$bd = new HallDAO('complucine');
|
||||||
if($bd ){
|
if($bd ){
|
||||||
if($bd->searchHall($hall)){
|
if($bd->searchHall($og_number, $cinema)){
|
||||||
$bd->editHall($hall);
|
if($og_number == $number){
|
||||||
return "Se ha editado la sala con exito";
|
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 {
|
} else {
|
||||||
return "Esta sala no existe";
|
return "La sala a editar no existe";
|
||||||
}
|
}
|
||||||
} else { return "Error al conectarse a la base de datos"; }
|
} 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');
|
$bd = new HallDAO('complucine');
|
||||||
if($bd ){
|
if($bd ){
|
||||||
if($bd->searchHall($hall)){
|
if($bd->searchHall($og_number, $cinema)){
|
||||||
$bd->deleteHall($hall);
|
$bd->deleteHall($og_number, $cinema);
|
||||||
return "Se ha eliminado la sala con exito";
|
Seat::deleteAllSeats($og_number, $cinema);
|
||||||
|
return "La sala se ha eliminado correctamente";
|
||||||
} else {
|
} else {
|
||||||
return "Esta sala no existe";
|
return "La sala a borrar no existe";
|
||||||
}
|
}
|
||||||
} else { return "Error al conectarse a la base de datos"; }
|
} else { return "Error al conectarse a la base de datos"; }
|
||||||
}
|
}
|
||||||
@ -79,7 +97,8 @@
|
|||||||
public function setTotalSeats($totalSeat){ $this->_total_seats = $totalSeat; }
|
public function setTotalSeats($totalSeat){ $this->_total_seats = $totalSeat; }
|
||||||
public function getTotalSeats(){ return $this->_total_seats; }
|
public function getTotalSeats(){ return $this->_total_seats; }
|
||||||
|
|
||||||
|
public function setSeatsmap($seats_map){ $this->_seats_map = $seats_map; }
|
||||||
|
public function getSeatsmap(){ return $this->_seats_map; }
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once($prefix.'assets/php/dao.php');
|
require_once($prefix.'assets/php/dao.php');
|
||||||
include_once('hall.php');
|
include_once('hall.php');
|
||||||
include_once('seat_dao.php');
|
|
||||||
|
|
||||||
class HallDAO extends DAO {
|
class HallDAO extends DAO {
|
||||||
|
|
||||||
@ -13,16 +13,14 @@
|
|||||||
//Methods:
|
//Methods:
|
||||||
|
|
||||||
//Create a new Hall.
|
//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`)
|
$sql = sprintf( "INSERT INTO `hall`( `number`, `idcinema`, `numrows`, `numcolumns`, `total_seats`)
|
||||||
VALUES ( '%d', '%d', '%d', '%d', '%d')",
|
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');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createhall');
|
||||||
|
|
||||||
Seat::createSeats($hall);
|
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,9 +33,8 @@
|
|||||||
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||||
|
|
||||||
$hall = null;
|
$hall = null;
|
||||||
|
|
||||||
while($fila=mysqli_fetch_array($resul)){
|
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);
|
mysqli_free_result($resul);
|
||||||
@ -46,11 +43,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Returns the count of the hall searched
|
//Returns the count of the hall searched
|
||||||
public function searchHall($hall){
|
public function searchHall($number, $cinema){
|
||||||
|
|
||||||
$sql = sprintf( "SELECT COUNT(*) FROM hall WHERE
|
$sql = sprintf( "SELECT COUNT(*) FROM hall WHERE
|
||||||
idcinema = '%s' AND number = '%s'",
|
number = '%s' AND idcinema = '%s'",
|
||||||
$hall['cinema'], $hall['number']);
|
$number, $cinema);
|
||||||
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||||
|
|
||||||
$hall = mysqli_fetch_array($resul);
|
$hall = mysqli_fetch_array($resul);
|
||||||
@ -63,27 +60,28 @@
|
|||||||
|
|
||||||
|
|
||||||
//Create a new Hall Data Transfer Object.
|
//Create a new Hall Data Transfer Object.
|
||||||
public function loadHall($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);
|
return new Hall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Edit Hall.
|
//Edit Hall.
|
||||||
public function editHall($hall){
|
public function editHall($number, $cinema, $rows, $cols, $seats, $og_number){
|
||||||
|
|
||||||
$sql = sprintf( "UPDATE `hall`
|
$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';",
|
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');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||||
|
|
||||||
return $resul;
|
return $resul;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete Hall.
|
//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');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||||
|
|
||||||
|
@ -19,19 +19,28 @@
|
|||||||
$this->_state = $state;
|
$this->_state = $state;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function createSeats($seat){
|
static public function createSeats($hall, $cinema, $rows, $cols, $seats_map){
|
||||||
$bd = new SeatDAO('complucine');
|
$bd = new SeatDAO('complucine');
|
||||||
|
|
||||||
for($i = 1;$i <= $seat["rows"];$i++){
|
for($i = 1;$i <= $rows;$i++){
|
||||||
for($j = 1; $j <= $seat["cols"];$j++){
|
for($j = 1; $j <= $cols;$j++){
|
||||||
error_log("DAO ===> number ->".$seat['number']." cinema ->".$seat['cinema']." fila -> ". $i. " columna ->".$j." activa -> ".$seat[$i][$j]);
|
$bd->createSeat($hall, $cinema, $i, $j, $seats_map[$i][$j]);
|
||||||
if($seat[$i][$j] == "1"){
|
|
||||||
$bd->createSeat($seat, $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:
|
//Getters && Setters:
|
||||||
public function setNumber($number){ $this->_number = $number; }
|
public function setNumber($number){ $this->_number = $number; }
|
||||||
public function getNumber(){ return $this->_number; }
|
public function getNumber(){ return $this->_number; }
|
||||||
|
@ -12,16 +12,48 @@
|
|||||||
//Methods:
|
//Methods:
|
||||||
|
|
||||||
//Create a new Hall.
|
//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`)
|
$sql = sprintf( "INSERT INTO `seat`( `idhall`, `idcinema`, `numrow`, `numcolum`, `active`)
|
||||||
VALUES ( '%d', '%d', '%d', '%d', '%d')",
|
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');
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createSeat');
|
||||||
|
|
||||||
return $sql;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user