/src/BITM/SEIP141617/ProfilePicture/ProfilePicture.php

https://gitlab.com/dhimanbarua/Atomic_Project_SEIP141617_B36 · PHP · 171 lines · 121 code · 47 blank · 3 comment · 6 complexity · bdd83d832f8f51b6e6de7d69b751be96 MD5 · raw file

  1. <?php
  2. namespace App\ProfilePicture;
  3. use App\Model\Database as DB;
  4. use App\Message\Message;
  5. use App\Utility\Utility;
  6. use PDO;
  7. class ProfilePicture extends DB
  8. {
  9. public $id="";
  10. public $name="";
  11. public $profilePicture="";
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. //echo "Hello";
  16. }
  17. public function setData($data=NULL)
  18. {
  19. if(array_key_exists('id',$data))
  20. {
  21. $this->id = $data['id'];
  22. }
  23. if(array_key_exists('name',$data))
  24. {
  25. $this->name= $data['name'];
  26. }
  27. if(array_key_exists('profilePicture',$data))
  28. {
  29. $this->profilePicture = $data['profilePicture'];
  30. }
  31. }
  32. public function store()
  33. {
  34. $arrData = array($this->name,$this->profilePicture);
  35. $conn=$this->DBH;
  36. $STH=$conn->prepare("INSERT INTO profilepic(name,profilePicture) VALUES(?,?) ");
  37. $STH->execute($arrData);
  38. if($STH)
  39. {
  40. Message::message("<div id='msg'><h3 align='center'>[User Name: $this->name],[Profile Picture:$this->profilePicture]
  41. <br>Data Has been Inserted Successfully!!!!!!</h3></div> ");
  42. }
  43. else
  44. {
  45. Message::message("<div id='msg'><h3 align='center'>>[User Name: $this->name],[Profile Picture:$this->profilePicture]
  46. <br>Data Has Not been Inserted Successfully!!!!!!</h3></div> ");
  47. }
  48. Utility::redirect('create.php');
  49. }
  50. public function index(){
  51. $STH = $this->DBH->query("SELECT * FROM profilepic WHERE is_deleted='No'");
  52. $STH->setFetchMode(PDO::FETCH_OBJ);
  53. $arrAllData = $STH->fetchAll();
  54. return $arrAllData;
  55. }
  56. public function view(){
  57. $sql = 'SELECT * FROM profilepic WHERE id='.$this->id;
  58. $STH = $this->DBH->query($sql);
  59. $STH->setFetchMode(PDO::FETCH_OBJ);
  60. $arrOneData = $STH->fetch();
  61. return $arrOneData;
  62. }// end of view();
  63. public function update(){
  64. $arrData = array($this->name, $this->profilePicture);
  65. $sql = "UPDATE profilepic SET name = ?, profilePicture = ? WHERE id =".$this->id;
  66. $STH = $this->DBH->prepare($sql);
  67. $STH->execute($arrData);
  68. Utility::redirect('index.php');
  69. }// end of update()
  70. public function delete(){
  71. $sql = "DELETE FROM profilePic WHERE id =".$this->id;
  72. $STH = $this->DBH->prepare($sql);
  73. $STH->execute();
  74. Utility::redirect('index.php');
  75. }// end of delete
  76. public function trash(){
  77. $sql = "UPDATE profilepic SET is_deleted=NOW() WHERE id=".$this->id;
  78. $STH = $this->DBH->prepare($sql);
  79. $STH->execute();
  80. Utility::redirect('index.php');
  81. }// end of trash
  82. public function indexPaginator($page=1,$itemsPerPage=3){
  83. $start = (($page-1) * $itemsPerPage);
  84. $sql = "SELECT * FROM profilePic WHERE is_deleted = 'No' LIMIT $start,$itemsPerPage";
  85. $STH = $this->DBH->query($sql);
  86. $STH->setFetchMode(PDO::FETCH_OBJ);
  87. $arrSomeData = $STH->fetchAll();
  88. return $arrSomeData;
  89. }// end of indexPaginator();
  90. public function search($requestArray){
  91. $sql = "";
  92. if( isset($requestArray['byName'])) $sql = "SELECT * FROM `profilePic` WHERE `is_deleted` ='No' AND (`name` LIKE '%".$requestArray['search']."%'";
  93. if(isset($requestArray['byName'])) $sql = "SELECT * FROM `profilePic` WHERE `is_deleted` ='No' AND `name` 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 `profilePic` 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. return array_unique($_allKeywords);
  123. }// get all keywords
  124. }