Project_Image.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 int Filename of the image.
  23. */
  24. private $image;
  25. /**
  26. * Constructor.
  27. *
  28. * Searches the database and retrieves the information about the
  29. * image, populating it.
  30. *
  31. * @param int $id Identifier of the image.
  32. */
  33. public function __construct($id){
  34. $statement = get_context()->get_db()->prepare("
  35. SELECT
  36. id,
  37. project,
  38. idx,
  39. image
  40. FROM project_image
  41. WHERE id = :id
  42. ");
  43. $statement->bindValue(':id', $id, PDO::PARAM_INT);
  44. $statement->execute();
  45. $r_image = $statement->fetch(PDO::FETCH_ASSOC);
  46. if ($r_image !== false){
  47. $this->id = $r_image["id"];
  48. $this->project = $r_image["title"];
  49. $this->idx = $r_image["idx"];
  50. $this->image = $r_image["image"];
  51. $this->mark_as_loaded(true);
  52. $this->mark_as_complete(true);
  53. }
  54. else{
  55. Log::warn("Project image with id '$id' doesn't exist");
  56. }
  57. }
  58. /**
  59. * Retrieves the image identifier
  60. *
  61. * @return int Image ID.
  62. */
  63. public function get_id(){
  64. return $this->id;
  65. }
  66. /**
  67. * Retrieves the project identifier
  68. *
  69. * @return int Project ID.
  70. */
  71. public function get_project(){
  72. return $this->project;
  73. }
  74. /**
  75. * Retrieves the image index for sorting.
  76. *
  77. * @return int Image index.
  78. */
  79. public function get_idx(){
  80. return $this->idx;
  81. }
  82. /**
  83. * Retrieves the image filename.
  84. *
  85. * @return string Image filename.
  86. */
  87. public function get_image(){
  88. return $this->image;
  89. }
  90. }