2021-04-28 21:46:10 +02:00
|
|
|
<?php
|
2021-05-05 16:55:00 +02:00
|
|
|
require_once($prefix.'assets/php/dao.php');
|
2021-05-03 12:37:10 +02:00
|
|
|
include_once('hall.php');
|
2021-05-10 16:46:18 +02:00
|
|
|
|
2021-05-06 23:23:34 +02:00
|
|
|
|
2021-04-28 21:46:10 +02:00
|
|
|
class HallDAO extends DAO {
|
|
|
|
|
|
|
|
//Constructor:
|
|
|
|
function __construct($bd_name){
|
|
|
|
parent::__construct($bd_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Methods:
|
|
|
|
|
|
|
|
//Create a new Hall.
|
2021-05-10 16:46:18 +02:00
|
|
|
public function createHall($number, $cinema, $rows, $cols, $seats, $seats_map){
|
2021-05-06 23:23:34 +02:00
|
|
|
|
|
|
|
$sql = sprintf( "INSERT INTO `hall`( `number`, `idcinema`, `numrows`, `numcolumns`, `total_seats`)
|
|
|
|
VALUES ( '%d', '%d', '%d', '%d', '%d')",
|
2021-05-10 16:46:18 +02:00
|
|
|
$number, $cinema, $rows, $cols, $seats );
|
2021-05-05 16:55:00 +02:00
|
|
|
|
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error BD createhall');
|
|
|
|
|
2021-04-28 21:46:10 +02:00
|
|
|
return $sql;
|
|
|
|
}
|
2021-05-05 16:55:00 +02:00
|
|
|
|
2021-04-28 21:46:10 +02:00
|
|
|
//Returns a query to get the halls data.
|
|
|
|
public function getAllHalls($cinema){
|
|
|
|
$sql = sprintf( "SELECT * FROM hall WHERE
|
|
|
|
idcinema = '%s'",
|
|
|
|
$cinema);
|
|
|
|
|
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
|
|
|
|
|
|
|
$hall = null;
|
|
|
|
while($fila=mysqli_fetch_array($resul)){
|
2021-05-10 16:46:18 +02:00
|
|
|
$hall[] = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"], $fila["total_seats"], null);
|
2021-04-28 21:46:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mysqli_free_result($resul);
|
|
|
|
|
|
|
|
return $hall;
|
|
|
|
}
|
2021-05-05 16:55:00 +02:00
|
|
|
|
2021-05-10 16:46:18 +02:00
|
|
|
public function searchHall($number, $cinema){
|
2021-05-05 16:55:00 +02:00
|
|
|
|
2021-05-13 14:06:07 +02:00
|
|
|
$sql = sprintf( "SELECT * FROM hall WHERE
|
2021-05-10 16:46:18 +02:00
|
|
|
number = '%s' AND idcinema = '%s'",
|
|
|
|
$number, $cinema);
|
2021-05-05 16:55:00 +02:00
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
2021-05-13 14:06:07 +02:00
|
|
|
$hall = false;
|
2021-05-05 16:55:00 +02:00
|
|
|
|
2021-05-13 14:06:07 +02:00
|
|
|
if($resul){
|
|
|
|
if($resul->num_rows == 1){
|
|
|
|
$fila = $resul->fetch_assoc();
|
|
|
|
$hall = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"], $fila["total_seats"], null);
|
|
|
|
}
|
|
|
|
$resul->free();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $hall;
|
2021-05-05 16:55:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-28 21:46:10 +02:00
|
|
|
//Create a new Hall Data Transfer Object.
|
2021-05-10 16:46:18 +02:00
|
|
|
public function loadHall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map){
|
|
|
|
return new Hall($number, $idcinema, $numrows, $numcolumns, $total_seats, $seats_map);
|
2021-04-28 21:46:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Edit Hall.
|
2021-05-10 16:46:18 +02:00
|
|
|
public function editHall($number, $cinema, $rows, $cols, $seats, $og_number){
|
|
|
|
|
2021-04-28 21:46:10 +02:00
|
|
|
$sql = sprintf( "UPDATE `hall`
|
2021-05-10 16:46:18 +02:00
|
|
|
SET `number` = '%d' ,`numrows` = '%d' , `numcolumns` = '%d' , `total_seats` = %d
|
2021-04-28 21:46:10 +02:00
|
|
|
WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",
|
2021-05-10 16:46:18 +02:00
|
|
|
$number, $rows, $cols, $seats, $og_number, $cinema );
|
|
|
|
|
|
|
|
|
2021-04-28 21:46:10 +02:00
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
|
|
|
|
|
|
|
return $resul;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Delete Hall.
|
2021-05-10 16:46:18 +02:00
|
|
|
public function deleteHall($number, $cinema){
|
2021-04-28 21:46:10 +02:00
|
|
|
|
2021-05-10 16:46:18 +02:00
|
|
|
$sql = sprintf( "DELETE FROM `hall` WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",$number, $cinema);
|
2021-04-28 21:46:10 +02:00
|
|
|
|
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
|
|
|
|
|
|
|
return $resul;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|