/src/Bitm/SEIP1020/birthday/Birthday.php
https://gitlab.com/thohid44/Complete_Sumitted_Project_Without_Filter_Search · PHP · 234 lines · 191 code · 38 blank · 5 comment · 23 complexity · 0665f94f1f358c49063be6cccc456dbd MD5 · raw file
- <?php
- namespace App\Bitm\SEIP1020\Birthday;
- use App\Bitm\SEIP1020\Utility\Utility;
- use App\Bitm\SEIP1020\Message\Message;
- class Birthday
- {
- public $id = "";
- public $birthdate = "";
- public $conn;
- public $deleted_at;
- public function prepare($data = "")
- {
- if (array_key_exists("birthdate", $data)) {
- $this->birthdate = $data['birthdate'];
- }
- if (array_key_exists("id", $data)) {
- $this->id = $data['id'];
- }
- //echo $this;
- }
- public function __construct()
- {
- $this->conn = mysqli_connect("localhost", "root", "", "atomicprojectb22") or die("Database connection failed");
- }
- public function store()
- {
- $query = "INSERT INTO `atomicprojectb22`.`birthday` (`birthdate`) VALUES ('" . $this->birthdate . "')";
- //echo $query;
- $result = mysqli_query($this->conn, $query);
- if ($result) {
- Message::message("
- <div class=\"alert alert-success\">
- <strong>Success!</strong> Data has been stored successfully.
- </div>");
- Utility::redirect("index.php");
- } else {
- echo "Error";
- }
- }
- public function index()
- {
- $_allbirthday = array();
- $query = "SELECT * FROM `birthday` WHERE `deleted_at` IS NULL";
- $result = mysqli_query($this->conn, $query);
- while ($row = mysqli_fetch_object($result)) {
- $_allbirthday[] = $row;
- }
- return $_allbirthday;
- }
- public function view()
- {
- $query = "SELECT * FROM `birthday` WHERE `id`=" . $this->id;
- $result = mysqli_query($this->conn, $query);
- $row = mysqli_fetch_object($result);
- return $row;
- }
- public function update()
- {
- $query = "UPDATE `atomicprojectb22`.`birthday` SET `birthdate` = '" . $this->birthdate . "' WHERE `birthday`.`id` = " . $this->id;
- //echo $query;
- $result = mysqli_query($this->conn, $query);
- if ($result) {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Success!</strong> Data has been updated successfully.
- </div>");
- Utility::redirect("index.php");
- } else {
- echo "Error";
- }
- }
- public function delete()
- {
- $query = "DELETE FROM `atomicprojectb22`.`birthday` WHERE `birthday`.`id` = " . $this->id;
- $result = mysqli_query($this->conn, $query);
- if ($result) {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Data has been deleted successfully.
- </div>");
- Utility::redirect("index.php");
- } else {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Data has not been deleted successfully.
- </div>");
- Utility::redirect("index.php");
- }
- }
- public function trash()
- {
- $this->deleted_at = time();
- $query = "UPDATE `atomicprojectb22`.`birthday` SET `deleted_at` =" . $this->deleted_at . " WHERE `birthday`.`id` = " . $this->id;
- $result = mysqli_query($this->conn, $query);
- if ($result) {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Data has been trashed successfully.
- </div>");
- Utility::redirect("index.php");
- } else {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Data has not been trashed successfully.
- </div>");
- Utility::redirect("index.php");
- }
- }
- public function trashed()
- {
- $_allbirthday = array();
- $query = "SELECT * FROM `birthday` WHERE `deleted_at` IS NOT NULL";
- $result = mysqli_query($this->conn, $query);
- while ($row = mysqli_fetch_object($result)) {
- $_allbirthday[] = $row;
- }
- return $_allbirthday;
- }
- public function recover()
- {
- $query = "UPDATE `atomicprojectb22`.`birthday` SET `deleted_at` = NULL WHERE `birthday`.`id` = " . $this->id;
- $result = mysqli_query($this->conn, $query);
- if ($result) {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Data has been recovered successfully.
- </div>");
- Utility::redirect("index.php");
- } else {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Data has not been recovered successfully.
- </div>");
- Utility::redirect("index.php");
- }
- }
- public function recoverSeleted($IDs = Array())
- {
- if ((is_array($IDs)) && (count($IDs > 0))) {
- $ids = implode(",", $IDs);
- $query = "UPDATE `atomicprojectb22`.`birthday` SET `deleted_at` = NULL WHERE `birthday`.`id` IN(" . $ids . ")";
- //echo $query;
- //die();
- $result = mysqli_query($this->conn, $query);
- if ($result) {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Selected Data has been recovered successfully.
- </div>");
- Utility::redirect("index.php");
- } else {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Selected Data has not been recovered successfully.
- </div>");
- Utility::redirect("index.php");
- }
- }
- }
- public function deleteMultiple($IDs = Array())
- {
- if ((is_array($IDs)) && (count($IDs > 0))) {
- $ids = implode(",", $IDs);
- $query = "DELETE FROM `atomicprojectb22`.`birthday` WHERE `birthday`.`id` IN(" . $ids . ")";
- $result = mysqli_query($this->conn, $query);
- if ($result) {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Selected Data has been deleted successfully.
- </div>");
- Utility::redirect("index.php");
- } else {
- Message::message("
- <div class=\"alert alert-info\">
- <strong>Deleted!</strong> Selected Data has not been deleted successfully.
- </div>");
- Utility::redirect("index.php");
- }
- }
- }
- public function count(){
- $query="SELECT COUNT(*) AS totalItem FROM `atomicprojectb22`.`birthday` ";
- $result=mysqli_query($this->conn,$query);
- $row= mysqli_fetch_assoc($result);
- return $row['totalItem'];
- }
- public function paginator($pageStartFrom=0,$Limit=5){
- $_allCity = array();
- $query="SELECT * FROM `birthday` LIMIT ".$pageStartFrom.",".$Limit;
- $result = mysqli_query($this->conn, $query);
- while ($row = mysqli_fetch_object($result)) {
- $_allCity[] = $row;
- }
- return $_allCity;
- }
- }