Decoration.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Decoration 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 . "Decorative.php");
  13. /**
  14. * A decoration.
  15. *
  16. * Represents a decoration owned by a player.
  17. * Decorations are buildings that can be built and leveled up. If it can't be leveled up, it's not
  18. * a decoration, but a {@link Building}.
  19. *
  20. * @category Entity
  21. */
  22. class Decoration extends Entity{
  23. /**
  24. * @var int Owner's player ID.
  25. */
  26. private $player_id;
  27. /**
  28. * @var Decorative Base decorative.
  29. */
  30. private $decorative;
  31. /**
  32. * @var int Current level.
  33. */
  34. private $level;
  35. /**
  36. * Constructor.
  37. *
  38. * Searches the database and retrieves the information about the
  39. * decoration, populating it and it's items.
  40. *
  41. * @param int $id Building identifier.
  42. */
  43. public function __construct($id){
  44. $statement = get_context()->get_db()->prepare("
  45. SELECT
  46. player,
  47. decorative,
  48. level
  49. FROM decoration
  50. WHERE id = :id;
  51. ");
  52. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  53. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  54. if ($r){
  55. $this->player = $r["player"];
  56. $this->decorative = new Decorative($r["decorative"]);
  57. $this->level = $r["level"];
  58. }
  59. }
  60. /**
  61. * Retrieves the owner's player id.
  62. *
  63. * @return int Player ID.
  64. */
  65. public function get_player_id(){
  66. return $this->player_id;
  67. }
  68. /**
  69. * Retrieves the base decorative structure.
  70. *
  71. * @return Decorative Base decorative.
  72. */
  73. public function get_decorative(){
  74. return $this->decorative;
  75. }
  76. /**
  77. * Retrieves the decoration level.
  78. *
  79. * @return int Decoration level.
  80. */
  81. public function get_level(){
  82. return $this->level;
  83. }
  84. }