PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIP151534/SummaryofOrganization/SummaryofOrganization.php

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