2021-04-08 18:00:08 +02:00
|
|
|
<?php
|
|
|
|
require_once('../assets/php/dao.php');
|
|
|
|
include_once('session_dto.php');
|
2021-04-15 22:34:33 +02:00
|
|
|
|
2021-04-08 18:00:08 +02:00
|
|
|
class SessionDAO extends DAO {
|
|
|
|
//Constructor:
|
|
|
|
function __construct($bd_name){
|
|
|
|
parent::__construct($bd_name);
|
|
|
|
}
|
|
|
|
//Methods:
|
2021-04-15 20:53:01 +02:00
|
|
|
|
2021-04-10 20:54:56 +02:00
|
|
|
public function createSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
|
2021-04-15 20:53:01 +02:00
|
|
|
$format = $this->mysqli->real_escape_string($format);
|
|
|
|
$date = date('Y-m-d', strtotime( $date ) );
|
|
|
|
$startTime = date('H:i:s', strtotime( $startTime ) );
|
2021-04-10 20:54:56 +02:00
|
|
|
|
|
|
|
$sql = sprintf( "INSERT INTO `session` (`id`, `idfilm`, `idhall`, `idcinema`, `date`, `start_time`, `seat_price`, `format`)
|
2021-04-16 12:57:10 +02:00
|
|
|
VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s')",
|
2021-04-10 20:54:56 +02:00
|
|
|
$id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format);
|
|
|
|
|
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
|
|
|
|
2021-04-08 18:00:08 +02:00
|
|
|
return $sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Returns a query to get the session's data.
|
|
|
|
public function sessionData($id){
|
2021-04-11 19:11:16 +02:00
|
|
|
$sql = sprintf( "SELECT * FROM `session` WHERE id = '%d'", $id );
|
2021-04-11 19:55:21 +02:00
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $id);
|
2021-04-11 19:08:22 +02:00
|
|
|
|
|
|
|
return $resul;
|
2021-04-15 20:53:01 +02:00
|
|
|
}
|
2021-04-10 20:54:56 +02:00
|
|
|
|
2021-04-15 20:53:01 +02:00
|
|
|
//Returns the count of the session searched
|
|
|
|
public function searchSession($cinema, $hall, $startTime, $date){
|
|
|
|
$date = date('Y-m-d', strtotime( $date ) );
|
|
|
|
$startTime = date('H:i:s', strtotime( $startTime ) );
|
|
|
|
|
|
|
|
$sql = sprintf( "SELECT COUNT(*) FROM session WHERE
|
2021-04-10 20:54:56 +02:00
|
|
|
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
|
2021-04-15 20:53:01 +02:00
|
|
|
$cinema, $hall, $date, $startTime);
|
2021-04-10 20:54:56 +02:00
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
2021-04-15 20:53:01 +02:00
|
|
|
|
|
|
|
$session = null;
|
|
|
|
$session = mysqli_fetch_array($resul);
|
|
|
|
|
|
|
|
mysqli_free_result($resul);
|
|
|
|
|
|
|
|
return $session[0];
|
2021-04-10 20:54:56 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 20:53:01 +02:00
|
|
|
//Returns a query to get all the session's data.
|
|
|
|
public function getAllSessionsFromACinemaHallDate($cinema, $hall, $date){
|
|
|
|
$date = date('Y-m-d', strtotime( $date ) );
|
|
|
|
|
2021-04-13 21:15:28 +02:00
|
|
|
$sql = sprintf( "SELECT * FROM session WHERE
|
|
|
|
idcinema = '%s' AND idhall = '%s' AND date = '%s'",
|
|
|
|
$cinema, $hall, $date);
|
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
|
|
|
|
|
|
|
$sessions = null;
|
|
|
|
|
|
|
|
while($fila=mysqli_fetch_array($resul)){
|
|
|
|
$sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"]);
|
|
|
|
}
|
|
|
|
mysqli_free_result($resul);
|
|
|
|
|
|
|
|
return $sessions;
|
|
|
|
}
|
|
|
|
|
2021-04-15 22:34:33 +02:00
|
|
|
public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
|
2021-04-15 20:53:01 +02:00
|
|
|
$format = $this->mysqli->real_escape_string($format);
|
|
|
|
$date = date('Y-m-d', strtotime( $date ) );
|
|
|
|
$startTime = date('H:i:s', strtotime( $startTime ) );
|
|
|
|
|
2021-04-11 19:55:21 +02:00
|
|
|
$sql = sprintf( "UPDATE `session`
|
|
|
|
SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s',
|
2021-04-16 12:57:10 +02:00
|
|
|
`start_time` = '%s', `seat_price` = '%d', `format` = '%s'
|
2021-04-15 22:34:33 +02:00
|
|
|
WHERE
|
|
|
|
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
|
|
|
|
$idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $_SESSION["cinema"],$_SESSION["hall"],$_SESSION["date"],$_SESSION["start"]);
|
2021-04-11 19:55:21 +02:00
|
|
|
|
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
|
|
|
|
|
|
|
return $resul;
|
|
|
|
}
|
|
|
|
|
2021-04-15 22:34:33 +02:00
|
|
|
public function deleteSession($hall, $cinema, $date, $startTime){
|
2021-04-11 19:55:21 +02:00
|
|
|
|
2021-04-15 22:34:33 +02:00
|
|
|
$sql = sprintf( "DELETE FROM `session` WHERE
|
|
|
|
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
|
|
|
|
$cinema, $hall, $date, $startTime);
|
2021-04-11 19:55:21 +02:00
|
|
|
|
|
|
|
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
|
|
|
|
|
|
|
return $resul;
|
|
|
|
}
|
2021-04-10 20:54:56 +02:00
|
|
|
|
2021-04-08 18:00:08 +02:00
|
|
|
//Create a new Session Data Transfer Object.
|
2021-04-13 21:15:28 +02:00
|
|
|
public function loadSession( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
|
|
|
|
return new SessionDTO( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format);
|
2021-04-08 18:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-10 20:54:56 +02:00
|
|
|
?>
|