Project_Image.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. require_once(PATH::ENTITY . "Entity.php");
  3. /**
  4. * Image of a project.
  5. *
  6. * Represents an object from the table 'project_image'.
  7. */
  8. class Project_Image extends Entity{
  9. /**
  10. * @var int Image identifier.
  11. */
  12. private $id;
  13. /**
  14. * @var int Project identifier.
  15. */
  16. private $project;
  17. /**
  18. * @var int Indicates the order position among other images.
  19. */
  20. private $idx;
  21. /**
  22. * @var string Filename of the image.
  23. */
  24. private $image;
  25. /**
  26. * @var string Alternative text for the image.
  27. */
  28. private $alt;
  29. /**
  30. * Constructor.
  31. *
  32. * Searches the database and retrieves the information about the
  33. * image, populating it.
  34. *
  35. * @param int $id Identifier of the image.
  36. */
  37. public function __construct($id){
  38. $statement = get_context()->get_db()->prepare("
  39. SELECT id, project, idx, image, alt FROM project_image WHERE id = :id
  40. ");
  41. $statement->bindValue(':id', $id, PDO::PARAM_INT);
  42. $statement->execute();
  43. $r_image = $statement->fetch(PDO::FETCH_ASSOC);
  44. if ($r_image !== false){
  45. $this->id = $r_image["id"];
  46. $this->project = $r_image["project"];
  47. $this->idx = $r_image["idx"];
  48. $this->image = $r_image["image"];
  49. $this->alt = Text::get($r_image["alt"]);
  50. }
  51. else{
  52. Log::warn("Project image with id '$id' doesn't exist");
  53. }
  54. }
  55. /**
  56. * Retrieves the image identifier
  57. *
  58. * @return int Image ID.
  59. */
  60. public function get_id(){
  61. return $this->id;
  62. }
  63. /**
  64. * Retrieves the project identifier
  65. *
  66. * @return int Project ID.
  67. */
  68. public function get_project(){
  69. return $this->project;
  70. }
  71. /**
  72. * Retrieves the image index for sorting.
  73. *
  74. * @return int Image index.
  75. */
  76. public function get_idx(){
  77. return $this->idx;
  78. }
  79. /**
  80. * Retrieves the image filename.
  81. *
  82. * @return string Image filename.
  83. */
  84. public function get_image(){
  85. return $this->image;
  86. }
  87. /**
  88. * Retrieves the image alternative text or title.
  89. *
  90. * @return string Image text.
  91. */
  92. public function get_text(){
  93. return $this->alt;
  94. }
  95. }