/src/BITM/SEIP148423/Birthday/Birthday.php
https://gitlab.com/Afsana/Afsana_148423_B35_Session_31 · PHP · 282 lines · 164 code · 104 blank · 14 comment · 13 complexity · 566c346e2ed58bc96bfdd6a3d112d78c 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 $birth_date="";
- public function __construct()
- {
- parent::__construct();
- }
- /*
- public function index(){
- echo "<br>".$this->id."<br>";
- echo $this->name."<br>";
- echo $this->birthDate."<br>";
- }
- */
- public function setData($data=NULL){
- if(array_key_exists('id',$data)){
- $this->id=$data['id'];
- }
- if(array_key_exists('name',$data)){
- $this->name=$data['name'];
- }
- if(array_key_exists('birth_date',$data)){
- $this->birth_date=$data['birth_date'];
- }
- }
- public function store(){
- $arrData=array($this->name, $this->birth_date);
- $sql="INSERT INTO Birthday (name,birth_date) 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 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->birth_date);
- $sql = "UPDATE birthday SET name = ?, birth_date = ? 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()
- public function trash(){
- $sql = "Update birthday 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 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=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['byName']) && isset($requestArray['byBirthDate']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND (`name` LIKE '%".$requestArray['search']."%' OR `birth_date` LIKE '%".$requestArray['search']."%')";
- if(isset($requestArray['byName']) && !isset($requestArray['byBirthDate']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND `name` LIKE '%".$requestArray['search']."%'";
- if(!isset($requestArray['byName']) && isset($requestArray['byBirthDate']) ) $sql = "SELECT * FROM `birthday` WHERE `is_deleted` ='No' AND `birth_date` LIKE '%".$requestArray['search']."%'";
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $someData = $STH->fetchAll();
- return $someData;
- }// 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->birth_date);
- }
- $STH = $this->DBH->query($sql);
- $STH->setFetchMode(PDO::FETCH_OBJ);
- $allData= $STH->fetchAll();
- foreach ($allData as $oneData) {
- $eachString= strip_tags($oneData->birth_date);
- $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 Birthday();
- //$objBirthday = new Birthday();
- ?>