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

/src/BITM/SEIP143979/ProfilePicture/ProfilePicture.php

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