K_Building.php 2.1 KB

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