/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
- <?php
- namespace App\BookTitle;
- use App\Message\Message;
- use App\Model\Database as DB;
- use App\Utility\Utility;
- use PDO;
- class BookTitle extends DB{
- public $id="";
- public $book_title="";
- public $author_name="";
- public function __construct()
- {
- parent::__construct();
- }
- /*
- public function index(){
- echo $this->id."<br>";
- echo $this->book_title."<br>";
- echo $this->author_name."<br>";
- }
- */
- public function setData($data=NULL){
- if(array_key_exists('id',$data)){
- $this->id=$data['id'];
- }
- if(array_key_exists('book_title',$data)){
- $this->book_title=$data['book_title'];
- }
- if(array_key_exists('author_name',$data)){
- $this->author_name=$data['author_name'];
- }
- }
- public function store(){
- $arrData=array($this->book_title, $this->author_name);
- $sql="INSERT INTO book_title (book_title,author_name) VALUES (?,?)";
- $STH=$this->DBH->prepare($sql);
- $result=$STH->execute($arrData);
- if ($result)
- Message::message("Success! Data Has Been Inserted Successfully :)");
- else
- Message::message("Failed! Data Has Not Been Inserted Successfully :(");
- Utility::redirect('create.php'); // redirect korte hobe create.php te tai utility.php use korechi //
- }//end of store method
- public function index($fetchMode='ASSOC'){
- $STH = $this->DBH->query("SELECT * from book_title where is_deleted='No'");
- $fetchMode = strtoupper($fetchMode);
- if(substr_count($fetchMode,'OBJ') > 0)
- $STH->setFetchMode(PDO::FETCH_OBJ);
- else
- $STH->setFetchMode(PDO::FETCH_ASSOC);
- $arrAllData = $STH->fetchAll();
- return $arrAllData;
- }// end of index();
- public function view($fetchMode='ASSOC'){
- $STH = $this->DBH->query('SELECT * from book_title where id='.$this->id);
- $fetchMode = strtoupper($fetchMode);
- if(substr_count($fetchMode,'OBJ') > 0)
- $STH->setFetchMode(PDO::FETCH_OBJ);
- else
- $STH->setFetchMode(PDO::FETCH_ASSOC);
- $arrOneData = $STH->fetch();
- return $arrOneData;
- }// end of view();
- public function update(){
- $arrData = array ($this->book_title, $this->author_name);
- $sql = "UPDATE book_title SET book_title = ?, author_name = ? WHERE id =".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute($arrData);
- Utility::redirect('index.php');
- }// end of update()
- public function delete(){
- $sql = "Delete from book_title where id=".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute();
- Utility::redirect('index.php');
- }// end of delete()
- public function trash(){
- $sql = "Update book_title SET is_deleted=NOW() where id=".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute();
- Utility::redirect('index.php');
- }// end of trash()
- public function trashed($fetchMode='ASSOC'){
- $sql = "SELECT * from book_title where is_deleted <> 'No' ";
- $STH = $this->DBH->query($sql);
- $fetchMode = strtoupper($fetchMode);
- if(substr_count($fetchMode,'OBJ') > 0)
- $STH->setFetchMode(PDO::FETCH_OBJ);
- else
- $STH->setFetchMode(PDO::FETCH_ASSOC);
- $arrAllData = $STH->fetchAll();
- return $arrAllData;
- }// end of trashed();
- public function recover(){
- $sql = "Update book_title SET is_deleted='No' where id=".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute();
- Utility::redirect('index.php');
- }// end of recover();
- public function indexPaginator($page=0,$itemsPerPage=3){
- $start = (($page-1) * $itemsPerPage);
- $sql = "SELECT * from book_title WHERE is_deleted = 'No' LIMIT $start,$itemsPerPage";
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $arrSomeData = $STH->fetchAll();
- return $arrSomeData;
- }// end of indexPaginator();
- public function trashedPaginator($page=0,$itemsPerPage=3){
- $start = (($page-1) * $itemsPerPage);
- $sql = "SELECT * from book_title WHERE is_deleted <> 'No' LIMIT $start,$itemsPerPage";
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $arrSomeData = $STH->fetchAll();
- return $arrSomeData;
- }// end of trashedPaginator();
- }//end of booktitle table
- //$objBooktitle = new Booktitle();
- ?>