/src/BITM/SEIP123456/BookTitle/BookTitle.php
https://gitlab.com/muhammadhasan/Hasan_143132_B35_Session29_Pagination · PHP · 294 lines · 167 code · 123 blank · 4 comment · 14 complexity · 5805b68036a425a9a38327c8fca4c7c1 MD5 · raw file
- <?php
- namespace App\BookTitle;
- use App\Message\Message;
- use App\Utility\Utility;
- use App\Model\Database as DB;
- use PDO;
- class BookTitle extends DB{
- public $id="";
- public $book_title="";
- public $author_name="";
- public function __construct(){
- parent:: __construct();
- if(!isset( $_SESSION)) session_start();
- }
- public function setData($postVariableData=NULL){
- if(array_key_exists('id',$postVariableData)){
- $this->id = $postVariableData['id'];
- }
- if(array_key_exists('book_title',$postVariableData)){
- $this->book_title = $postVariableData['book_title'];
- }
- if(array_key_exists('author_name',$postVariableData)){
- $this->author_name = $postVariableData['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');
- }// end of store method
- public function index($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 index();
- public function view($fetchMode='ASSOC'){
- $sql = 'SELECT * from book_title where id='.$this->id;
- $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);
- $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('trashed.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();
- public function search($requestArray){
- $sql = "";
- 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']."%')";
- if(isset($requestArray['byTitle']) && !isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `book_title` WHERE `is_deleted` ='No' AND `book_title` LIKE '%".$requestArray['search']."%'";
- if(!isset($requestArray['byTitle']) && isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `book_title` WHERE `is_deleted` ='No' AND `author_name` LIKE '%".$requestArray['search']."%'";
-
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $allData = $STH->fetchAll();
-
- return $allData;
- }// end of search()
- public function getAllKeywords()
- {
- $_allKeywords = array();
- $WordsArr = array();
- $sql = "SELECT * FROM `book_title` WHERE `is_deleted` ='No'";
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- // for each search field block start
- $allData= $STH->fetchAll();
- foreach ($allData as $oneData) {
- $_allKeywords[] = trim($oneData->book_title);
- }
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $allData= $STH->fetchAll();
- foreach ($allData as $oneData) {
- $eachString= strip_tags($oneData->book_title);
- $eachString=trim( $eachString);
- $eachString= preg_replace( "/\r|\n/", " ", $eachString);
- $eachString= str_replace(" ","", $eachString);
- $WordsArr = explode(" ", $eachString);
- foreach ($WordsArr as $eachWord){
- $_allKeywords[] = trim($eachWord);
- }
- }
- // for each search field block end
- // for each search field block start
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $allData= $STH->fetchAll();
- foreach ($allData as $oneData) {
- $_allKeywords[] = trim($oneData->author_name);
- }
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $allData= $STH->fetchAll();
- foreach ($allData as $oneData) {
- $eachString= strip_tags($oneData->author_name);
- $eachString=trim( $eachString);
- $eachString= preg_replace( "/\r|\n/", " ", $eachString);
- $eachString= str_replace(" ","", $eachString);
- $WordsArr = explode(" ", $eachString);
- foreach ($WordsArr as $eachWord){
- $_allKeywords[] = trim($eachWord);
- }
- }
- // for each search field block end
- return array_unique($_allKeywords);
- }// get all keywords
- }// end of BookTitle Class
- ?>