PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIP_141176/Profile_Picture/Profile_Picture.php

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