Home_Page.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "Post.php");
  4. require_once($path["entity"] . "Activity.php");
  5. /**
  6. * Home page model.
  7. */
  8. class Home_Page extends Page{
  9. /**
  10. * List of the last 3 {@see Post}.
  11. */
  12. public $post = [];
  13. /**
  14. * List of {@see Activity} in the future, sorted with the closest one
  15. * first.
  16. */
  17. public $future = [];
  18. /**
  19. * List of {@see Activity} in the past, sorted with the closest one
  20. * first. Limited to 3.
  21. */
  22. public $past = [];
  23. /**
  24. * Constructor.
  25. *
  26. * Retrieves the data and initializes the variables.
  27. *
  28. * @param db Connection to the database.
  29. * @param lang Lowercase, two-letter language code.
  30. */
  31. public function __construct($db, $lang){
  32. global $path;
  33. global $base_url;
  34. global $data;
  35. parent::__construct($db, $lang);
  36. $this->template = $path["template"] . "home.php";
  37. $s =
  38. "SELECT id " .
  39. "FROM post " .
  40. "WHERE visible = 1 " .
  41. "ORDER BY dtime DESC " .
  42. "LIMIT 3;";
  43. $q = mysqli_query($this->db, $s);
  44. while($r = mysqli_fetch_array($q)){
  45. array_push($this->post, new Post($this->db, $this->lang, $r["id"]));
  46. }
  47. $s_future =
  48. "SELECT id " .
  49. "FROM activity " .
  50. "WHERE " .
  51. " visible = 1 AND " .
  52. " date > now() " .
  53. "ORDER BY date;";
  54. $q_future = mysqli_query($this->db, $s_future);
  55. while($r_future = mysqli_fetch_array($q_future)){
  56. array_push($this->future, new Activity($this->db, $this->lang, $r_future["id"]));
  57. }
  58. $s_past =
  59. "SELECT id " .
  60. "FROM activity " .
  61. "WHERE " .
  62. " visible = 1 AND " .
  63. " date < now() " .
  64. "ORDER BY date DESC " .
  65. "LIMIT 3;";
  66. $q_past = mysqli_query($this->db, $s_past);
  67. while($r_past = mysqli_fetch_array($q_past)){
  68. array_push($this->past, new Activity($this->db, $this->lang, $r_past["id"]));
  69. }
  70. $this->title = $data["name"];
  71. $this->description = $data["description"];
  72. $this->canonical = $base_url . "/";
  73. }
  74. }
  75. ?>