/src/BITM/SEIP148423/Birthday/Birthday.php

https://gitlab.com/Afsana/Afsana_148423_B35_Session_31 · PHP · 282 lines · 164 code · 104 blank · 14 comment · 13 complexity · 566c346e2ed58bc96bfdd6a3d112d78c MD5 · raw file

  1. <?php
  2. namespace App\Birthday;
  3. use App\Message\Message;
  4. use App\Model\Database as DB;
  5. use App\Utility\Utility;
  6. use PDO;
  7. class Birthday extends DB{
  8. public $id="";
  9. public $name="";
  10. public $birth_date="";
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. /*
  16. public function index(){
  17. echo "<br>".$this->id."<br>";
  18. echo $this->name."<br>";
  19. echo $this->birthDate."<br>";
  20. }
  21. */
  22. public function setData($data=NULL){
  23. if(array_key_exists('id',$data)){
  24. $this->id=$data['id'];
  25. }
  26. if(array_key_exists('name',$data)){
  27. $this->name=$data['name'];
  28. }
  29. if(array_key_exists('birth_date',$data)){
  30. $this->birth_date=$data['birth_date'];
  31. }
  32. }
  33. public function store(){
  34. $arrData=array($this->name, $this->birth_date);
  35. $sql="INSERT INTO Birthday (name,birth_date) VALUES (?,?)";
  36. $STH=$this->DBH->prepare($sql);
  37. $result=$STH->execute($arrData);
  38. if ($result)
  39. Message::message("Success! Data Has Been Inserted Successfully :)");
  40. else
  41. Message::message("Failed! Data Has Not Been Inserted Successfully :(");
  42. Utility::redirect('create.php'); // redirect korte hobe create.php te tai utility.php use korechi //
  43. }//end of store method
  44. public function index($fetchMode='ASSOC'){
  45. $STH = $this->DBH->query("SELECT * from birthday where is_deleted='No'");
  46. $fetchMode = strtoupper($fetchMode);
  47. if(substr_count($fetchMode,'OBJ') > 0)
  48. $STH->setFetchMode(PDO::FETCH_OBJ);
  49. else
  50. $STH->setFetchMode(PDO::FETCH_ASSOC);
  51. $arrAllData = $STH->fetchAll();
  52. return $arrAllData;
  53. }// end of index();
  54. public function view($fetchMode='ASSOC'){
  55. $STH = $this->DBH->query('SELECT * from birthday where id='.$this->id);
  56. $fetchMode = strtoupper($fetchMode);
  57. if(substr_count($fetchMode,'OBJ') > 0)
  58. $STH->setFetchMode(PDO::FETCH_OBJ);
  59. else
  60. $STH->setFetchMode(PDO::FETCH_ASSOC);
  61. $arrOneData = $STH->fetch();
  62. return $arrOneData;
  63. }// end of view();
  64. public function update(){
  65. $arrData = array ($this->name, $this->birth_date);
  66. $sql = "UPDATE birthday SET name = ?, birth_date = ? WHERE id =".$this->id;
  67. $STH = $this->DBH->prepare($sql);
  68. $STH->execute($arrData);
  69. Utility::redirect('index.php');
  70. }// end of update()
  71. public function delete(){
  72. $sql = "Delete from birthday where id=".$this->id;
  73. $STH = $this->DBH->prepare($sql);
  74. $STH->execute();
  75. Utility::redirect('index.php');
  76. }// end of delete()
  77. public function trash(){
  78. $sql = "Update birthday SET is_deleted=NOW() where id=".$this->id;
  79. $STH = $this->DBH->prepare($sql);
  80. $STH->execute();
  81. Utility::redirect('index.php');
  82. }// end of trash()
  83. public function trashed($fetchMode='ASSOC'){
  84. $sql = "SELECT * from birthday where is_deleted <> 'No' ";
  85. $STH = $this->DBH->query($sql);
  86. $fetchMode = strtoupper($fetchMode);
  87. if(substr_count($fetchMode,'OBJ') > 0)
  88. $STH->setFetchMode(PDO::FETCH_OBJ);
  89. else
  90. $STH->setFetchMode(PDO::FETCH_ASSOC);
  91. $arrAllData = $STH->fetchAll();
  92. return $arrAllData;
  93. }// end of trashed();
  94. public function recover(){
  95. $sql = "Update birthday SET is_deleted='No' where id=".$this->id;
  96. $STH = $this->DBH->prepare($sql);
  97. $STH->execute();
  98. Utility::redirect('index.php');
  99. }// end of recover();
  100. public function indexPaginator($page=0,$itemsPerPage=3){
  101. $start = (($page-1) * $itemsPerPage);
  102. $sql = "SELECT * from birthday WHERE is_deleted = 'No' LIMIT $start,$itemsPerPage";
  103. $STH = $this->DBH->query($sql);
  104. $STH->setFetchMode(PDO::FETCH_OBJ);
  105. $arrSomeData = $STH->fetchAll();
  106. return $arrSomeData;
  107. }// end of indexPaginator();
  108. public function trashedPaginator($page=0,$itemsPerPage=3){
  109. $start = (($page-1) * $itemsPerPage);
  110. $sql = "SELECT * from birthday WHERE is_deleted <> 'No' LIMIT $start,$itemsPerPage";
  111. $STH = $this->DBH->query($sql);
  112. $STH->setFetchMode(PDO::FETCH_OBJ);
  113. $arrSomeData = $STH->fetchAll();
  114. return $arrSomeData;
  115. }// end of trashedPaginator();
  116. public function search($requestArray){
  117. $sql = "";
  118. if( isset($requestArray['byName']) && isset($requestArray['byBirthDate']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND (`name` LIKE '%".$requestArray['search']."%' OR `birth_date` LIKE '%".$requestArray['search']."%')";
  119. if(isset($requestArray['byName']) && !isset($requestArray['byBirthDate']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND `name` LIKE '%".$requestArray['search']."%'";
  120. if(!isset($requestArray['byName']) && isset($requestArray['byBirthDate']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND `birth_date` LIKE '%".$requestArray['search']."%'";
  121. $STH = $this->DBH->query($sql);
  122. $STH->setFetchMode(PDO::FETCH_OBJ);
  123. $someData = $STH->fetchAll();
  124. return $someData;
  125. }// end of search()
  126. public function getAllKeywords()
  127. {
  128. $_allKeywords = array();
  129. //$WordsArr = array();
  130. $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No'";
  131. $STH = $this->DBH->query($sql);
  132. $STH->setFetchMode(PDO::FETCH_OBJ);
  133. // for each search field block start
  134. $allData= $STH->fetchAll();
  135. foreach ($allData as $oneData) {
  136. $_allKeywords[] = trim($oneData->name);
  137. }
  138. $STH = $this->DBH->query($sql);
  139. $STH->setFetchMode(PDO::FETCH_OBJ);
  140. $allData= $STH->fetchAll();
  141. foreach ($allData as $oneData) {
  142. $eachString= strip_tags($oneData->name);
  143. $eachString=trim( $eachString);
  144. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  145. $eachString= str_replace("&nbsp;","", $eachString);
  146. $WordsArr = explode(" ", $eachString);
  147. foreach ($WordsArr as $eachWord){
  148. $_allKeywords[] = trim($eachWord);
  149. }
  150. }
  151. // for each search field block end
  152. // for each search field block start
  153. $STH = $this->DBH->query($sql);
  154. $STH->setFetchMode(PDO::FETCH_OBJ);
  155. $allData= $STH->fetchAll();
  156. foreach ($allData as $oneData) {
  157. $_allKeywords[] = trim($oneData->birth_date);
  158. }
  159. $STH = $this->DBH->query($sql);
  160. $STH->setFetchMode(PDO::FETCH_OBJ);
  161. $allData= $STH->fetchAll();
  162. foreach ($allData as $oneData) {
  163. $eachString= strip_tags($oneData->birth_date);
  164. $eachString=trim( $eachString);
  165. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  166. $eachString= str_replace("&nbsp;","", $eachString);
  167. $WordsArr = explode(" ", $eachString);
  168. foreach ($WordsArr as $eachWord){
  169. $_allKeywords[] = trim($eachWord);
  170. }
  171. }
  172. // for each search field block end
  173. return array_unique($_allKeywords);
  174. }// get all keywords
  175. }//end of Birthday();
  176. //$objBirthday = new Birthday();
  177. ?>