PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIP123456/BookTitle/BookTitle.php

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