PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIP143979/SummaryOfOrganization/SummaryOfOrganization.php

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