PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIP148423/BookTitle/BookTitle.php

https://gitlab.com/Afsana/Afsana_148423_B35_Session_29
PHP | 201 lines | 110 code | 81 blank | 10 comment | 7 complexity | 4a0d53c05354195a159861c97a78d750 MD5 | raw file
  1. <?php
  2. namespace App\BookTitle;
  3. use App\Message\Message;
  4. use App\Model\Database as DB;
  5. use App\Utility\Utility;
  6. use PDO;
  7. class BookTitle extends DB{
  8. public $id="";
  9. public $book_title="";
  10. public $author_name="";
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. /*
  16. public function index(){
  17. echo $this->id."<br>";
  18. echo $this->book_title."<br>";
  19. echo $this->author_name."<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('book_title',$data)){
  27. $this->book_title=$data['book_title'];
  28. }
  29. if(array_key_exists('author_name',$data)){
  30. $this->author_name=$data['author_name'];
  31. }
  32. }
  33. public function store(){
  34. $arrData=array($this->book_title, $this->author_name);
  35. $sql="INSERT INTO book_title (book_title,author_name) VALUES (?,?)";
  36. $STH=$this->DBH->prepare($sql);
  37. $result=$STH->execute($arrData);
  38. if ($result)
  39. Message::message("Success! Data Has Been Inserted Successfully :)");
  40. else
  41. Message::message("Failed! Data Has Not Been Inserted Successfully :(");
  42. Utility::redirect('create.php'); // redirect korte hobe create.php te tai utility.php use korechi //
  43. }//end of store method
  44. public function index($fetchMode='ASSOC'){
  45. $STH = $this->DBH->query("SELECT * from book_title where is_deleted='No'");
  46. $fetchMode = strtoupper($fetchMode);
  47. if(substr_count($fetchMode,'OBJ') > 0)
  48. $STH->setFetchMode(PDO::FETCH_OBJ);
  49. else
  50. $STH->setFetchMode(PDO::FETCH_ASSOC);
  51. $arrAllData = $STH->fetchAll();
  52. return $arrAllData;
  53. }// end of index();
  54. public function view($fetchMode='ASSOC'){
  55. $STH = $this->DBH->query('SELECT * from book_title where id='.$this->id);
  56. $fetchMode = strtoupper($fetchMode);
  57. if(substr_count($fetchMode,'OBJ') > 0)
  58. $STH->setFetchMode(PDO::FETCH_OBJ);
  59. else
  60. $STH->setFetchMode(PDO::FETCH_ASSOC);
  61. $arrOneData = $STH->fetch();
  62. return $arrOneData;
  63. }// end of view();
  64. public function update(){
  65. $arrData = array ($this->book_title, $this->author_name);
  66. $sql = "UPDATE book_title SET book_title = ?, author_name = ? WHERE id =".$this->id;
  67. $STH = $this->DBH->prepare($sql);
  68. $STH->execute($arrData);
  69. Utility::redirect('index.php');
  70. }// end of update()
  71. public function delete(){
  72. $sql = "Delete from book_title where id=".$this->id;
  73. $STH = $this->DBH->prepare($sql);
  74. $STH->execute();
  75. Utility::redirect('index.php');
  76. }// end of delete()
  77. public function trash(){
  78. $sql = "Update book_title SET is_deleted=NOW() where id=".$this->id;
  79. $STH = $this->DBH->prepare($sql);
  80. $STH->execute();
  81. Utility::redirect('index.php');
  82. }// end of trash()
  83. public function trashed($fetchMode='ASSOC'){
  84. $sql = "SELECT * from book_title where is_deleted <> 'No' ";
  85. $STH = $this->DBH->query($sql);
  86. $fetchMode = strtoupper($fetchMode);
  87. if(substr_count($fetchMode,'OBJ') > 0)
  88. $STH->setFetchMode(PDO::FETCH_OBJ);
  89. else
  90. $STH->setFetchMode(PDO::FETCH_ASSOC);
  91. $arrAllData = $STH->fetchAll();
  92. return $arrAllData;
  93. }// end of trashed();
  94. public function recover(){
  95. $sql = "Update book_title SET is_deleted='No' where id=".$this->id;
  96. $STH = $this->DBH->prepare($sql);
  97. $STH->execute();
  98. Utility::redirect('index.php');
  99. }// end of recover();
  100. public function indexPaginator($page=0,$itemsPerPage=3){
  101. $start = (($page-1) * $itemsPerPage);
  102. $sql = "SELECT * from book_title WHERE is_deleted = 'No' LIMIT $start,$itemsPerPage";
  103. $STH = $this->DBH->query($sql);
  104. $STH->setFetchMode(PDO::FETCH_OBJ);
  105. $arrSomeData = $STH->fetchAll();
  106. return $arrSomeData;
  107. }// end of indexPaginator();
  108. public function trashedPaginator($page=0,$itemsPerPage=3){
  109. $start = (($page-1) * $itemsPerPage);
  110. $sql = "SELECT * from book_title WHERE is_deleted <> 'No' LIMIT $start,$itemsPerPage";
  111. $STH = $this->DBH->query($sql);
  112. $STH->setFetchMode(PDO::FETCH_OBJ);
  113. $arrSomeData = $STH->fetchAll();
  114. return $arrSomeData;
  115. }// end of trashedPaginator();
  116. }//end of booktitle table
  117. //$objBooktitle = new Booktitle();
  118. ?>