Source.php 2.5 KB

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