PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIP148423/ProfilePicture/ProfilePicture.php

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