PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/src/BITM/SEIP141617/Hobbies/Hobbies.php

https://gitlab.com/dhimanbarua/Atomic_Project_SEIP141617_B36
PHP | 204 lines | 138 code | 62 blank | 4 comment | 10 complexity | fa2c145cb97263d03432ba6b6d8eed94 MD5 | raw file
  1. <?php
  2. namespace App\Hobbies;
  3. use App\Model\Database as DB;
  4. use App\Message\Message;
  5. use App\Utility\Utility;
  6. use PDO;
  7. class Hobbies extends DB
  8. {
  9. public $id="";
  10. public $name="";
  11. public $hobbies="";
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. public function setData($data=NULL)
  17. {
  18. if(array_key_exists('id',$data))
  19. {
  20. $this->id= $data['id'];
  21. }
  22. if(array_key_exists('name',$data))
  23. {
  24. $this->name= $data['name'];
  25. }
  26. if(array_key_exists('hobbies',$data))
  27. {
  28. $this->hobbies = $data['hobbies'];
  29. }
  30. }
  31. public function store()
  32. {
  33. $arrData = array($this->name,$this->hobbies);
  34. $conn=$this->DBH;
  35. $STH=$conn->prepare("INSERT INTO hobbies(name,hobbies) VALUES(?,?) ");
  36. $STH->execute($arrData);
  37. if($STH)
  38. {
  39. Message::message("<div id='msg'><h3 align='center'>[User Name: $this->name],[Hobbie:$this->hobbies]
  40. <br>Data Has been Inserted Successfully!!!!!!</h3></div> ");
  41. }
  42. else
  43. {
  44. Message::message("<div id='msg'><h3 align='center'>>[User Name: $this->name],[Hobbie:$this->hobbies]
  45. <br>Data Has Not been Inserted Successfully!!!!!!</h3> </div>");
  46. }
  47. Utility::redirect('create.php');
  48. }
  49. public function index(){
  50. $STH = $this->DBH->query("SELECT * from hobbies where is_deleted='No' ORDER BY hobbies DESC");
  51. $STH->setFetchMode(PDO::FETCH_OBJ);
  52. $arrAllData = $STH->fetchAll();
  53. return $arrAllData;
  54. }// end of index();
  55. public function view(){
  56. $sql = 'SELECT * FROM hobbies WHERE id='.$this->id;
  57. $STH = $this->DBH->query($sql);
  58. $STH->setFetchMode(PDO::FETCH_OBJ);
  59. $arrOneData = $STH->fetch();
  60. return $arrOneData;
  61. }// end of view();
  62. public function update(){
  63. $arrData = array ($this->name, $this->hobbies);
  64. $sql = "UPDATE hobbies SET name = ?, hobbies = ? WHERE id =".$this->id;
  65. $STH = $this->DBH->prepare($sql);
  66. $STH->execute($arrData);
  67. Utility::redirect('index.php');
  68. }// end of update()
  69. public function delete(){
  70. $sql = "DELETE FROM hobbies WHERE id =".$this->id;
  71. $STH = $this->DBH->prepare($sql);
  72. $STH->execute();
  73. Utility::redirect('index.php');
  74. }// end of delete
  75. public function trash(){
  76. $sql = "UPDATE hobbies SET is_deleted=NOW() WHERE id=".$this->id;
  77. $STH = $this->DBH->prepare($sql);
  78. $STH->execute();
  79. Utility::redirect('index.php');
  80. }// end of trash
  81. public function indexPaginator($page=1,$itemsPerPage=3){
  82. $start = (($page-1) * $itemsPerPage);
  83. $sql = "SELECT * FROM hobbies WHERE is_deleted = 'No' LIMIT $start,$itemsPerPage";
  84. $STH = $this->DBH->query($sql);
  85. $STH->setFetchMode(PDO::FETCH_OBJ);
  86. $arrSomeData = $STH->fetchAll();
  87. return $arrSomeData;
  88. }// end of indexPaginator();
  89. public function search($requestArray){
  90. $sql = "";
  91. if( isset($requestArray['byName']) && isset($requestArray['byHobbies']) ) $sql = "SELECT * FROM `hobbies` WHERE `is_deleted` ='No' AND (`name` LIKE '%".$requestArray['search']."%' OR `hobbies` LIKE '%".$requestArray['search']."%')";
  92. if(isset($requestArray['byName']) && !isset($requestArray['byHobbies']) ) $sql = "SELECT * FROM `hobbies` WHERE `is_deleted` ='No' AND `name` LIKE '%".$requestArray['search']."%'";
  93. if(!isset($requestArray['byName']) && isset($requestArray['byHobbies']) ) $sql = "SELECT * FROM `hobbies` WHERE `is_deleted` ='No' AND `hobbies` LIKE '%".$requestArray['search']."%'";
  94. $STH = $this->DBH->query($sql);
  95. $STH->setFetchMode(PDO::FETCH_OBJ);
  96. $allData = $STH->fetchAll();
  97. return $allData;
  98. }// end of search()
  99. public function getAllKeywords()
  100. {
  101. $_allKeywords = array();
  102. $WordsArr = array();
  103. $sql = "SELECT * FROM `hobbies` WHERE `is_deleted` ='No'";
  104. $STH = $this->DBH->query($sql);
  105. $STH->setFetchMode(PDO::FETCH_OBJ);
  106. // for each search field block start
  107. $allData= $STH->fetchAll();
  108. foreach ($allData as $oneData) {
  109. $_allKeywords[] = trim($oneData->name);
  110. }
  111. foreach ($allData as $oneData) {
  112. $eachString= strip_tags($oneData->name);
  113. $eachString=trim( $eachString);
  114. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  115. $eachString= str_replace("&nbsp;","", $eachString);
  116. $WordsArr = explode(" ", $eachString);
  117. foreach ($WordsArr as $eachWord){
  118. $_allKeywords[] = trim($eachWord);
  119. }
  120. }
  121. // for each search field block end
  122. // for each search field block start
  123. $STH = $this->DBH->query($sql);
  124. $STH->setFetchMode(PDO::FETCH_OBJ);
  125. $allData= $STH->fetchAll();
  126. foreach ($allData as $oneData) {
  127. $_allKeywords[] = trim($oneData->hobbies);
  128. }
  129. foreach ($allData as $oneData) {
  130. $eachString= strip_tags($oneData->hobbies);
  131. $eachString=trim( $eachString);
  132. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  133. $eachString= str_replace("&nbsp;","", $eachString);
  134. $WordsArr = explode(" ", $eachString);
  135. foreach ($WordsArr as $eachWord){
  136. $_allKeywords[] = trim($eachWord);
  137. }
  138. }
  139. // for each search field block end
  140. return array_unique($_allKeywords);
  141. }// get all keywords
  142. }