Festivals_Page.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. require_once($path["page"] . "Page.php");
  3. require_once($path["entity"] . "Festival.php");
  4. /**
  5. * Festivals page model.
  6. */
  7. class Festivals_Page extends Page{
  8. /**
  9. * The selected {@see Festival}.
  10. * If a year has been specified, and it exists, it will be defined.
  11. * If no year is specified, and the setting for the festival is active,
  12. * it will have the one of the current year.
  13. * In any other case, it will be null.
  14. */
  15. public $festival;
  16. /**
  17. * Previous years with festivals.
  18. */
  19. public $previous = [];
  20. /**
  21. * Constructor.
  22. *
  23. * Retrieves the data and initializes the variables.
  24. *
  25. * @param db Connection to the database.
  26. * @param lang Lowercase, two-letter language code.
  27. * @param $year Year of the festivals.
  28. */
  29. public function __construct($db, $lang, $year = null){
  30. global $path;
  31. global $base_url;
  32. global $url;
  33. global $data;
  34. parent::__construct($db, $lang);
  35. if (is_set($year)){
  36. $s_festival =
  37. "SELECT 1 " .
  38. "FROM festival " .
  39. "WHERE " .
  40. " year = $year;";
  41. $q_festival = mysqli_query($this->db, $s_festival);
  42. if (mysqli_num_rows($q_festival) > 0){
  43. $this->festival = new Festival($this->db, $this->lang, $year);
  44. $this->template = $path["template"] . "festivals_active.php";
  45. $this->title = str_replace('#', $year, $this->string['lablanca_title']) . " - " . $data["name"];
  46. $this->description = str_replace('#', $year, $this->string['lablanca_title']) . " - " . $data["name"];
  47. $this->canonical = $base_url . "/" . $url->festivals . "/" . $year;
  48. }
  49. else{
  50. $this->template = $path["template"] . "festivals_inactive.php";
  51. $this->title = $this->string['lablanca_no_title'] . " - " . $data["name"];
  52. $this->description = $this->string['lablanca_no_title'] . " - " . $data["name"];
  53. $this->canonical = $base_url . "/" . $url->festivals . "/";
  54. }
  55. }
  56. else{
  57. $s_setting =
  58. "SELECT value " .
  59. "FROM settings " .
  60. "WHERE " .
  61. " value = 1 AND " .
  62. " name = 'festivals';";
  63. $q_setting = mysqli_query($this->db, $s_setting);
  64. if (mysqli_num_rows($q_setting) > 0){
  65. $s_festival =
  66. "SELECT 1 " .
  67. "FROM festival " .
  68. "WHERE " .
  69. " year = " . date("Y") . ";";
  70. $q_festival = mysqli_query($this->db, $s_festival);
  71. if (mysqli_num_rows($q_festival) > 0){
  72. $this->festival = new Festival($this->db, $this->lang, date("Y"));
  73. $this->template = $path["template"] . "festivals_active.php";
  74. $this->title = str_replace('#', date("Y"), $this->string['lablanca_title']) . " - " . $data["name"];
  75. $this->description = str_replace('#', date("Y"), $this->string['lablanca_title']) . " - " . $data["name"];
  76. $this->canonical = $base_url . "/" . $url->festivals . "/" . date("Y");
  77. }
  78. else{
  79. $this->template = $path["template"] . "festivals_inactive.php";
  80. $this->title = $this->string['lablanca_no_title'] . " - " . $data["name"];
  81. $this->description = $this->string['lablanca_no_title'] . " - " . $data["name"];
  82. $this->canonical = $base_url . "/" . $url->festivals . "/";
  83. }
  84. }
  85. }
  86. $s_previous =
  87. "SELECT year " .
  88. "FROM festival " .
  89. "WHERE str_to_date(concat(year, '-08-10'), '%Y-%m-%d') < now() " .
  90. "ORDER BY year DESC;";
  91. $q_previous = mysqli_query($this->db, $s_previous);
  92. while($r_previous = mysqli_fetch_array($q_previous)){
  93. array_push($this->previous, $r_previous["year"]);
  94. }
  95. }
  96. }
  97. ?>