Building.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 int $id Building identifier.
  41. * @global resource Database connection.
  42. */
  43. public function __construct($id){
  44. global $db;
  45. $statement = $db->prepare("
  46. SELECT
  47. uid,
  48. building,
  49. gain
  50. FROM building
  51. WHERE id = :id;
  52. ");
  53. $statement->bindValue(':id', $id, SQLITE3_INTEGER);
  54. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  55. if ($r){
  56. $this->uid = $r["uid"];
  57. $this->building = new K_Building($r["building"]);
  58. $this->gain = $r["gain"];
  59. }
  60. }
  61. }
  62. ?>