Building.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 . "Buildable.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. private $player_id;
  23. private $buildable;
  24. private $gain;
  25. /**
  26. * Constructor.
  27. *
  28. * Searches the database and retrieves the information about the
  29. * building, populating it and it's items.
  30. *
  31. * @param int $id Building identifier.
  32. */
  33. public function __construct($id){
  34. $statement = get_context()->get_db()->prepare("
  35. SELECT
  36. player,
  37. buildable,
  38. gain
  39. FROM building
  40. WHERE id = :id;
  41. ");
  42. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  43. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  44. if ($r){
  45. $this->player = $r["player"];
  46. $this->buildable = new Buildable($r["buildable"]);
  47. $this->gain = $r["gain"];
  48. }
  49. }
  50. /**
  51. * Retrieves the player identifier of the owner
  52. *
  53. * @return int Player ID.
  54. */
  55. public function get_player(){
  56. return $this->player_id;
  57. }
  58. /**
  59. * Retrieves the base buildable.
  60. *
  61. * @return Buildable Base buildable.
  62. */
  63. public function get_buildable(){
  64. return $this->buildable;
  65. }
  66. /**
  67. * Retrieves the gain per hour, on whatever the building provides.
  68. *
  69. * @return number Gain per hour.
  70. */
  71. public function get_gain(){
  72. return $this->gain;
  73. }
  74. }
  75. ?>