PageRenderTime 76ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Bitm/SEIP129575/Gender/Gender.php

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