/src/BITM/SEIP142691/Birthday/Birthday.php
https://gitlab.com/istiyakaminsanto/Atomic_project_IstiyakAmin_142691_B35 · PHP · 283 lines · 166 code · 113 blank · 4 comment · 14 complexity · 248026483eea67b39fea927b77d9c2bc MD5 · raw file
- <?php
- namespace App\Birthday;
- use PDO;
- use PDOException;
- use App\Message\Message;
- use App\Utility\Utility;
- use App\Model\Database as DB;
- class Birthday extends DB{
- public $id="";
- public $birthday="";
- 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('birthday',$postVariableData)){
- $this->birthday = $postVariableData['birthday'];
- }
- if(array_key_exists('author_name',$postVariableData)){
- $this->author_name = $postVariableData['author_name'];
- }
- }
- public function store(){
- $arrData = array( $this->birthday, $this->author_name);
- $sql = "Insert INTO birthday(birthday, author_name) VALUES (?,?)";
- $STH = $this->DBH->prepare($sql);
- $result = $STH->execute($arrData);
- if($result)
- Message::message("<h3>Success! Data Has Been Inserted Successfully :)</h3>");
- else
- Message::message("<h3>Failed! Data Has Not Been Inserted Successfully :( </h3>");
- Utility::redirect('create.php');
- }// end of store method
- public function index($fetchMode='ASSOC'){
- $STH = $this->DBH->query('SELECT * from birthday 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 birthday 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->birthday, $this->author_name);
- $sql = "UPDATE birthday SET birthday = ?, author_name = ? WHERE id =".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute($arrData);
- Utility::redirect('index.php');
- }
- public function delete(){
- $sql = "Delete from birthday where id=".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute();
- Utility::redirect('index.php');
- }
- public function softDelete(){
- $sql = "Update birthday SET is_deleted=NOW() where id=".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute();
- Utility::redirect('index.php');
- }
- public function trashed($fetchMode='ASSOC'){
- $sql = "SELECT * from birthday 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;
- }
- public function recover(){
- $sql = "Update birthday SET is_deleted='No' where id=".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute();
- Utility::redirect('trash.php');
- }
- public function indexPaginator($page=0,$itemsPerPage=3){
- $start = (($page-1) * $itemsPerPage);
- $sql = "SELECT * from birthday 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 birthday 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 `birthday` WHERE `is_deleted` ='No' AND (`birthday` LIKE '%".$requestArray['search']."%' OR `author_name` LIKE '%".$requestArray['search']."%')";
- if(isset($requestArray['byTitle']) && !isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND `birthday` LIKE '%".$requestArray['search']."%'";
- if(!isset($requestArray['byTitle']) && isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `birthday` 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 `birthday` 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->birthday);
- }
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $allData= $STH->fetchAll();
- foreach ($allData as $oneData) {
- $eachString= strip_tags($oneData->birthday);
- $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
- }
- ?>