From 7ea975ded7b78e2a48124fbb73c232446d183afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mu=C3=B1oz=20Garcia?= <73303506+danimu03@users.noreply.github.com> Date: Wed, 5 May 2021 11:56:27 +0200 Subject: [PATCH] new functionality --- assets/php/common/promotion.php | 36 +++++++++++++ assets/php/common/promotion_dao.php | 80 +++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 assets/php/common/promotion.php create mode 100644 assets/php/common/promotion_dao.php diff --git a/assets/php/common/promotion.php b/assets/php/common/promotion.php new file mode 100644 index 0000000..0abe64c --- /dev/null +++ b/assets/php/common/promotion.php @@ -0,0 +1,36 @@ +_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;} + + } +?> \ No newline at end of file diff --git a/assets/php/common/promotion_dao.php b/assets/php/common/promotion_dao.php new file mode 100644 index 0000000..1b2d23b --- /dev/null +++ b/assets/php/common/promotion_dao.php @@ -0,0 +1,80 @@ +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); + } + + } + +?>