Guild_Skill_Group.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Guild skill group 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 . "Guild_Skill.php");
  14. /**
  15. * Guild skill group.
  16. *
  17. * Represents an object from the table 'guild_skill_group'.
  18. *
  19. * @category Entity
  20. */
  21. class Guild_Skill_Group extends Entity{
  22. private $id;
  23. private $name;
  24. private $description;
  25. private $flag_skills = false;
  26. private $skills = [];
  27. /**
  28. * Retrieves the identifier of the skill group.
  29. *
  30. * @return int Group ID
  31. */
  32. public function get_id(){
  33. return $this->id;
  34. }
  35. /**
  36. * Retrieves the name of the skill_group.
  37. *
  38. * @return string Group name.
  39. */
  40. public function get_name(){
  41. return $this->name;
  42. }
  43. /**
  44. * Retrieves the description of the skill group.
  45. *
  46. * @return string Group description.
  47. */
  48. public function get_description(){
  49. return $this->description;
  50. }
  51. /**
  52. * Retrieves the skills in the group.
  53. *
  54. * @return Guild_Skill[] Skills in the group.
  55. */
  56. public function get_skills(){
  57. if (! $this->flag_skills){
  58. $this->load_skills();
  59. }
  60. return $this->skills;
  61. }
  62. /**
  63. * Constructor.
  64. *
  65. * Searches the database and retrieves the information about the
  66. * skill group, populating it and it's items.
  67. *
  68. * @param int $id Skill group identifier.
  69. */
  70. public function __construct($id){
  71. $statement = get_context()->get_db()->prepare("
  72. SELECT
  73. id,
  74. name,
  75. description
  76. FROM guild_skill_group
  77. WHERE id = :id;
  78. ");
  79. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  80. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  81. if ($r){
  82. $this->id = $r["id"];
  83. $this->name = HTML::e($r["name"]);
  84. $this->description = HTML::e($r["description"]);
  85. }
  86. }
  87. private function load_skills(){
  88. $statement = get_context()->get_db()->prepare("
  89. SELECT id
  90. FROM guild_skill
  91. WHERE skill_group = :id;
  92. ");
  93. $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
  94. $q = $statement->execute();
  95. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  96. array_push($this->skills, new Guild_Skill($r["id"]));
  97. }
  98. $this->flag_skills = true;
  99. }
  100. /**
  101. * Gets the pathto the monster image. The image must be in the
  102. * img/skill_guild/ directory, and its name must be the monster id,
  103. * padded with '0' to 1 digits, and the extension must be '.png'.
  104. *
  105. * @return string Image URL, or a fixed unknown image.
  106. */
  107. public function get_image(){
  108. return APPLICATION::img("SKILL_GUILD", $this->id);
  109. }
  110. }
  111. ?>