Album.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Photo.php");
  4. /**
  5. * Album.
  6. *
  7. * Represents an object from the table 'album'.
  8. */
  9. class Album extends Entity{
  10. /**
  11. * Identifier.
  12. */
  13. public $id;
  14. /**
  15. * Permalink for linking the entity (relative).
  16. */
  17. public $permalink;
  18. /**
  19. * Title in the selected language. It may be not set.
  20. */
  21. public $title;
  22. /**
  23. * The content in the defined language. It may be not set.
  24. */
  25. public $description;
  26. /**
  27. * Array with every {@see Photo} in the album.
  28. */
  29. public $photo = [];
  30. /**
  31. * Constructor.
  32. *
  33. * Searches the database and retrieves the information about the
  34. * entity, populating it and it's items.
  35. *
  36. * @param db Connection to the database.
  37. * @param lang Lowercase, two-letter language code.
  38. * @param id Identifier or permalink.
  39. */
  40. public function __construct($db, $lang, $id){
  41. parent::__construct($db, $lang);
  42. $s =
  43. "SELECT " .
  44. " id, " .
  45. " file, " .
  46. " permalink, " .
  47. " title_" . $this->lang . " AS title, " .
  48. " description_" . $this->lang . " AS description " .
  49. "FROM album " .
  50. "WHERE " .
  51. " id = '$id' OR " .
  52. " permalink = '$id';";
  53. $q = mysqli_query($this->db, $s);
  54. if (mysqli_num_rows($q) > 0){
  55. $r = mysqli_fetch_array($q);
  56. $this->id = $r["id"];
  57. $this->permalink = $r["permalink"];
  58. if (!is_null($r["title"])){
  59. $this->title = $r["title"];
  60. }
  61. if (!is_null($r["description"])){
  62. $this->description = $r["description"];
  63. }
  64. }
  65. $s_photo =
  66. "SELECT id " .
  67. "FROM photo_album " .
  68. "WHERE " .
  69. " album = " . $this->id . ";";
  70. $q_photo = mysqli_query($this->db, $s_photo);
  71. while($r_photo = mysqli_fetch_array($q_photo)){
  72. array_push($this->photo, new Photo($this->db, $this->lang, $r_photo["id"]));
  73. }
  74. }
  75. }
  76. ?>