Album.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. " permalink, " .
  46. " title_" . $this->lang . " AS title, " .
  47. " description_" . $this->lang . " AS description " .
  48. "FROM album " .
  49. "WHERE " .
  50. " id = '$id' OR " .
  51. " permalink = '$id';";
  52. $q = mysqli_query($this->db, $s);
  53. if (mysqli_num_rows($q) > 0){
  54. $r = mysqli_fetch_array($q);
  55. $this->id = $r["id"];
  56. $this->permalink = $r["permalink"];
  57. if (!is_null($r["title"])){
  58. $this->title = $r["title"];
  59. }
  60. if (!is_null($r["description"])){
  61. $this->description = $r["description"];
  62. }
  63. }
  64. $s_photo =
  65. "SELECT photo " .
  66. "FROM photo_album " .
  67. "WHERE " .
  68. " album = " . $this->id . ";";
  69. $q_photo = mysqli_query($this->db, $s_photo);
  70. while($r_photo = mysqli_fetch_array($q_photo)){
  71. array_push($this->photo, new Photo($this->db, $this->lang, $r_photo["photo"]));
  72. }
  73. }
  74. }
  75. ?>