PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIP143467/Birthday/Birthday.php

https://gitlab.com/Mishu_ctg69/Princy_143467_B37_Atomic_project
PHP | 399 lines | 295 code | 95 blank | 9 comment | 18 complexity | 8c92af2e927daf0b610af484249f5be5 MD5 | raw file
  1. <?php
  2. namespace App\BITM\SEIP143467\Birthday;
  3. use App\BITM\SEIP143467\Message\Message;
  4. use App\BITM\SEIP143467\Utility\Utility;
  5. use App\BITM\SEIP143467\Model\Database as DB;
  6. use PDO;
  7. class Birthday extends DB{
  8. public $id="";
  9. public $name="";
  10. public $birthday="";
  11. public function __construct(){
  12. parent::__construct();
  13. }
  14. public function index($fetchMode='ASSOC'){
  15. $fetchMode = strtoupper($fetchMode);
  16. $DBH=$this->connection;
  17. $sth=$DBH->prepare("select * from birthday Where is_deleted='0'");
  18. $sth->execute();
  19. if(substr_count($fetchMode,'OBJ') > 0)
  20. $sth->setFetchMode(PDO::FETCH_OBJ);
  21. else
  22. $sth->setFetchMode(PDO::FETCH_ASSOC);
  23. $all_birthday=$sth->fetchAll();
  24. return $all_birthday;
  25. }
  26. // end of index();
  27. public function view($id){
  28. $DBH=$this->connection;
  29. $sth=$DBH->prepare("select * from birthday Where id=$id");
  30. $sth->execute();
  31. $sth->setFetchMode(PDO::FETCH_ASSOC);
  32. $selected_person=$sth->fetch();
  33. return $selected_person;
  34. }
  35. public function update(){
  36. $dbh=$this->connection;
  37. $values=array($this->name,$this->birthday);
  38. //var_dump($values);
  39. $query='UPDATE birthday SET name = ? , birthday = ? where id ='.$this->id;
  40. // $query='UPDATE book_title SET book_title = ? , author_name = ? where id ='.$this->id;
  41. $sth=$dbh->prepare($query);
  42. $sth->execute($values);
  43. if($sth)
  44. { Message::message("<div id='msg'><h3 align='center'>[ name: $this->name ] ,
  45. [ Birthday: $this->birthday ] <br> Data Has Been Updated Successfully!</h3></div>");
  46. }
  47. else
  48. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been Updated !</h3></div>");
  49. Utility::redirect('index.php');
  50. }
  51. public function delete($id){
  52. $DBH=$this->connection;
  53. $sth=$DBH->prepare("delete from birthday Where id=$id");
  54. $sth->execute();
  55. if($sth)
  56. { Message::message("<div id='msg'><h3 align='center'>
  57. <br> Data Has deleted Successfully!</h3></div>");
  58. }
  59. else
  60. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been Inserted !</h3></div>");
  61. Utility::redirect('index.php');
  62. }
  63. public function setData($data=null){
  64. if(array_key_exists('id',$data)){
  65. $this->id=$data['id'];
  66. }
  67. if(array_key_exists('name',$data)){
  68. $this->name=$data['name'];
  69. }
  70. if(array_key_exists('birthday',$data)){
  71. $this->birthday=$data['birthday'];
  72. }
  73. }
  74. public function store(){
  75. $dbh=$this->connection;
  76. $values=array($this->name,$this->birthday);
  77. $query="insert into birthday(name,birthday) VALUES (?,?)";
  78. $sth=$dbh->prepare($query);
  79. $sth->execute($values);
  80. if($sth)
  81. { Message::message("<div id='msg'><h3 align='center'>[ Name: $this->name ] ,
  82. [ birthday: $this->birthday ] <br> Data Has Been Inserted Successfully!</h3></div>");
  83. }
  84. else
  85. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been Inserted !</h3></div>");
  86. Utility::redirect('index.php');
  87. }
  88. public function trash($id){
  89. $dbh=$this->connection;
  90. //var_dump($values);
  91. $query='UPDATE birthday SET is_deleted = "1" where id ='.$id;
  92. $sth=$dbh->prepare($query);
  93. $sth->execute();
  94. if($sth)
  95. { Message::message("<div id='msg'><h3 align='center'>
  96. <br> Data Has Been trashed Successfully!</h3></div>");
  97. }
  98. else
  99. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been trashed !</h3></div>");
  100. Utility::redirect('index.php');
  101. }
  102. public function trashed($fetchMode='ASSOC'){
  103. $fetchMode = strtoupper($fetchMode);
  104. $DBH=$this->connection;
  105. $sth=$DBH->prepare("select * from birthday WHERE is_deleted='1'");
  106. $sth->execute();
  107. if(substr_count($fetchMode,'OBJ') > 0)
  108. $sth->setFetchMode(PDO::FETCH_OBJ);
  109. else
  110. $sth->setFetchMode(PDO::FETCH_ASSOC);
  111. $all_person=$sth->fetchAll();
  112. return $all_person;
  113. }
  114. public function recover($id){
  115. $dbh=$this->connection;
  116. //var_dump($values);
  117. $query='UPDATE birthday SET is_deleted = "0" where id ='.$id;
  118. $sth=$dbh->prepare($query);
  119. $sth->execute();
  120. if($sth)
  121. { Message::message("<div id='msg'><h3 align='center'>
  122. <br> Data Has Been recovered Successfully!</h3></div>");
  123. }
  124. else
  125. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been recovered !</h3></div>");
  126. Utility::redirect('trashed.php');
  127. }
  128. public function deleteMultiple($IDs = Array())
  129. {
  130. if ((is_array($IDs)) && (count($IDs > 0))) {
  131. $dbh=$this->connection;
  132. $n=count($IDs);
  133. // Utility::dd($IDs);
  134. for($i=0;$i<$n;$i++)
  135. {
  136. $query="delete from birthday Where id=$IDs[$i]";
  137. $sth=$dbh->prepare($query);
  138. $sth->execute();
  139. }
  140. if($sth)
  141. { Message::message("<div id='msg'><h3 align='center'>
  142. <br> Selected Data has been deleted Successfully!</h3></div>");
  143. }
  144. else
  145. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been recovered !</h3></div>");
  146. Utility::redirect('index.php');
  147. }
  148. }
  149. public function recoverMultiple($IDs = Array())
  150. {
  151. if ((is_array($IDs)) && (count($IDs > 0))) {
  152. $dbh=$this->connection;
  153. $n=count($IDs);
  154. // Utility::dd($IDs);
  155. for($i=0;$i<$n;$i++)
  156. {
  157. $query='UPDATE birthday SET is_deleted = "0" where id ='.$IDs["$i"];
  158. $sth=$dbh->prepare($query);
  159. $sth->execute();
  160. }
  161. if($sth)
  162. { Message::message("<div id='msg'><h3 align='center'>
  163. <br> Selected Data has been deleted Successfully!</h3></div>");
  164. }
  165. else
  166. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been recovered !</h3></div>");
  167. Utility::redirect('index.php');
  168. }
  169. }
  170. public function trashMultiple($IDs = Array())
  171. {
  172. if ((is_array($IDs)) && (count($IDs > 0))) {
  173. $dbh=$this->connection;
  174. $n=count($IDs);
  175. // Utility::dd($IDs);
  176. for($i=0;$i<$n;$i++)
  177. {
  178. $query='UPDATE birthday SET is_deleted = "1" where id ='.$IDs["$i"];
  179. $sth=$dbh->prepare($query);
  180. $sth->execute();
  181. }
  182. if($sth)
  183. { Message::message("<div id='msg'><h3 align='center'>
  184. <br> Selected Data has been Trashed Successfully!</h3></div>");
  185. }
  186. else
  187. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been trashed !</h3></div>");
  188. Utility::redirect('index.php');
  189. }
  190. }
  191. public function indexPaginator($page=0,$itemsPerPage=3){
  192. $start = (($page-1) * $itemsPerPage);
  193. $DBH=$this->connection;
  194. $sth=$DBH->prepare("select * from birthday WHERE is_deleted='0' LIMIT $start,$itemsPerPage");
  195. $sth->execute();
  196. $sth->setFetchMode(PDO::FETCH_ASSOC);
  197. $arrSomeData = $sth->fetchAll();
  198. return $arrSomeData;
  199. }// end of indexPaginator();
  200. public function trashPaginator($page=0,$itemsPerPage=3){
  201. $start = (($page-1) * $itemsPerPage);
  202. $DBH=$this->connection;
  203. $sth=$DBH->prepare("select * from birthday WHERE is_deleted='1' LIMIT $start,$itemsPerPage");
  204. $sth->execute();
  205. $sth->setFetchMode(PDO::FETCH_ASSOC);
  206. $arrSomeData = $sth->fetchAll();
  207. return $arrSomeData;
  208. }// end of indexPaginator();
  209. public function getAllKeywords()
  210. {
  211. $_allKeywords = array();
  212. $WordsArr = array();
  213. $sql = "SELECT * FROM birthday WHERE is_deleted='0'";
  214. $DBH=$this->connection;
  215. $STH = $DBH->query($sql);
  216. $STH->setFetchMode(PDO::FETCH_ASSOC);
  217. // for each search field block start
  218. $allData= $STH->fetchAll();
  219. foreach ($allData as $oneData) {
  220. $_allKeywords[] = trim($oneData['name']);
  221. }
  222. $STH = $DBH->query($sql);
  223. $STH->setFetchMode(PDO::FETCH_ASSOC);
  224. $allData= $STH->fetchAll();
  225. foreach ($allData as $oneData) {
  226. $eachString= strip_tags($oneData['name']);
  227. $eachString=trim( $eachString);
  228. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  229. $eachString= str_replace("&nbsp;","", $eachString);
  230. $WordsArr = explode(" ", $eachString);
  231. foreach ($WordsArr as $eachWord){
  232. $_allKeywords[] = trim($eachWord);
  233. }
  234. }
  235. // for each search field block end
  236. // for each search field block start
  237. $STH = $DBH->query($sql);
  238. $STH->setFetchMode(PDO::FETCH_ASSOC);
  239. $allData= $STH->fetchAll();
  240. foreach ($allData as $oneData) {
  241. $_allKeywords[] = trim($oneData['birthday']);
  242. }
  243. $STH = $DBH->query($sql);
  244. $STH->setFetchMode(PDO::FETCH_ASSOC);
  245. $allData= $STH->fetchAll();
  246. foreach ($allData as $oneData) {
  247. $eachString= strip_tags($oneData['birthday']);
  248. $eachString=trim( $eachString);
  249. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  250. $eachString= str_replace("&nbsp;","", $eachString);
  251. $WordsArr = explode(" ", $eachString);
  252. foreach ($WordsArr as $eachWord){
  253. $_allKeywords[] = trim($eachWord);
  254. }
  255. }
  256. // for each search field block end
  257. return array_unique($_allKeywords);
  258. }// get all keywords
  259. public function search($requestArray){
  260. $sql = "";
  261. $DBH=$this->connection;
  262. if( isset($requestArray['byTitle']) && isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='0' AND (`name` LIKE '%".$requestArray['search']."%' OR `birthday` LIKE '%".$requestArray['search']."%')";
  263. if(isset($requestArray['byTitle']) && !isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='0' AND `name` LIKE '%".$requestArray['search']."%'";
  264. if(!isset($requestArray['byTitle']) && isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='0' AND `birthday` LIKE '%".$requestArray['search']."%'";
  265. $STH = $DBH->query($sql);
  266. $STH->setFetchMode(PDO::FETCH_ASSOC);
  267. $allData = $STH->fetchAll();
  268. return $allData;
  269. }// end of search()
  270. }