/src/BITM/SEIP136344/Birthday/Birthday.php
https://gitlab.com/Charlesbasis/AtomicProject_CharlesValerioHowlader_136344_B35 · PHP · 273 lines · 164 code · 102 blank · 7 comment · 13 complexity · 966fd63cfbe88c5422d5cfc9fa906957 MD5 · raw file
- <?php
- namespace App\Birthday;
- use App\Message\Message;
- use App\Model\Database as DB;
- use App\Utility\Utility;
- use PDO;
- class Birthday extends DB{
- public $id="";
- public $name="";
- public $birthday="";
- public function __construct(){
- parent::__construct();
- }
- // public function index(){
- // echo "Birthday found!";
- // }
- public function setData($postVariabledata=NULL){
- if(array_key_exists('id',$postVariabledata)){
- $this->id = $postVariabledata['id'];
- }
- if(array_key_exists('name',$postVariabledata)){
- $this->name = $postVariabledata['name'];
- }
- if(array_key_exists('birthday',$postVariabledata)){
- $this->birthday = $postVariabledata['birthday'];
- }
- }
- public function store(){
- $arrData = array($this->name, $this->birthday);
- $sql = "Insert INTO birthday(name, birthday) 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! :(");
- 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->name,$this->birthday);
- $sql="UPDATE birthday SET name = ?, birthday = ? 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 birthday WHERE id =".$this->id;
- $STH= $this->DBH->prepare($sql);
- $STH->execute();
- Utility::redirect('index.php');
- } // end of delete(), permanent delete
- public function trash(){
- $sql="UPDATE birthday SET is_deleted=now() WHERE id =".$this->id;
- $STH = $this->DBH->prepare($sql);
- $STH->execute($arrData);
- Utility::redirect('index.php');
- }//end of trash()
- 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;
- }// end of trashed()
- public function recover(){
- $sql = "Update birthday 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=1,$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['byName']) && isset($requestArray['byBirthday']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND (`name` LIKE '%".$requestArray['search']."%' OR `birthday` LIKE '%".$requestArray['search']."%')";
- if(isset($requestArray['byName']) && !isset($requestArray['byBirthday']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND `name` LIKE '%".$requestArray['search']."%'";
- if(!isset($requestArray['byName']) && isset($requestArray['byBirthday']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND `birthday` 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->name);
- }
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $allData= $STH->fetchAll();
- foreach ($allData as $oneData) {
- $eachString= strip_tags($oneData->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
- // 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->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
- return array_unique($_allKeywords);
- }// end of get all keywords
- }
- ?>