Activity.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Activity_Comment.php");
  4. require_once($path["entity"] . "Activity_Image.php");
  5. require_once($path["entity"] . "Activity_Itinerary.php");
  6. /**
  7. * Activity.
  8. *
  9. * Represents an object from the table 'activity'.
  10. */
  11. class Activity extends Entity{
  12. /**
  13. * Identifier.
  14. */
  15. public $id;
  16. /**
  17. * Permalink for linking the entity (relative).
  18. */
  19. public $permalink;
  20. /**
  21. * Date of the activity.
  22. */
  23. public $date;
  24. /**
  25. * City the activity takes place in.
  26. */
  27. public $city;
  28. /**
  29. * Title in the selected language.
  30. */
  31. public $title;
  32. /**
  33. * Description in the defined language.
  34. */
  35. public $text;
  36. /**
  37. * Description for when it's in the pase in the defined language.
  38. */
  39. public $after;
  40. /**
  41. * Price of the activity.
  42. */
  43. public $price;
  44. /**
  45. * Indicates if an inscription is required.
  46. */
  47. public $inscription;
  48. /**
  49. * People inscribed to the activity. Undefined if {@see $inscription}
  50. * is false.
  51. */
  52. public $people;
  53. /**
  54. * Maximum number of people that can inscribe. Undefined if
  55. * {@see $inscription} is false.
  56. */
  57. public $max_people;
  58. /**
  59. * Indicates if the activity must be visible.
  60. */
  61. public $visible;
  62. /**
  63. * Posting datetime.
  64. */
  65. public $dtime;
  66. /**
  67. * Photo {@see Album} of the activity.
  68. */
  69. public $album;
  70. /**
  71. * Array with the {@see Activity_Image}.
  72. */
  73. public $image = [];
  74. /**
  75. * Array with the tags.
  76. */
  77. public $tag = [];
  78. /**
  79. * Array with the {@see Activity_Comment}.
  80. */
  81. public $comment = [];
  82. /**
  83. * Array with the {@see Activity_Itinerary} items.
  84. */
  85. public $itinerary = [];
  86. /**
  87. * Constructor.
  88. *
  89. * Searches the database and retrieves the information about the
  90. * entity, populating it and it's items.
  91. *
  92. * @param db Connection to the database.
  93. * @param lang Lowercase, two-letter language code.
  94. * @param id Identifier or permalink.
  95. */
  96. public function __construct($db, $lang, $id){
  97. parent::__construct($db, $lang);
  98. $s =
  99. "SELECT " .
  100. " id, " .
  101. " permalink, " .
  102. " date, " .
  103. " city, " .
  104. " title_" . $this->lang . " AS title, " .
  105. " text_" . $this->lang . " AS text, " .
  106. " after_" . $this->lang . " AS after, " .
  107. " price, " .
  108. " inscription, " .
  109. " people, " .
  110. " max_people, " .
  111. " visible, " .
  112. " dtime, " .
  113. " album " .
  114. "FROM activity " .
  115. "WHERE " .
  116. " visible = 1 AND " .
  117. " ( " .
  118. " id = '$id' OR " .
  119. " permalink = '$id' " .
  120. " );";
  121. $q = mysqli_query($this->db, $s);
  122. if (mysqli_num_rows($q) > 0){
  123. $r = mysqli_fetch_array($q);
  124. $this->id = $r["id"];
  125. $this->permalink = $r["permalink"];
  126. $this->title = $r["title"];
  127. $this->text = $r["text"];
  128. $this->date = $r["date"];
  129. $this->city = $r["city"];
  130. if (!is_null($r["after"])){
  131. $this->after = $r["after"];
  132. }
  133. if ($r["inscription"] == 1){
  134. $this->inscription = true;
  135. $this->people = $r["people"];
  136. $this->max_people = $r["max_people"];
  137. }
  138. else{
  139. $this->inscription = false;
  140. }
  141. if ($r["visible"] == 1){
  142. $this->visible = true;
  143. }
  144. else{
  145. $this->visible = false;
  146. }
  147. $this->price = $r["price"];
  148. $this->dtime = $r["dtime"];
  149. // TODO
  150. //if (!is_null($r["album"])){
  151. // $this->after = New Album($this->db, $this->lang, $r["album"]);
  152. //}
  153. }
  154. $s_image =
  155. "SELECT id " .
  156. "FROM activity_image " .
  157. "WHERE activity = " . $this->id . " " .
  158. "ORDER BY idx; ";
  159. $q_image = mysqli_query($this->db, $s_image);
  160. while($r_image = mysqli_fetch_array($q_image)){
  161. array_push($this->image, new Activity_Image($this->db, $r_image["id"]));
  162. }
  163. $s_tag =
  164. "SELECT tag " .
  165. "FROM activity_tag " .
  166. "WHERE activity = " . $this->id . ";";
  167. $q_tag = mysqli_query($this->db, $s_tag);
  168. while($r_tag = mysqli_fetch_array($q_tag)){
  169. array_push($this->tag, $r_tag["tag"]);
  170. }
  171. $s_comment =
  172. "SELECT id " .
  173. "FROM activity_comment " .
  174. "WHERE " .
  175. " activity = " . $this->id . " AND " .
  176. " approved = 1;";
  177. $q_comment = mysqli_query($this->db, $s_comment);
  178. while($r_tag = mysqli_fetch_array($q_comment)){
  179. array_push($this->comment, new Activity_Comment($this->db, $r_comment["id"]));
  180. }
  181. $s_itinerary =
  182. "SELECT id " .
  183. "FROM activity_itinerary " .
  184. "WHERE " .
  185. " activity = " . $this->id . ";";
  186. $q_itinerary = mysqli_query($this->db, $s_itinerary);
  187. while($r_itinerary = mysqli_fetch_array($q_itinerary)){
  188. array_push($this->itinerary, new Activity_Itinerary($this->db, $this->lang, $r_itinerary["id"]));
  189. }
  190. }
  191. /**
  192. * Checks if an activity is in the future.
  193. *
  194. * If the activity takes place during the current day, it's still
  195. * considered in the future.
  196. *
  197. * @return true if future, false if past.
  198. */
  199. public function is_future(){
  200. return (time() - 60 * 60 * 24 < $this->date);
  201. }
  202. /**
  203. * Checks if an activity is in the past.
  204. *
  205. * If the activity takes place during the current day, it's still
  206. * considered in the future.
  207. *
  208. * @return true if past, false if future.
  209. */
  210. public function is_past(){
  211. return !$this->is_future();
  212. }
  213. }
  214. ?>