PageRenderTime 32ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIP143203/BookTitle/Booktitle.php

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