K_Decoration.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Decoration key 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. /**
  14. * Decoration.
  15. *
  16. * Represents an object from the table 'k_decoration'.
  17. *
  18. * @category Entity
  19. */
  20. class K_Decoration extends Entity{
  21. /**
  22. * @var int Decoration identifier.
  23. */
  24. public $id;
  25. /**
  26. * @var string Decoration name.
  27. */
  28. public $name;
  29. /**
  30. * @var string Decoration description.
  31. */
  32. public $description;
  33. /**
  34. * @var int Area of effect identifier (if any).
  35. */
  36. public $area;
  37. /**
  38. * @var int Affected stat id (if any).
  39. */
  40. public $stat;
  41. /**
  42. * @var int Affected element id(if any).
  43. */
  44. public $element;
  45. /**
  46. * @var int Max. level.
  47. */
  48. public $max_level;
  49. /**
  50. * @var int[] Effect bonus per level.
  51. */
  52. public $level_bonus = [];
  53. /**
  54. * Cost per level.
  55. */
  56. public $level_cost = [];
  57. /**
  58. * Constructor.
  59. *
  60. * Searches the database and retrieves the information about the
  61. * decoration, populating it and it's items.
  62. *
  63. * @param int $id Decoration identifier.
  64. * @global resource Database connection.
  65. */
  66. public function __construct($id){
  67. global $db;
  68. $statement = $db->prepare("
  69. SELECT
  70. id,
  71. name,
  72. description,
  73. area,
  74. affected_stat,
  75. element,
  76. max_level
  77. FROM k_decoration
  78. WHERE id = :id;
  79. ");
  80. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  81. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  82. if ($r){
  83. $this->id = $r["id"];
  84. $this->name = HTML::e($r["name"]);
  85. $this->description = HTML::e($r["description"]);
  86. $this->area = $r["area"];
  87. $this->stat = $r["affected_stat"];
  88. $this->element = $r["element"];
  89. $this->max_level = $r["max_level"];
  90. $statement = $db->prepare("
  91. SELECT
  92. level,
  93. bonus,
  94. cost
  95. FROM k_decoration_level
  96. WHERE decoration = :id
  97. ");
  98. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  99. $q = $statement->execute();
  100. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  101. $this->level_bonus[$r["level"]] = $r["bonus"];
  102. $this->level_cost[$r["level"]] = $r["cost"];
  103. }
  104. }
  105. }
  106. /**
  107. * Gets the path to the building image. The image must be in the
  108. * img/decoration/ directory, and its name must be the decoration
  109. * id, padded with '0' to 4 digites, and the extension must be '.png'.
  110. *
  111. * @return string Image URL, or a fixed unknown image.
  112. */
  113. public function get_image(){
  114. return APPLICATION::img("DECORATION", $this->id);
  115. }
  116. }
  117. ?>