PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/views/SEIP128330/Hobby/index.php

https://gitlab.com/shaon2016/day13
PHP | 213 lines | 163 code | 41 blank | 9 comment | 20 complexity | b482f8cc5898afb505d6fa088ddfaa9d MD5 | raw file
  1. <?php
  2. session_start();
  3. include_once("../../../vendor/autoload.php");
  4. use App\BITM\SEIP128330\Hobby\Hobby;
  5. use App\BITM\SEIP128330\Utility;
  6. use App\BITM\SEIP128330\Message;
  7. ////Creating object
  8. //$hobby = new Hobby();
  9. ////Getting DB data as object form
  10. //$getAllHobbyData = $hobby->index();
  11. //// Checking DB data
  12. ////Utility::dd($getAllHobbyData);
  13. $hobby= new Hobby();
  14. //Utility::d($allBook);
  15. if(array_key_exists('itemPerPage',$_SESSION)) {
  16. if (array_key_exists('itemPerPage', $_GET)) {
  17. $_SESSION['itemPerPage'] = $_GET['itemPerPage'];
  18. }
  19. }
  20. else{
  21. $_SESSION['itemPerPage']=5;
  22. }
  23. //Utility::dd($_SESSION['itemPerPage']);
  24. $itemPerPage=$_SESSION['itemPerPage'];
  25. $totalItem=$hobby->count();
  26. $totalPage=ceil($totalItem/$itemPerPage);
  27. //Utility::dd($itemPerPage);
  28. $pagination="";
  29. if(array_key_exists('pageNumber',$_GET)){
  30. $pageNumber=$_GET['pageNumber'];
  31. }else{
  32. $pageNumber=1;
  33. }
  34. for($i=1;$i<=$totalPage;$i++){
  35. $class=($pageNumber==$i)?"active":"";
  36. $pagination.="<li class='$class'><a href='index.php?pageNumber=$i'>$i</a></li>";
  37. }
  38. $pageStartFrom=$itemPerPage*($pageNumber-1);
  39. $getAllHobbyData=$hobby->paginator($pageStartFrom,$itemPerPage);
  40. ?>
  41. <!DOCTYPE html>
  42. <html lang="en">
  43. <head>
  44. <title>Hobby</title>
  45. <meta charset="utf-8">
  46. <meta name="viewport" content="width=device-width, initial-scale=1">
  47. <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  48. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  49. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  50. </head>
  51. <body>
  52. <div class="container">
  53. <h2>Hobby List</h2>
  54. <a href="create.php" class="btn btn-info" role="button">Create Again</a>
  55. <a href="trashed.php" class="btn btn-info" role="button">Go to trashed</a>
  56. <div id = 'message'>
  57. <?php
  58. if (array_key_exists('message', $_SESSION) && (!empty($_SESSION['message'])))
  59. echo Message::examineMessage();
  60. ?>
  61. </div>
  62. <form role="form">
  63. <div class="form-group">
  64. <label for="sel1">Select homw many items you want to show (select one):</label>
  65. <select class="form-control" id="sel1" name="itemPerPage">
  66. <option
  67. <?php
  68. if ($itemPerPage == 5) {
  69. ?>
  70. selected
  71. <?php
  72. }
  73. ?>
  74. >5</option>
  75. <option
  76. <?php
  77. if ($itemPerPage == 10) {
  78. ?>
  79. selected
  80. <?php
  81. }
  82. ?>
  83. >10</option>
  84. <option
  85. <?php
  86. if ($itemPerPage == 15) {
  87. ?>
  88. selected
  89. <?php
  90. }
  91. ?>
  92. >15</option>
  93. <option
  94. <?php
  95. if ($itemPerPage == 20) {
  96. ?>
  97. selected
  98. <?php
  99. }
  100. ?>
  101. >20</option>
  102. <option
  103. <?php
  104. if ($itemPerPage == 25) {
  105. ?>
  106. selected
  107. <?php
  108. }
  109. ?>
  110. >25</option>
  111. </select>
  112. <button type="submit">Go!</button>
  113. </div>
  114. </form>
  115. <table class="table table-hover">
  116. <thead>
  117. <tr>
  118. <th>SL</th>
  119. <th>ID</th>
  120. <th>Hobby</th>
  121. <th>Action</th>
  122. </tr>
  123. </thead>
  124. <tbody>
  125. <!-- Here getAllBookData is a object -->
  126. <?php
  127. $serialNumber = 1;
  128. foreach ($getAllHobbyData as $hobby) {
  129. ?>
  130. <tr>
  131. <td><?php echo $serialNumber++ + $pageStartFrom ?></td>
  132. <td><?php echo $hobby['id'] ?></td>
  133. <td><?php echo $hobby['hobby'] ?></td>
  134. <td>
  135. <a href="view.php?id=<?php echo $hobby['id']?>" class="btn btn-info" role="button">View</a>
  136. <a href="edit.php?id=<?php echo $hobby['id']?>" class="btn btn-primary" role="button">Edit</a>
  137. <a href="delete.php?id=<?php echo $hobby['id']?>" class="btn btn-danger" role="button">Delete</a>
  138. <a href="trash.php?id=<?php echo $hobby['id']?>" class="btn btn-warning" role="button">Trash</a>
  139. </td>
  140. </tr>
  141. <?php
  142. }
  143. ?>
  144. </tbody>
  145. </table>
  146. <ul class="pagination">
  147. <li
  148. <?php
  149. if ($pageNumber == 1) {
  150. ?>
  151. class="hidden"
  152. <?php
  153. }
  154. ?>
  155. ><a href="index.php?pageNumber= <?php echo($pageNumber - 1) ?>>">Prev</a></li>
  156. <?php echo $pagination ?>
  157. <li
  158. <?php
  159. if ($pageNumber == $totalPage) {
  160. ?>
  161. class="hidden"
  162. <?php
  163. }
  164. ?>
  165. ><a href="index.php?pageNumber= <?php echo($pageNumber + 1) ?>>">Next</a></li>
  166. </ul>
  167. </div>
  168. <script>
  169. $('#message').show().delay(2000).fadeOut();
  170. </script>
  171. </body>
  172. </html>