diff --git a/assets/php/common/hall.php b/assets/php/common/hall.php index c6fa2ad..92a5377 100644 --- a/assets/php/common/hall.php +++ b/assets/php/common/hall.php @@ -1,6 +1,7 @@ _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; } } ?> \ No newline at end of file diff --git a/assets/php/common/hall_dao.php b/assets/php/common/hall_dao.php index ff0dace..15d49b7 100644 --- a/assets/php/common/hall_dao.php +++ b/assets/php/common/hall_dao.php @@ -1,7 +1,7 @@ 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'); diff --git a/assets/php/common/seat.php b/assets/php/common/seat.php index eb3b950..5dd1a4e 100644 --- a/assets/php/common/seat.php +++ b/assets/php/common/seat.php @@ -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; } diff --git a/assets/php/common/seat_dao.php b/assets/php/common/seat_dao.php index c97f8e3..d129882 100644 --- a/assets/php/common/seat_dao.php +++ b/assets/php/common/seat_dao.php @@ -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); + } + } ?> \ No newline at end of file