/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

  1. <?php
  2. namespace App\Bitm\SEIP1020\Birthday;
  3. use App\Bitm\SEIP1020\Utility\Utility;
  4. use App\Bitm\SEIP1020\Message\Message;
  5. class Birthday
  6. {
  7. public $id = "";
  8. public $birthdate = "";
  9. public $conn;
  10. public $deleted_at;
  11. public function prepare($data = "")
  12. {
  13. if (array_key_exists("birthdate", $data)) {
  14. $this->birthdate = $data['birthdate'];
  15. }
  16. if (array_key_exists("id", $data)) {
  17. $this->id = $data['id'];
  18. }
  19. //echo $this;
  20. }
  21. public function __construct()
  22. {
  23. $this->conn = mysqli_connect("localhost", "root", "", "atomicprojectb22") or die("Database connection failed");
  24. }
  25. public function store()
  26. {
  27. $query = "INSERT INTO `atomicprojectb22`.`birthday` (`birthdate`) VALUES ('" . $this->birthdate . "')";
  28. //echo $query;
  29. $result = mysqli_query($this->conn, $query);
  30. if ($result) {
  31. Message::message("
  32. <div class=\"alert alert-success\">
  33. <strong>Success!</strong> Data has been stored successfully.
  34. </div>");
  35. Utility::redirect("index.php");
  36. } else {
  37. echo "Error";
  38. }
  39. }
  40. public function index()
  41. {
  42. $_allbirthday = array();
  43. $query = "SELECT * FROM `birthday` WHERE `deleted_at` IS NULL";
  44. $result = mysqli_query($this->conn, $query);
  45. while ($row = mysqli_fetch_object($result)) {
  46. $_allbirthday[] = $row;
  47. }
  48. return $_allbirthday;
  49. }
  50. public function view()
  51. {
  52. $query = "SELECT * FROM `birthday` WHERE `id`=" . $this->id;
  53. $result = mysqli_query($this->conn, $query);
  54. $row = mysqli_fetch_object($result);
  55. return $row;
  56. }
  57. public function update()
  58. {
  59. $query = "UPDATE `atomicprojectb22`.`birthday` SET `birthdate` = '" . $this->birthdate . "' WHERE `birthday`.`id` = " . $this->id;
  60. //echo $query;
  61. $result = mysqli_query($this->conn, $query);
  62. if ($result) {
  63. Message::message("
  64. <div class=\"alert alert-info\">
  65. <strong>Success!</strong> Data has been updated successfully.
  66. </div>");
  67. Utility::redirect("index.php");
  68. } else {
  69. echo "Error";
  70. }
  71. }
  72. public function delete()
  73. {
  74. $query = "DELETE FROM `atomicprojectb22`.`birthday` WHERE `birthday`.`id` = " . $this->id;
  75. $result = mysqli_query($this->conn, $query);
  76. if ($result) {
  77. Message::message("
  78. <div class=\"alert alert-info\">
  79. <strong>Deleted!</strong> Data has been deleted successfully.
  80. </div>");
  81. Utility::redirect("index.php");
  82. } else {
  83. Message::message("
  84. <div class=\"alert alert-info\">
  85. <strong>Deleted!</strong> Data has not been deleted successfully.
  86. </div>");
  87. Utility::redirect("index.php");
  88. }
  89. }
  90. public function trash()
  91. {
  92. $this->deleted_at = time();
  93. $query = "UPDATE `atomicprojectb22`.`birthday` SET `deleted_at` =" . $this->deleted_at . " WHERE `birthday`.`id` = " . $this->id;
  94. $result = mysqli_query($this->conn, $query);
  95. if ($result) {
  96. Message::message("
  97. <div class=\"alert alert-info\">
  98. <strong>Deleted!</strong> Data has been trashed successfully.
  99. </div>");
  100. Utility::redirect("index.php");
  101. } else {
  102. Message::message("
  103. <div class=\"alert alert-info\">
  104. <strong>Deleted!</strong> Data has not been trashed successfully.
  105. </div>");
  106. Utility::redirect("index.php");
  107. }
  108. }
  109. public function trashed()
  110. {
  111. $_allbirthday = array();
  112. $query = "SELECT * FROM `birthday` WHERE `deleted_at` IS NOT NULL";
  113. $result = mysqli_query($this->conn, $query);
  114. while ($row = mysqli_fetch_object($result)) {
  115. $_allbirthday[] = $row;
  116. }
  117. return $_allbirthday;
  118. }
  119. public function recover()
  120. {
  121. $query = "UPDATE `atomicprojectb22`.`birthday` SET `deleted_at` = NULL WHERE `birthday`.`id` = " . $this->id;
  122. $result = mysqli_query($this->conn, $query);
  123. if ($result) {
  124. Message::message("
  125. <div class=\"alert alert-info\">
  126. <strong>Deleted!</strong> Data has been recovered successfully.
  127. </div>");
  128. Utility::redirect("index.php");
  129. } else {
  130. Message::message("
  131. <div class=\"alert alert-info\">
  132. <strong>Deleted!</strong> Data has not been recovered successfully.
  133. </div>");
  134. Utility::redirect("index.php");
  135. }
  136. }
  137. public function recoverSeleted($IDs = Array())
  138. {
  139. if ((is_array($IDs)) && (count($IDs > 0))) {
  140. $ids = implode(",", $IDs);
  141. $query = "UPDATE `atomicprojectb22`.`birthday` SET `deleted_at` = NULL WHERE `birthday`.`id` IN(" . $ids . ")";
  142. //echo $query;
  143. //die();
  144. $result = mysqli_query($this->conn, $query);
  145. if ($result) {
  146. Message::message("
  147. <div class=\"alert alert-info\">
  148. <strong>Deleted!</strong> Selected Data has been recovered successfully.
  149. </div>");
  150. Utility::redirect("index.php");
  151. } else {
  152. Message::message("
  153. <div class=\"alert alert-info\">
  154. <strong>Deleted!</strong> Selected Data has not been recovered successfully.
  155. </div>");
  156. Utility::redirect("index.php");
  157. }
  158. }
  159. }
  160. public function deleteMultiple($IDs = Array())
  161. {
  162. if ((is_array($IDs)) && (count($IDs > 0))) {
  163. $ids = implode(",", $IDs);
  164. $query = "DELETE FROM `atomicprojectb22`.`birthday` WHERE `birthday`.`id` IN(" . $ids . ")";
  165. $result = mysqli_query($this->conn, $query);
  166. if ($result) {
  167. Message::message("
  168. <div class=\"alert alert-info\">
  169. <strong>Deleted!</strong> Selected Data has been deleted successfully.
  170. </div>");
  171. Utility::redirect("index.php");
  172. } else {
  173. Message::message("
  174. <div class=\"alert alert-info\">
  175. <strong>Deleted!</strong> Selected Data has not been deleted successfully.
  176. </div>");
  177. Utility::redirect("index.php");
  178. }
  179. }
  180. }
  181. public function count(){
  182. $query="SELECT COUNT(*) AS totalItem FROM `atomicprojectb22`.`birthday` ";
  183. $result=mysqli_query($this->conn,$query);
  184. $row= mysqli_fetch_assoc($result);
  185. return $row['totalItem'];
  186. }
  187. public function paginator($pageStartFrom=0,$Limit=5){
  188. $_allCity = array();
  189. $query="SELECT * FROM `birthday` LIMIT ".$pageStartFrom.",".$Limit;
  190. $result = mysqli_query($this->conn, $query);
  191. while ($row = mysqli_fetch_object($result)) {
  192. $_allCity[] = $row;
  193. }
  194. return $_allCity;
  195. }
  196. }