/src/BITM/SEIP152207/SummaryOfOrganization/SummaryOfOrganization.php

https://gitlab.com/Soikot/AtomicProject_AmirulIslam_152207 · PHP · 404 lines · 305 code · 93 blank · 6 comment · 19 complexity · c8a10f9933149f6d5316fe75a4fe2ea5 MD5 · raw file

  1. <?php
  2. namespace App\BITM\SEIP152207\SummaryOfOrganization;
  3. use App\BITM\SEIP152207\Message\Message;
  4. use App\BITM\SEIP152207\Utility\Utility;
  5. use App\BITM\SEIP152207\Model\Database as DB;
  6. use PDO;
  7. class SummaryOfOrganization extends DB{
  8. public $id="";
  9. public $organization_name="";
  10. public $organization_summary="";
  11. public function __construct(){
  12. parent::__construct();
  13. }
  14. public function index($fetchMode='ASSOC'){
  15. $fetchMode = strtoupper($fetchMode);
  16. $DBH=$this->connection;
  17. $sth=$DBH->prepare("select * from summary_of_organization where is_deleted='0'");
  18. $sth->execute();
  19. if(substr_count($fetchMode,'OBJ') > 0)
  20. $sth->setFetchMode(PDO::FETCH_OBJ);
  21. else
  22. $sth->setFetchMode(PDO::FETCH_ASSOC);
  23. $all_organization=$sth->fetchAll();
  24. return $all_organization;
  25. }
  26. public function view($id){
  27. $DBH=$this->connection;
  28. $sth=$DBH->prepare("select * from summary_of_organization Where id=$id");
  29. $sth->execute();
  30. $sth->setFetchMode(PDO::FETCH_ASSOC);
  31. $selected_organization=$sth->fetch();
  32. return $selected_organization;
  33. }
  34. public function setData($data=null){
  35. if(array_key_exists('id',$data)){
  36. $this->id=$data['id'];
  37. }
  38. if(array_key_exists('organization_name',$data)){
  39. $this->organization_name=$data['organization_name'];
  40. }
  41. if(array_key_exists('organization_summary',$data)){
  42. $this->organization_summary=$data['organization_summary'];
  43. }
  44. }
  45. public function store(){
  46. $dbh=$this->connection;
  47. $values=array($this->organization_name,$this->organization_summary);
  48. $query="insert into summary_of_organization(organization_name,organization_summary) VALUES (?,?)";
  49. $sth=$dbh->prepare($query);
  50. $sth->execute($values);
  51. if($sth)
  52. Message::message("<div id='msg'><h3 align='center'>[ Organization name: $this->organization_name ] ,
  53. [ organization_summary: $this->organization_summary ] <br> Data Has Been Inserted Successfully!</h3></div>");
  54. else Message::message("<div id='msg'><h3 align='center'>[ Organization name: $this->organization_name ] ,
  55. [ organization_summary: $this->organization_summary ] <br> Data Hasn't Been Inserted Successfully!</h3></div>");
  56. Utility::redirect('create.php');
  57. }
  58. public function update(){
  59. $dbh=$this->connection;
  60. $values=array($this->organization_name,$this->organization_summary);
  61. //var_dump($values);
  62. $query='UPDATE summary_of_organization SET organization_name = ? , organization_summary = ? where id ='.$this->id;
  63. $sth=$dbh->prepare($query);
  64. $sth->execute($values);
  65. if($sth)
  66. { Message::message("<div id='msg'><h3 align='center'>[ Organization name: $this->organization_name ] ,
  67. [ Organization Summary:$this->organization_summary ] <br> Data Has Been Inserted Successfully!</h3></div>");
  68. }
  69. else
  70. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been Inserted !</h3></div>");
  71. Utility::redirect('index.php');
  72. }
  73. public function delete($id){
  74. $DBH=$this->connection;
  75. $sth=$DBH->prepare("delete from summary_of_organization Where id=$id");
  76. $sth->execute();
  77. if($sth)
  78. { Message::message("<div id='msg'><h3 align='center'>
  79. <br> Data Has deleted Successfully!</h3></div>");
  80. }
  81. else
  82. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been Inserted !</h3></div>");
  83. Utility::redirect('index.php');
  84. }
  85. public function trash($id){
  86. $dbh=$this->connection;
  87. //var_dump($values);
  88. $query='UPDATE summary_of_organization SET is_deleted = "1" where id ='.$id;
  89. $sth=$dbh->prepare($query);
  90. $sth->execute();
  91. if($sth)
  92. { Message::message("<div id='msg'><h3 align='center'>
  93. <br> Data Has Been trashed Successfully!</h3></div>");
  94. }
  95. else
  96. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been trashed !</h3></div>");
  97. Utility::redirect('index.php');
  98. }
  99. public function trashed($fetchMode='ASSOC'){
  100. $fetchMode = strtoupper($fetchMode);
  101. $DBH=$this->connection;
  102. $sth=$DBH->prepare("select * from summary_of_organization WHERE is_deleted='1'");
  103. $sth->execute();
  104. if(substr_count($fetchMode,'OBJ') > 0)
  105. $sth->setFetchMode(PDO::FETCH_OBJ);
  106. else
  107. $sth->setFetchMode(PDO::FETCH_ASSOC);
  108. $all_organization=$sth->fetchAll();
  109. return $all_organization;
  110. }
  111. public function recover($id){
  112. $dbh=$this->connection;
  113. //var_dump($values);
  114. $query='UPDATE summary_of_organization SET is_deleted = "0" where id ='.$id;
  115. $sth=$dbh->prepare($query);
  116. $sth->execute();
  117. if($sth)
  118. { Message::message("<div id='msg'><h3 align='center'>
  119. <br> Data Has Been recovered Successfully!</h3></div>");
  120. }
  121. else
  122. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been recovered !</h3></div>");
  123. Utility::redirect('index.php');
  124. }
  125. public function deleteMultiple($IDs = Array())
  126. {
  127. if ((is_array($IDs)) && (count($IDs > 0))) {
  128. $dbh=$this->connection;
  129. $n=count($IDs);
  130. // Utility::dd($IDs);
  131. for($i=0;$i<$n;$i++)
  132. {
  133. $query="delete from summary_of_organization Where id=$IDs[$i]";
  134. $sth=$dbh->prepare($query);
  135. $sth->execute();
  136. }
  137. if($sth)
  138. { Message::message("<div id='msg'><h3 align='center'>
  139. <br> Selected Data has been deleted Successfully!</h3></div>");
  140. }
  141. else
  142. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been recovered !</h3></div>");
  143. Utility::redirect('index.php');
  144. }
  145. }
  146. public function recoverMultiple($IDs = Array())
  147. {
  148. if ((is_array($IDs)) && (count($IDs > 0))) {
  149. $dbh=$this->connection;
  150. $n=count($IDs);
  151. // Utility::dd($IDs);
  152. for($i=0;$i<$n;$i++)
  153. {
  154. $query='UPDATE summary_of_organization SET is_deleted = "0" where id ='.$IDs["$i"];
  155. $sth=$dbh->prepare($query);
  156. $sth->execute();
  157. }
  158. if($sth)
  159. { Message::message("<div id='msg'><h3 align='center'>
  160. <br> Selected Data has been deleted Successfully!</h3></div>");
  161. }
  162. else
  163. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been recovered !</h3></div>");
  164. Utility::redirect('index.php');
  165. }
  166. }
  167. public function trashMultiple($IDs = Array())
  168. {
  169. if ((is_array($IDs)) && (count($IDs > 0))) {
  170. $dbh=$this->connection;
  171. $n=count($IDs);
  172. // Utility::dd($IDs);
  173. for($i=0;$i<$n;$i++)
  174. {
  175. $query='UPDATE summary_of_organization SET is_deleted = "1" where id ='.$IDs["$i"];
  176. $sth=$dbh->prepare($query);
  177. $sth->execute();
  178. }
  179. if($sth)
  180. { Message::message("<div id='msg'><h3 align='center'>
  181. <br> Selected Data has been Trashed Successfully!</h3></div>");
  182. }
  183. else
  184. Message::message("<div id='msg'></div><h3 align='center'> <br> Data Hasn't Been trashed !</h3></div>");
  185. Utility::redirect('index.php');
  186. }
  187. }
  188. public function indexPaginator($page=0,$itemsPerPage=3){
  189. $start = (($page-1) * $itemsPerPage);
  190. $DBH=$this->connection;
  191. $sth=$DBH->prepare("select * from summary_of_organization WHERE is_deleted='0' LIMIT $start,$itemsPerPage");
  192. $sth->execute();
  193. $sth->setFetchMode(PDO::FETCH_ASSOC);
  194. $arrSomeData = $sth->fetchAll();
  195. return $arrSomeData;
  196. }// end of indexPaginator();
  197. public function trashPaginator($page=0,$itemsPerPage=3){
  198. $start = (($page-1) * $itemsPerPage);
  199. $DBH=$this->connection;
  200. $sth=$DBH->prepare("select * from summary_of_organization WHERE is_deleted='1' LIMIT $start,$itemsPerPage");
  201. $sth->execute();
  202. $sth->setFetchMode(PDO::FETCH_ASSOC);
  203. $arrSomeData = $sth->fetchAll();
  204. return $arrSomeData;
  205. }// end of indexPaginator();
  206. public function getAllKeywords()
  207. {
  208. $_allKeywords = array();
  209. $WordsArr = array();
  210. $sql = "SELECT * FROM summary_of_organization WHERE is_deleted='0'";
  211. $DBH=$this->connection;
  212. $STH = $DBH->query($sql);
  213. $STH->setFetchMode(PDO::FETCH_ASSOC);
  214. // for each search field block start
  215. $allData= $STH->fetchAll();
  216. foreach ($allData as $oneData) {
  217. $_allKeywords[] = trim($oneData['organization_name']);
  218. }
  219. $STH = $DBH->query($sql);
  220. $STH->setFetchMode(PDO::FETCH_ASSOC);
  221. $allData= $STH->fetchAll();
  222. foreach ($allData as $oneData) {
  223. $eachString= strip_tags($oneData['organization_name']);
  224. $eachString=trim( $eachString);
  225. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  226. $eachString= str_replace("&nbsp;","", $eachString);
  227. $WordsArr = explode(" ", $eachString);
  228. foreach ($WordsArr as $eachWord){
  229. $_allKeywords[] = trim($eachWord);
  230. }
  231. }
  232. // for each search field block end
  233. // for each search field block start
  234. $STH = $DBH->query($sql);
  235. $STH->setFetchMode(PDO::FETCH_ASSOC);
  236. $allData= $STH->fetchAll();
  237. foreach ($allData as $oneData) {
  238. $_allKeywords[] = trim($oneData['organization_summary']);
  239. }
  240. $STH = $DBH->query($sql);
  241. $STH->setFetchMode(PDO::FETCH_ASSOC);
  242. $allData= $STH->fetchAll();
  243. foreach ($allData as $oneData) {
  244. $eachString= strip_tags($oneData['organization_summary']);
  245. $eachString=trim( $eachString);
  246. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  247. $eachString= str_replace("&nbsp;","", $eachString);
  248. $WordsArr = explode(" ", $eachString);
  249. foreach ($WordsArr as $eachWord){
  250. $_allKeywords[] = trim($eachWord);
  251. }
  252. }
  253. // for each search field block end
  254. return array_unique($_allKeywords);
  255. }// get all keywords
  256. public function search($requestArray){
  257. $sql = "";
  258. $DBH=$this->connection;
  259. if( isset($requestArray['byTitle']) && isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `summary_of_organization` WHERE `is_deleted` ='0' AND (`organization_name` LIKE '%".$requestArray['search']."%' OR `organization_summary` LIKE '%".$requestArray['search']."%')";
  260. if(isset($requestArray['byTitle']) && !isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `summary_of_organization` WHERE `is_deleted` ='0' AND `organization_name` LIKE '%".$requestArray['search']."%'";
  261. if(!isset($requestArray['byTitle']) && isset($requestArray['byAuthor']) ) $sql = "SELECT * FROM `summary_of_organization` WHERE `is_deleted` ='0' AND `organization_summary` LIKE '%".$requestArray['search']."%'";
  262. $STH = $DBH->query($sql);
  263. $STH->setFetchMode(PDO::FETCH_ASSOC);
  264. $allData = $STH->fetchAll();
  265. return $allData;
  266. }// end of search()
  267. }