License.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. require_once(PATH::ENTITY . "Entity.php");
  3. /**
  4. * License.
  5. *
  6. * Represents an object from the table 'license'.
  7. */
  8. class License extends Entity{
  9. /**
  10. * @var string License identifier. Usually an abbreviation.
  11. */
  12. private $id;
  13. /**
  14. * @var string Short, easily readable text summarizing the full text of
  15. * the license.
  16. */
  17. private $summary;
  18. /**
  19. * @var string Full text of the license.
  20. */
  21. private $legal;
  22. /**
  23. * @var string License logo.
  24. */
  25. private $logo;
  26. /**
  27. * @var string License icon, small.
  28. */
  29. private $icon;
  30. /**
  31. * Constructor.
  32. *
  33. * Searches the database and retrieves the information about the
  34. * object, populating it.
  35. *
  36. * @param string $id Identifier of the license.
  37. */
  38. public function __construct($id){
  39. $statement = get_context()->get_db()->prepare("
  40. SELECT
  41. id
  42. summary
  43. legal
  44. logo
  45. icon
  46. FROM license
  47. WHERE id = :id
  48. ");
  49. $statement->bindValue(':id', $id, PDO::PARAM_INT);
  50. $statement->execute();
  51. $r_license = $statement->fetch(PDO::FETCH_ASSOC);
  52. if ($r_license !== false){
  53. $this->id = $r_license["id"];
  54. $this->summary = TEXT::get($r_license["summary"]);
  55. $this->legal = TEXT::get($r_license["legal"]);
  56. $this->logo = $r_license["logo"];
  57. $this->icon = $r_license["icon"];
  58. $this->mark_as_loaded(true);
  59. $this->mark_as_complete(true);
  60. }
  61. else{
  62. Log::warn("License with id '$id' doesn't exist");
  63. }
  64. }
  65. /**
  66. * Retrieves the license identifier
  67. *
  68. * @return string License ID.
  69. */
  70. public function get_id(){
  71. return $this->id;
  72. }
  73. /**
  74. * Retrieves a short, easily readable text summarizing the full text of
  75. * the license.
  76. *
  77. * @return string License summary.
  78. */
  79. public function get_summary(){
  80. return $this->summary;
  81. }
  82. /**
  83. * Retrieves the full text of the license
  84. *
  85. * @return string License legal text.
  86. */
  87. public function get_legal(){
  88. return $this->legal;
  89. }
  90. /**
  91. * Retrieves the license logo.
  92. *
  93. * @return string The logo filename.
  94. */
  95. public function get_logo(){
  96. return $this->logo;
  97. }
  98. /**
  99. * Retrieves the license icon.
  100. *
  101. * @return string The icon filename.
  102. */
  103. public function get_icon(){
  104. return $this->icon;
  105. }
  106. }