K_Source.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. /**
  4. * Monster source.
  5. *
  6. * Represents an object from the table 'k_source'.
  7. */
  8. class K_Source extends Entity{
  9. /**
  10. * Monster identifier.
  11. */
  12. public $id;
  13. /**
  14. * Source name.
  15. */
  16. public $name;
  17. /**
  18. * Source description.
  19. */
  20. public $description;
  21. /**
  22. * Indicates if the source is farmable.
  23. */
  24. public $farmable_source;
  25. /**
  26. * Constructor.
  27. *
  28. * Searches the database and retrieves the information about the
  29. * monster, populating it and it's items.
  30. *
  31. * @param SQLite3 $db Connection to the database.
  32. * @param int $id Monster identifier.
  33. */
  34. public function __construct($db, $id){
  35. global $path;
  36. parent::__construct($db);
  37. $s =
  38. "SELECT " .
  39. " id, " .
  40. " name, " .
  41. " description, " .
  42. " farmable_source " .
  43. "FROM k_source " .
  44. "WHERE id = $id; ";
  45. $q = $this->db->query($s);
  46. $r = $q->fetchArray(SQLITE3_ASSOC);
  47. if ($r){
  48. $this->id = $r["id"];
  49. $this->name = $r["name"];
  50. $this->description = $r["description"];
  51. $this->farmable_source = $r["farmable_source"];
  52. }
  53. }
  54. /**
  55. * Gets the path to the source image. The image must be in the
  56. * img/source/ directory, and it's name must be the source id,
  57. * padded with '0' to 4 digits, and the extension must be '.png'.
  58. *
  59. * @return Path to the image, or a path to a fixed unknown image if it
  60. * doesn't exist.
  61. */
  62. public function get_image(){
  63. global $base_dir;
  64. global $path;
  65. if (file_exists($base_dir . "img/source/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
  66. return $path["img"]["source"] . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
  67. }
  68. else{
  69. return $path["img"]["root"] . "unknown.png";
  70. }
  71. }
  72. }
  73. ?>