Building.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Building entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::ENTITY . "Entity.php");
  12. require_once(PATH::ENTITY . "Buildable.php");
  13. /**
  14. * A building.
  15. *
  16. * Represents an building owned by a player.
  17. * Buildings that can be built and leveled up are not considered buildings, but {@link Decoration}s.
  18. *
  19. * @category Entity
  20. */
  21. class Building extends Entity{
  22. /**
  23. * @var int Owner's player ID.
  24. */
  25. private $player_id;
  26. /**
  27. * @var Buildable The base buildable.
  28. */
  29. private $buildable;
  30. /**
  31. * @var int The gain per hour, on whatever bonus the building provides.
  32. */
  33. private $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. */
  42. public function __construct($id){
  43. $statement = get_context()->get_db()->prepare("
  44. SELECT
  45. player,
  46. buildable,
  47. gain
  48. FROM building
  49. WHERE id = :id;
  50. ");
  51. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  52. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  53. if ($r){
  54. $this->player = $r["player"];
  55. $this->buildable = new Buildable($r["buildable"]);
  56. $this->gain = $r["gain"];
  57. }
  58. }
  59. /**
  60. * Retrieves the player identifier of the owner
  61. *
  62. * @return int Player ID.
  63. */
  64. public function get_player(){
  65. return $this->player_id;
  66. }
  67. /**
  68. * Retrieves the base buildable.
  69. *
  70. * @return Buildable Base buildable.
  71. */
  72. public function get_buildable(){
  73. return $this->buildable;
  74. }
  75. /**
  76. * Retrieves the gain per hour, on whatever the building provides.
  77. *
  78. * @return int Gain per hour.
  79. */
  80. public function get_gain(){
  81. return $this->gain;
  82. }
  83. }