PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/BITM/SEIP136344/SummaryOfOrganization/SummaryOfOrganization.php

https://gitlab.com/Charlesbasis/AtomicProject_CharlesValerioHowlader_136344_B35
PHP | 282 lines | 163 code | 112 blank | 7 comment | 13 complexity | 76ce2c82bff0c44db2c8dc1ad794b847 MD5 | raw file
  1. <?php
  2. namespace App\SummaryOfOrganization;
  3. use App\Message\Message;
  4. use App\Model\Database as DB;
  5. use App\Utility\Utility;
  6. use PDO;
  7. class SummaryOfOrganization extends DB{
  8. public $id="";
  9. public $company_name="";
  10. public $summary="";
  11. public function __construct(){
  12. parent::__construct();
  13. }
  14. // public function index(){
  15. // echo "SummaryOfOrganization found!";
  16. // }
  17. public function setData($postVariabledata=NULL){
  18. if(array_key_exists('id',$postVariabledata)){
  19. $this->id = $postVariabledata['id'];
  20. }
  21. if(array_key_exists('company_name',$postVariabledata)){
  22. $this->company_name = $postVariabledata['company_name'];
  23. }
  24. if(array_key_exists('summary',$postVariabledata)){
  25. $this->summary = $postVariabledata['summary'];
  26. }
  27. }
  28. public function store(){
  29. $arrData = array($this->company_name, $this->summary);
  30. $sql = "Insert INTO summary_of_organization(company_name,summary) VALUES(?,?)";
  31. $STH = $this->DBH->prepare($sql);
  32. $result = $STH->execute($arrData);
  33. if($result)
  34. Message::message("Success! Data Has Been Inserted Successfully! :)");
  35. else
  36. Message::message("Failed! Data Has Not Been Inserted! :(");
  37. Utility::redirect('create.php');
  38. } //end of store method
  39. public function index($fetchMode='ASSOC'){
  40. $STH = $this->DBH->query("SELECT * from summary_of_organization where is_deleted = 'No'");
  41. $fetchMode = strtoupper($fetchMode);
  42. if(substr_count($fetchMode,'OBJ') > 0)
  43. $STH->setFetchMode(PDO::FETCH_OBJ);
  44. else
  45. $STH->setFetchMode(PDO::FETCH_ASSOC);
  46. $arrAllData = $STH->fetchAll();
  47. return $arrAllData;
  48. }// end of index();
  49. public function view($fetchMode='ASSOC'){
  50. $STH = $this->DBH->query('SELECT * from summary_of_organization where id='.$this->id);
  51. $fetchMode = strtoupper($fetchMode);
  52. if(substr_count($fetchMode,'OBJ') > 0)
  53. $STH->setFetchMode(PDO::FETCH_OBJ);
  54. else
  55. $STH->setFetchMode(PDO::FETCH_ASSOC);
  56. $arrOneData = $STH->fetch();
  57. return $arrOneData;
  58. }// end of index();
  59. public function update(){
  60. $arrData= array($this->company_name,$this->summary);
  61. $sql="UPDATE summary_of_organization SET company_name = ?, summary = ? WHERE id =".$this->id;
  62. $STH = $this->DBH->prepare($sql);
  63. $STH->execute($arrData);
  64. Utility::redirect('index.php');
  65. } //end of update()
  66. public function delete(){
  67. $sql= "DELETE FROM summary_of_organization WHERE id =".$this->id;
  68. $STH= $this->DBH->prepare($sql);
  69. $STH->execute();
  70. Utility::redirect('index.php');
  71. } // end of delete(), permanent delete
  72. public function trash(){
  73. $sql = "Update summary_of_organization SET is_deleted=NOW() where id=".$this->id;
  74. $STH = $this->DBH->prepare($sql);
  75. $STH->execute();
  76. Utility::redirect('index.php');
  77. }// end of trash()
  78. public function trashed($fetchMode='ASSOC'){
  79. $sql = "SELECT * from summary_of_organization where is_deleted <> 'No' ";
  80. $STH = $this->DBH->query($sql);
  81. $fetchMode = strtoupper($fetchMode);
  82. if(substr_count($fetchMode,'OBJ') > 0)
  83. $STH->setFetchMode(PDO::FETCH_OBJ);
  84. else
  85. $STH->setFetchMode(PDO::FETCH_ASSOC);
  86. $arrAllData = $STH->fetchAll();
  87. return $arrAllData;
  88. }// end of trashed()
  89. public function recover(){
  90. $sql = "Update summary_of_organization SET is_deleted='No' where id=".$this->id;
  91. $STH = $this->DBH->prepare($sql);
  92. $STH->execute();
  93. Utility::redirect('index.php');
  94. }// end of recover()
  95. public function indexPaginator($page=1,$itemsPerPage=3){
  96. $start = (($page-1) * $itemsPerPage);
  97. $sql = "SELECT * from summary_of_organization WHERE is_deleted = 'No' LIMIT $start,$itemsPerPage";
  98. $STH = $this->DBH->query($sql);
  99. $STH->setFetchMode(PDO::FETCH_OBJ);
  100. $arrSomeData = $STH->fetchAll();
  101. return $arrSomeData;
  102. }// end of indexPaginator();
  103. public function trashedPaginator($page=0,$itemsPerPage=3){
  104. $start = (($page-1) * $itemsPerPage);
  105. $sql = "SELECT * from summary_of_organization WHERE is_deleted <> 'No' LIMIT $start,$itemsPerPage";
  106. $STH = $this->DBH->query($sql);
  107. $STH->setFetchMode(PDO::FETCH_OBJ);
  108. $arrSomeData = $STH->fetchAll();
  109. return $arrSomeData;
  110. }// end of trashedPaginator();
  111. public function search($requestArray){
  112. $sql = "";
  113. if( isset($requestArray['byName']) && isset($requestArray['bySummaryOfOrganizations']) ) $sql = "SELECT * FROM `summary_of_organization` WHERE `is_deleted` ='No' AND (`company_name` LIKE '%".$requestArray['search']."%' OR `summary` LIKE '%".$requestArray['search']."%')";
  114. if(isset($requestArray['byName']) && !isset($requestArray['bySummaryOfOrganizations']) ) $sql = "SELECT * FROM `summary_of_organization` WHERE `is_deleted` ='No' AND `company_name` LIKE '%".$requestArray['search']."%'";
  115. if(!isset($requestArray['byName']) && isset($requestArray['bySummaryOfOrganizations']) ) $sql = "SELECT * FROM `summary_of_organization` WHERE `is_deleted` ='No' AND `summary` LIKE '%".$requestArray['search']."%'";
  116. $STH = $this->DBH->query($sql);
  117. $STH->setFetchMode(PDO::FETCH_OBJ);
  118. $allData = $STH->fetchAll();
  119. return $allData;
  120. }// end of search()
  121. public function getAllKeywords()
  122. {
  123. $_allKeywords = array();
  124. $WordsArr = array();
  125. $sql = "SELECT * FROM `summary_of_organization` WHERE `is_deleted` ='No'";
  126. $STH = $this->DBH->query($sql);
  127. $STH->setFetchMode(PDO::FETCH_OBJ);
  128. // for each search field block start
  129. $allData= $STH->fetchAll();
  130. foreach ($allData as $oneData) {
  131. $_allKeywords[] = trim($oneData->company_name);
  132. }
  133. $STH = $this->DBH->query($sql);
  134. $STH->setFetchMode(PDO::FETCH_OBJ);
  135. $allData= $STH->fetchAll();
  136. foreach ($allData as $oneData) {
  137. $eachString= strip_tags($oneData->company_name);
  138. $eachString=trim( $eachString);
  139. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  140. $eachString= str_replace("&nbsp;","", $eachString);
  141. $WordsArr = explode(" ", $eachString);
  142. foreach ($WordsArr as $eachWord){
  143. $_allKeywords[] = trim($eachWord);
  144. }
  145. }
  146. // for each search field block end
  147. // for each search field block start
  148. $STH = $this->DBH->query($sql);
  149. $STH->setFetchMode(PDO::FETCH_OBJ);
  150. $allData= $STH->fetchAll();
  151. foreach ($allData as $oneData) {
  152. $_allKeywords[] = trim($oneData->summary);
  153. }
  154. $STH = $this->DBH->query($sql);
  155. $STH->setFetchMode(PDO::FETCH_OBJ);
  156. $allData= $STH->fetchAll();
  157. foreach ($allData as $oneData) {
  158. $eachString= strip_tags($oneData->summary);
  159. $eachString=trim( $eachString);
  160. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  161. $eachString= str_replace("&nbsp;","", $eachString);
  162. $WordsArr = explode(" ", $eachString);
  163. foreach ($WordsArr as $eachWord){
  164. $_allKeywords[] = trim($eachWord);
  165. }
  166. }
  167. // for each search field block end
  168. return array_unique($_allKeywords);
  169. }// end of get all keywords
  170. }