Project_Url.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. require_once(PATH::ENTITY . "Entity.php");
  3. /**
  4. * URL related to a project.
  5. *
  6. * Represents an object from the table 'project_url'.
  7. */
  8. class Project_Url extends Entity{
  9. /**
  10. * @var int Identifier of the URL.
  11. */
  12. private $id;
  13. /**
  14. * @var int Identifier of the project the URL is related to.
  15. */
  16. private $project;
  17. /**
  18. * @var Project_Url_Type URL type.
  19. */
  20. private $type;
  21. /**
  22. * @var string Full URL address.
  23. */
  24. private $url;
  25. /**
  26. * Constructor.
  27. *
  28. * Searches the database and retrieves the information about the
  29. * url, populating it and its items.
  30. *
  31. * @param int $id Identifier of the URL.
  32. */
  33. public function __construct($id){
  34. $statement = get_context()->get_db()->prepare("
  35. SELECT
  36. id
  37. project
  38. type
  39. url
  40. FROM project_url
  41. WHERE id = :id
  42. ");
  43. $statement->bindValue(':id', $id, PDO::PARAM_INT);
  44. $statement->execute();
  45. $r_url = $statement->fetch(PDO::FETCH_ASSOC);
  46. if ($r_url !== false){
  47. $this->id = $r_url["id"];
  48. $this->project = $r_url["project"];
  49. $this->type = new Project_Url_Type($r_url["type"]);
  50. $this->url = $r_url["url"];
  51. $this->mark_as_loaded(true);
  52. $this->mark_as_complete(true);
  53. }
  54. else{
  55. Log::warn("Project URL with id '$id' doesn't exist");
  56. }
  57. }
  58. /**
  59. * Retrieves the URL identifier
  60. *
  61. * @return int URL 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 url type.
  76. *
  77. * @return Project_Url_Type URL type.
  78. */
  79. public function get_type(){
  80. return $this->type;
  81. }
  82. /**
  83. * Retrieves the URL
  84. *
  85. * @return string The URL.
  86. */
  87. public function get_url(){
  88. return $this->url;
  89. }
  90. }