Building.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Building 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. require_once(PATH::ENTITY . "K_Building.php");
  14. /**
  15. * A Building.
  16. *
  17. * Represents an object from the table 'building'.
  18. *
  19. * @category Entity
  20. */
  21. class Building extends Entity{
  22. /**
  23. * @var int Owner identifier.
  24. */
  25. public $uid;
  26. /**
  27. * @var K_Building Base building.
  28. */
  29. public $building;
  30. /**
  31. * @var int Gain per horu.
  32. */
  33. public $gain;
  34. /**
  35. * Constructor.
  36. *
  37. * Searches the database and retrieves the information about the
  38. * building, populating it and it's items.
  39. *
  40. * @param resource $db Connection to the database.
  41. * @param int $id Building identifier.
  42. */
  43. public function __construct($db, $id){
  44. parent::__construct($db);
  45. $s = "
  46. SELECT
  47. uid,
  48. building,
  49. gain
  50. FROM building
  51. WHERE building = $id;
  52. ";
  53. $q = $this->db->query($s);
  54. $r = $q->fetchArray(SQLITE3_ASSOC);
  55. $this->uid = $r["uid"];
  56. $this->building = new K_Building($this->db, $r["building"]);
  57. $this->gain = $r["gain"];
  58. }
  59. }
  60. ?>