K_Unit_Transformation.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Transformation 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_Skill.php");
  14. require_once(PATH::ENTITY . "K_Leader_Skill.php");
  15. require_once(PATH::ENTITY . "K_Source.php");
  16. /**
  17. * Unit transformation.
  18. *
  19. * Represents an object from the table 'k_unit_transformation'.
  20. *
  21. * @category Entity
  22. */
  23. class K_Unit_Transformation extends Entity{
  24. /**
  25. * @var int Transformed unit identifier.
  26. */
  27. public $id;
  28. /**
  29. * @var int Transformed unit family id.
  30. */
  31. public $family;
  32. /**
  33. * @var int ID of the unit that transformes into this.
  34. */
  35. public $unit;
  36. /**
  37. * @var \K_Skill[] Skills in the transformed form.
  38. */
  39. public $skill = [];
  40. /**
  41. * Constructor.
  42. *
  43. * Searches the database and retrieves the information about the
  44. * trnsformed unit, populating it and it's items.
  45. *
  46. * @param int $id Transformed unit identifier.
  47. * @global resource Database connection.
  48. */
  49. public function __construct($id){
  50. global $db;
  51. $statement = $db->prepare("
  52. SELECT
  53. id,
  54. family,
  55. unit
  56. FROM k_unit_transformation
  57. WHERE id = :id;
  58. ");
  59. $statement->bindValue(':id', $id, SQLITE3_INTEGER);
  60. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  61. if ($r){
  62. $this->id = $r["id"];
  63. $this->family = $r["family"];
  64. $this->unit = $r["unit"];
  65. $this->load_skills();
  66. }
  67. }
  68. /**
  69. * Loads the information about the unit skills in the transformed form.
  70. *
  71. * @global resource Database connection.
  72. */
  73. private function load_skills(){
  74. global $db;
  75. $this->skill = [];
  76. $s = "
  77. SELECT skill
  78. FROM
  79. k_skill,
  80. k_unit_skill
  81. WHERE
  82. id = skill AND
  83. unit = " . $this->id . "
  84. ORDER BY slot;
  85. ";
  86. $q = $db->query($s);
  87. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  88. array_push($this->skill, new K_Skill($r["skill"]));
  89. }
  90. }
  91. /**
  92. * Gets the path to the unit image. The image must be in the
  93. * img/unit/ directory, and it's name must be the unit id,
  94. * padded with '0' to 8 digits, and the extension must be '.png'.
  95. *
  96. * @return string Image URL, or a fixed unknown image.
  97. */
  98. public function get_image(){
  99. return APPLICATION::img("UNIT", $this->id);
  100. }
  101. }
  102. ?>