Festival.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Festival_Day.php");
  4. require_once($path["entity"] . "Festival_Offer.php");
  5. require_once($path["entity"] . "Festival_Event.php");
  6. /**
  7. * Festival.
  8. *
  9. * Represents an object from the table 'festival'.
  10. */
  11. class Festival extends Entity{
  12. /**
  13. * Identifier.
  14. */
  15. public $id;
  16. /**
  17. * Year of the festivals.
  18. */
  19. public $year;
  20. /**
  21. * Short text.
  22. */
  23. public $text;
  24. /**
  25. * Description of the festivals.
  26. */
  27. public $description;
  28. /**
  29. * Filename of the festivals banner.
  30. */
  31. public $image;
  32. /**
  33. * Array of {@see Festival_Day}.
  34. */
  35. public $day = [];
  36. /**
  37. * Array of {@see Festival_Offer}.
  38. */
  39. public $offer = [];
  40. /**
  41. * Array of {@see Festival_Event}.
  42. */
  43. public $event = [
  44. "internal" => [],
  45. "public" => []
  46. ];
  47. /**
  48. * Constructor.
  49. *
  50. * Searches the database and retrieves the information about the
  51. * entity, populating it and it's items.
  52. *
  53. * @param db Connection to the database.
  54. * @param lang Lowercase, two-letter language code.
  55. * @param year Year or identifier.
  56. */
  57. public function __construct($db, $lang, $year){
  58. parent::__construct($db, null);
  59. $s =
  60. "SELECT " .
  61. " id, " .
  62. " year, " .
  63. " text_$lang AS text, " .
  64. " description_$lang AS description, " .
  65. " img AS image " .
  66. "FROM festival " .
  67. "WHERE " .
  68. " id = $id OR " .
  69. " year = $id;";
  70. $q = mysqli_query($this->db, $s);
  71. if (mysqli_num_rows($q) > 0){
  72. $r = mysqli_fetch_array($q);
  73. $this->id = $r["id"];
  74. $this->internal = $r["year"];
  75. $this->text = $r["text"];
  76. $this->description = $r["description"];
  77. if (!is_null($r["image"])){
  78. $this->image = $r["image"];
  79. }
  80. }
  81. $s_day =
  82. "SELECT id " .
  83. "FROM festival_day " .
  84. "WHERE year(date) = " . $this->year . " " .
  85. "ORDER BY date; ";
  86. $q_day = mysqli_query($this->db, $s_day);
  87. while($r_day = mysqli_fetch_array($q_day)){
  88. array_push($this->day, new Festival_Day($this->db, $this->lang, $r_day["id"]));
  89. }
  90. $s_offer =
  91. "SELECT id " .
  92. "FROM festival_offer " .
  93. "WHERE year = " . $this->year . " " .
  94. "ORDER BY days; ";
  95. $q_offer = mysqli_query($this->db, $s_offer);
  96. while($r_day = mysqli_fetch_array($q_offer)){
  97. array_push($this->offer, new Festival_Offer($this->db, $this->lang, $r_offer["id"]));
  98. }
  99. // TODO Check
  100. $s_g_day =
  101. "SELECT DISTINCT " .
  102. " date(start) AS date, " .
  103. " day(start) AS day, " .
  104. "FROM festival_event " .
  105. "WHERE " .
  106. " gm = 0 AND " .
  107. " year(start) = " . $this->year . " " .
  108. "ORDER BY date;";
  109. $q_g_day = mysqli_query($this->db, $s_g_day);
  110. $events = [];
  111. while($r_g_day = mysqli_fetch_array($q_g_day)){
  112. $events->$r_g_day["day"] = [];
  113. $s_event =
  114. "SELECT id " .
  115. "FROM festival_event " .
  116. "WHERE " .
  117. " gm = 0 AND " .
  118. " date(date_add(start, INTERVAL -4 HOUR)) = '" . $r_g_day["date"] . "' " .
  119. "ORDER BY start;";
  120. $q_event = mysqli_query($this->db, $s_event);
  121. while($r_event = mysqli_fetch_array($q_event)){
  122. array_push($events->$r_g_day["day"], new Festival_Event($this->db, $this->lang, $r_event["id"]));
  123. }
  124. }
  125. array_push($this->event->public, $events);
  126. $s_g_day =
  127. "SELECT DISTINCT " .
  128. " date(start) AS date, " .
  129. " day(start) AS day, " .
  130. "FROM festival_event " .
  131. "WHERE " .
  132. " gm = 1 AND " .
  133. " year(start) = " . $this->year . " " .
  134. "ORDER BY date;";
  135. $q_g_day = mysqli_query($this->db, $s_g_day);
  136. $events = [];
  137. while($r_g_day = mysqli_fetch_array($q_g_day)){
  138. $events->$r_g_day["day"] = [];
  139. $s_event =
  140. "SELECT id " .
  141. "FROM festival_event " .
  142. "WHERE " .
  143. " gm = 1 AND " .
  144. " date(date_add(start, INTERVAL -4 HOUR)) = '" . $r_g_day["date"] . "' " .
  145. "ORDER BY start;";
  146. $q_event = mysqli_query($this->db, $s_event);
  147. while($r_event = mysqli_fetch_array($q_event)){
  148. array_push($events->$r_g_day["day"], new Festival_Event($this->db, $this->lang, $r_event["id"]));
  149. }
  150. }
  151. array_push($this->event->internal, $events);
  152. }
  153. }
  154. ?>