Project_Url.php 2.0 KB

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