Sponsor.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. /**
  4. * Sponsor.
  5. *
  6. * Represents an object from the table 'sponsor'.
  7. */
  8. class Sponsor extends Entity{
  9. /**
  10. * Identifier.
  11. */
  12. public $id;
  13. /**
  14. * Name of the sponsor.
  15. */
  16. public $name;
  17. /**
  18. * Short text describing the sponsor.
  19. */
  20. public $text;
  21. /**
  22. * Sponsor logo.
  23. */
  24. public $image;
  25. /**
  26. * Sponsor url.
  27. */
  28. public $link;
  29. /**
  30. * Indicates if the sponsor has a phisical location.
  31. */
  32. public $local;
  33. /**
  34. * Address, if any.
  35. */
  36. public $address;
  37. /**
  38. * Geographical location, if any.
  39. */
  40. public $location = [
  41. "lat" => null,
  42. "lon" => null
  43. ];
  44. /**
  45. * Constructor.
  46. *
  47. * Searches the database and retrieves the information about the
  48. * entity, populating it and it's items.
  49. *
  50. * @param db Connection to the database.
  51. * @param lang Lowercase, two-letter language code.
  52. * @param id Identifier.
  53. */
  54. public function __construct($db, $lang, $id){
  55. parent::__construct($db, $lang);
  56. $s =
  57. "SELECT " .
  58. " id, " .
  59. " name_$lang AS name, " .
  60. " text_$lang AS text, " .
  61. " image, " .
  62. " link, " .
  63. " local, " .
  64. " address_$lang AS address, " .
  65. " lat, " .
  66. " lon " .
  67. "FROM sponsor " .
  68. "WHERE id = '$id';";
  69. $q = mysqli_query($this->db, $s);
  70. if (mysqli_num_rows($q) > 0){
  71. $r = mysqli_fetch_array($q);
  72. $this->id = $r["id"];
  73. $this->name = $r["name"];
  74. $this->text = $r["text"];
  75. $this->image = $r["image"];
  76. $this->link = $r["link"];
  77. if ($r["local"] == 1){
  78. $this->local = true;
  79. $this->address = $r["address"];
  80. $this->location["lat"] = $r["lat"];
  81. $this->location["lon"] = $r["lon"];
  82. }
  83. else{
  84. $this->local = false;
  85. }
  86. }
  87. }
  88. }
  89. ?>