Source.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Monster source entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @category Entity
  8. */
  9. /**
  10. * Require dependent entities if not present.
  11. */
  12. require_once(PATH::ENTITY . "Entity.php");
  13. /**
  14. * Monster source.
  15. *
  16. * Represents an object from the table 'source'.
  17. *
  18. * @category Entity
  19. */
  20. class Source extends Entity{
  21. /**
  22. * @var int Source identifier.
  23. */
  24. private $id;
  25. /**
  26. * @var string Source name.
  27. */
  28. private $name;
  29. /**
  30. * @var string Source description.
  31. */
  32. private $description;
  33. /**
  34. * @var bool Indicates if the source is farmable.
  35. */
  36. private $farmable;
  37. /**
  38. * Constructor.
  39. *
  40. * Searches the database and retrieves the information about the
  41. * source, populating it and it's items.
  42. *
  43. * @param int $id Surce identifier.
  44. */
  45. public function __construct($id){
  46. $statement = get_context()->get_db()->prepare("
  47. SELECT
  48. id,
  49. name,
  50. description,
  51. farmable
  52. FROM source
  53. WHERE id = :id;
  54. ");
  55. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  56. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  57. if ($r){
  58. $this->id = $r["id"];
  59. $this->name = HTML::e($r["name"]);
  60. $this->description = HTML::e($r["description"]);
  61. $this->farmable_source = $r["farmable"];
  62. }
  63. }
  64. /**
  65. * Retrieves the source identifier.
  66. *
  67. * @return number Source ID.
  68. */
  69. public function get_id(){
  70. return $this->id;
  71. }
  72. /**
  73. * Retrieves the source name.
  74. *
  75. * @return string Source name.
  76. */
  77. public function get_name(){
  78. return $this->name;
  79. }
  80. /**
  81. * Retrieves the source description.
  82. *
  83. * @return string Source description.
  84. */
  85. public function get_description(){
  86. return $this->description;
  87. }
  88. /**
  89. * Checks if the osurce is farmable.
  90. *
  91. * @return boolean True if the source is farmable, false otherwise.
  92. */
  93. public function is_farmable(){
  94. return $this->farmable;
  95. }
  96. /**
  97. * Gets the path to the source image.
  98. *
  99. * @return string Image URL, or a fixed unknown image.
  100. */
  101. public function get_image(){
  102. return APPLICATION::img("SOURCE", $this->id);
  103. }
  104. }
  105. ?>