restructuring and functionality cinemas
This commit is contained in:
committed by
GitHub
parent
d85e933c73
commit
dfbe2877b5
32
panel_admin/includes/cinema.php
Normal file
32
panel_admin/includes/cinema.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class Cinema{
|
||||
|
||||
//Attributes:
|
||||
private $_id; //Cinema ID.
|
||||
private $_name; //Cinema name.
|
||||
private $_direction; //Cinema direction.
|
||||
private $_phone; //Cinema phone.
|
||||
|
||||
|
||||
//Constructor:
|
||||
function __construct($id, $name, $direction, $phone){
|
||||
$this->_id = $id;
|
||||
$this->_name = $name;
|
||||
$this->_direction = $direction;
|
||||
$this->_phone = $phone;
|
||||
}
|
||||
|
||||
//Methods:
|
||||
|
||||
//Getters && Setters:
|
||||
public function setId($id){ $this->_id = $id; }
|
||||
public function getId(){ return $this->_id; }
|
||||
public function setName($name){ $this->_name = $name; }
|
||||
public function getName(){ return $this->_name; }
|
||||
public function setDirection($direction){ $this->_direction = $direction; }
|
||||
public function getDirection(){ return $this->_direction; }
|
||||
public function setPhone($phone){$this->_phone = $phone; }
|
||||
public function getPhone(){ return $this->_phone; }
|
||||
}
|
||||
?>
|
66
panel_admin/includes/cinema_dao.php
Normal file
66
panel_admin/includes/cinema_dao.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
include_once('cinema_dto.php');
|
||||
$template = new Template();
|
||||
$prefix = $template->get_prefix();
|
||||
include_once($prefix.'assets/php/dao.php');
|
||||
|
||||
class Cinema_DAO extends DAO {
|
||||
|
||||
//Constructor:
|
||||
function __construct($bd_name){
|
||||
parent::__construct($bd_name);
|
||||
}
|
||||
|
||||
//Methods:
|
||||
|
||||
//Create a new Session.
|
||||
public function createCinema($id, $name, $direction, $phone){
|
||||
$sql = sprintf( "INSERT INTO `cinema`( `id`, `name`, `direction`, `phone`)
|
||||
VALUES ( '%d', '%s', '%s', '%s')",
|
||||
$id, $name, $direction, $phone);
|
||||
|
||||
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||
return $resul;
|
||||
}
|
||||
|
||||
|
||||
//Returns a query to get All the films.
|
||||
public function allCinemaData(){
|
||||
$sql = sprintf( "SELECT * FROM cinema ");
|
||||
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||
|
||||
while($fila=$resul->fetch_assoc()){
|
||||
$films[] = $this->loadCinema($fila["id"], $fila["name"], $fila["direction"], $fila["phone"]);
|
||||
}
|
||||
$resul->free();
|
||||
return $films;
|
||||
}
|
||||
|
||||
//Deleted film by "id".
|
||||
public function deleteCinema($id){
|
||||
$sql = sprintf( "DELETE FROM cinema WHERE cinema.id = '%d' ;",$id);
|
||||
|
||||
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||
|
||||
return $resul;
|
||||
}
|
||||
|
||||
//Edit a film.
|
||||
public function editCinema($id, $name, $direction, $phone){
|
||||
$sql = sprintf( "UPDATE cinema SET name = '%s' , direction = '%s', phone ='%s'
|
||||
WHERE cinema.id = '%d';",
|
||||
$name, $direction, $phone, $id);
|
||||
|
||||
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
|
||||
|
||||
return $resul;
|
||||
}
|
||||
|
||||
//Create a new film Data Transfer Object.
|
||||
public function loadCinema($id, $name, $direction, $phone){
|
||||
return new Cinema($id, $name, $direction, $phone);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
include_once('film_dto_interface.php');
|
||||
|
||||
class Film{
|
||||
|
||||
@ -33,5 +32,7 @@
|
||||
public function getLanguage(){return $this->_language;}
|
||||
public function setDescription($description){ $this->_description = $description;}
|
||||
public function getDescription(){return $this->_description;}
|
||||
|
||||
|
||||
}
|
||||
?>
|
115
panel_admin/includes/formCinema.php
Normal file
115
panel_admin/includes/formCinema.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
include_once('../assets/php/config.php');
|
||||
include_once('../assets/php/common/cinema_dao.php');
|
||||
include_once('../assets/php/common/cinema.php');
|
||||
include_once('../assets/php/form.php');
|
||||
|
||||
class FormCinema extends Form {
|
||||
|
||||
//Atributes:
|
||||
private $correct; // Indicates if the session is correct.
|
||||
private $reply; // Validation response
|
||||
private $option;
|
||||
private $array;
|
||||
//Constructor:
|
||||
public function __construct() {
|
||||
parent::__construct('formCinema');
|
||||
$this->reply = array();
|
||||
}
|
||||
|
||||
public function getReply() {
|
||||
if($this->correct){
|
||||
if($this->option == "new"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha añadido el cine correctamente en la base de datos.</p>
|
||||
<a href='../panel_admin/index.php?state=mc'><button>Cerrar Mensaje</button></a>";
|
||||
}else if($this->option == "edit"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha editado el cine correctamente en la base de datos.</p>
|
||||
<a href='../panel_admin/index.php?state=mc'><button>Cerrar Mensaje</button></a>";
|
||||
}else if($this->option == "del"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha eliminado el cine correctamente en la base de datos.</p>
|
||||
<a href='../panel_admin/index.php?state=mc'><button>Cerrar Mensaje</button></a>";
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->reply = "<h1> ERROR </h1><hr />
|
||||
<p> Ha habido un error en la operacion. Revisa los datos introducidos</p>
|
||||
<a href='../panel_admin/index.php?state=mc'><button>Panel Admin</button></a>";
|
||||
|
||||
}
|
||||
return $this->reply;
|
||||
}
|
||||
|
||||
//Process form:
|
||||
public function processesForm($_id, $_name, $_direction, $_phone, $_option) {
|
||||
$this->correct = true;
|
||||
$this->option = $_option;
|
||||
|
||||
$id= $this->test_input($_id);
|
||||
$name=$this->test_input($_name);
|
||||
$direction=$this->test_input($_direction);
|
||||
$phone=$this->test_input($_phone);
|
||||
|
||||
//Habria que validar todo para que encaje en la base de datos
|
||||
|
||||
$bd = new Cinema_DAO('complucine');
|
||||
if($bd){
|
||||
if($this->option == "new"){
|
||||
//Primero comprobar si los campos no son vacios y la duracion es mayor que 0
|
||||
if(!empty($name)&&!empty($direction)&&!empty($phone)){
|
||||
// comprobar si existe una pelicula con el mismo nombre y direccion
|
||||
$exist = $bd->GetCinema($name,$direction);
|
||||
if( mysqli_num_rows($exist) != 0){
|
||||
$this->correct =false;
|
||||
}
|
||||
else{
|
||||
$bd->createCinema(null, $name, $direction, $phone);
|
||||
|
||||
}
|
||||
$exist->free();
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
} else if ($this->option == "del"){
|
||||
//Primero comprobar si existe una pelicula con el mismo id
|
||||
$exist = $bd-> CinemaData($id);
|
||||
if( mysqli_num_rows($exist) == 1){
|
||||
$bd->deleteCinema($id);
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
} else if ($this->option == "edit"){
|
||||
//Primero comprobar si los campos no son vacios y la duracion es mayor que 0
|
||||
if(!empty($name)&&!empty($direction)&&!empty($phone)){
|
||||
//comprobar si existe una pelicula con el mismo id
|
||||
$exist = $bd-> CinemaData($id);
|
||||
if( mysqli_num_rows($exist) == 1){
|
||||
$bd->editCinema($id,$name,$direction,$phone);
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
$exist->free();
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
}
|
||||
else {$this->correct = false;}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function test_input($input){
|
||||
return htmlspecialchars(trim(strip_tags($input)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -18,8 +18,6 @@ class FormFilm extends Form {
|
||||
$this->reply = array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getReply() {
|
||||
if($this->correct){
|
||||
if($this->option == "new"){
|
||||
@ -34,8 +32,6 @@ class FormFilm extends Form {
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha eliminado la pelicula correctamente en la base de datos.</p>
|
||||
<a href='../panel_admin/index.php?state=mf'><button>Cerrar Mensaje</button></a>";
|
||||
} else if($this->option == "show"){
|
||||
$this->reply= $this->array;
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -104,9 +100,7 @@ class FormFilm extends Form {
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
} else if($this->option == "show") {
|
||||
$this->array = $bd->allFilmData();
|
||||
}
|
||||
}
|
||||
else {$this->correct = false;}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user