Photo.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Photo_Comment.php");
  4. require_once($path["entity"] . "Place.php");
  5. /**
  6. * Photo.
  7. *
  8. * Represents an object from the table 'photo'.
  9. */
  10. class Photo extends Entity{
  11. /**
  12. * Identifier.
  13. */
  14. public $id;
  15. /**
  16. * Filename.
  17. */
  18. public $file;
  19. /**
  20. * Permalink for linking the entity (relative).
  21. */
  22. public $permalink;
  23. /**
  24. * Title in the selected language. It may be not set.
  25. */
  26. public $title;
  27. /**
  28. * The content in the defined language. It may be not set.
  29. */
  30. public $description;
  31. /**
  32. * Time the photo was taken.
  33. */
  34. public $dtime;
  35. /**
  36. * Time the photo was taken.
  37. */
  38. public $uploaded;
  39. /**
  40. * {@see Place} the photo was taken in. It may be unknown.
  41. */
  42. public $place;
  43. /**
  44. * Indicates if the photo has been approven and can be shown.
  45. */
  46. public $approved;
  47. /**
  48. * Username of the uploader or sender.
  49. */
  50. public $username;
  51. /**
  52. * Array with the {@see Post_Comment}.
  53. */
  54. public $comment = [];
  55. /**
  56. * Constructor.
  57. *
  58. * Searches the database and retrieves the information about the
  59. * entity, populating it and it's items.
  60. *
  61. * @param db Connection to the database.
  62. * @param lang Lowercase, two-letter language code.
  63. * @param id Identifier or permalink.
  64. */
  65. public function __construct($db, $lang, $id){
  66. parent::__construct($db, $lang);
  67. $s =
  68. "SELECT " .
  69. " id, " .
  70. " file, " .
  71. " permalink, " .
  72. " title_" . $this->lang . " AS title, " .
  73. " description_" . $this->lang . " AS description, " .
  74. " dtime, " .
  75. " uploaded, " .
  76. " place, " .
  77. " approved, " .
  78. " username " .
  79. "FROM photo " .
  80. "WHERE " .
  81. " approved = 1 AND " .
  82. " ( " .
  83. " id = '$id' OR " .
  84. " permalink = '$id' " .
  85. " );";
  86. $q = mysqli_query($this->db, $s);
  87. if (mysqli_num_rows($q) > 0){
  88. $r = mysqli_fetch_array($q);
  89. $this->id = $r["id"];
  90. $this->file = $r["file"];
  91. $this->permalink = $r["permalink"];
  92. if (!is_null($r["title"])){
  93. $this->title = $r["title"];
  94. }
  95. if (!is_null($r["description"])){
  96. $this->description = $r["description"];
  97. }
  98. if (!is_null($r["dtime"])){
  99. $this->dtime = $r["dtime"];
  100. }
  101. $this->uploaded = $r["uploaded"];
  102. if (!is_null($r["place"])){
  103. $this->place = New Place($this->db, $this->lang, $r["place"]);
  104. }
  105. $this->approved = $r["approved"];
  106. if (!is_null($r["username"])){
  107. $this->username = $r["username"];
  108. }
  109. }
  110. $s_comment =
  111. "SELECT id " .
  112. "FROM photo_comment " .
  113. "WHERE " .
  114. " photo = " . $this->id . " AND " .
  115. " approved = 1;";
  116. $q_comment = mysqli_query($this->db, $s_comment);
  117. while($r_comment = mysqli_fetch_array($q_comment)){
  118. array_push($this->comment, new Photo_Comment($this->db, $r_comment["id"]));
  119. }
  120. }
  121. }
  122. ?>