K_Source.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Unit 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 'k_source'.
  17. *
  18. * @category Entity
  19. */
  20. class K_Source extends Entity{
  21. /**
  22. * @var int Unit identifier.
  23. */
  24. public $id;
  25. /**
  26. * @var string Source name.
  27. */
  28. public $name;
  29. /**
  30. * @var string Source description.
  31. */
  32. public $description;
  33. /**
  34. * @var bool Indicates if the source is farmable.
  35. */
  36. public $farmable;
  37. /**
  38. * Constructor.
  39. *
  40. * Searches the database and retrieves the information about the
  41. * monster, populating it and it's items.
  42. *
  43. * @param resource $db Connection to the database.
  44. * @param int $id Monster identifier.
  45. */
  46. public function __construct($db, $id){
  47. parent::__construct($db);
  48. $s =
  49. "SELECT " .
  50. " id, " .
  51. " name, " .
  52. " description, " .
  53. " farmable " .
  54. "FROM k_source " .
  55. "WHERE id = $id; ";
  56. $q = $this->db->query($s);
  57. $r = $q->fetchArray(SQLITE3_ASSOC);
  58. if ($r){
  59. $this->id = $r["id"];
  60. $this->name = HTML::e($r["name"]);
  61. $this->description = HTML::e($r["description"]);
  62. $this->farmable_source = $r["farmable"];
  63. }
  64. }
  65. /**
  66. * Gets the path to the source image. The image must be in the
  67. * img/source/ directory, and it's name must be the source id,
  68. * padded with '0' to 4 digits, and the extension must be '.png'.
  69. *
  70. * @return string Image URL, or a fixed unknown image.
  71. */
  72. public function get_image(){
  73. return APPLICATION::img("SOURCE", $this->id);
  74. }
  75. }
  76. ?>