new functionality

This commit is contained in:
Daniel Muñoz Garcia 2021-05-05 11:56:27 +02:00 committed by GitHub
parent 17c64e04de
commit 7ea975ded7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
class Promotion{
//Attributes:
private $_id; //Cinema ID.
private $_tittle; //Cinema name.
private $_description; //Cinema direction.
private $_code; //Cinema phone.
private $_active;
//Constructor:
function __construct($id, $tittle, $description, $code, $active){
$this->_id = $id;
$this->_tittle = $tittle;
$this->_description = $description;
$this->_code = $code;
$this->_active = $active;
}
//Methods:
//Getters && Setters:
public function setId($id){ $this->_id = $id; }
public function getId(){ return $this->_id; }
public function setTittle($tittle){ $this->_tittle = $tittle; }
public function getTittle(){ return $this->_tittle; }
public function setDescription($description){ $this->_description = $description;}
public function getDescription(){return $this->_description;}
public function setCode($code){ $this->_code = $code;}
public function getCode(){return $this->_code;}
public function setActive($active){ $this->_active = $active;}
public function getActive(){return $this->_active;}
}
?>

View File

@ -0,0 +1,80 @@
<?php
include_once('promotion.php');
$template = new Template();
$prefix = $template->get_prefix();
include_once($prefix.'assets/php/dao.php');
class Promotion_DAO extends DAO {
//Constructor:
function __construct($bd_name){
parent::__construct($bd_name);
}
//Methods:
//Create a new Session.
public function createPromotion($id, $tittle, $description, $code, $active){
$sql = sprintf( "INSERT INTO `promotion`( `id`, `tittle`, `description`, `code`, `active`)
VALUES ( '%d', '%s', '%s', '%s', '%s')",
$id, $tittle, $description, $code, $active);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a query to get All the films.
public function allPromotionData(){
$sql = sprintf( "SELECT * FROM promotion ");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
while($fila=$resul->fetch_assoc()){
$promotions[] = $this->loadPromotion($fila["id"], $fila["tittle"], $fila["description"], $fila["code"], $fila["active"]);
}
$resul->free();
return $promotions;
}
//Returns a film data .
public function GetPromotion($code){
$sql = sprintf( "SELECT * FROM promotion WHERE promotion.code = '%s'", $code );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a film data .
public function promotionData($id){
$sql = sprintf( "SELECT * FROM promotion WHERE promotion.id = '%d'", $id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Deleted film by "id".
public function deletePromotion($id){
$sql = sprintf( "DELETE FROM promotion WHERE promotion.id = '%d' ;",$id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Edit a film.
public function editPromotion($id, $tittle, $description, $code, $active){
$sql = sprintf( "UPDATE promotion SET tittle = '%s' , description = '%s', code ='%s' , active ='%s'
WHERE promotion.id = '%d';",
$tittle, $description, $code, $active, $id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new film Data Transfer Object.
public function loadPromotion($id, $tittle, $description, $code, $active){
return new Promotion($id, $tittle, $description, $code, $active);
}
}
?>