K_Guild_Skill_Group.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 . "K_Guild_Skill.php");
  14. /**
  15. * Guild skill group.
  16. *
  17. * Represents an object from the table 'k_guild_skill_group'.
  18. *
  19. * @category Entity
  20. */
  21. class K_Guild_Skill_Group extends Entity{
  22. /**
  23. * @var int Group identifier.
  24. */
  25. public $id;
  26. /**
  27. * @var string Group name.
  28. */
  29. public $name;
  30. /**
  31. * @var string Group description.
  32. */
  33. public $description;
  34. /**
  35. * @var \K_Guild_Skill[] List of K_Guild_Skills in the group.
  36. */
  37. public $skills = [];
  38. /**
  39. * Constructor.
  40. *
  41. * Searches the database and retrieves the information about the
  42. * skill group, populating it and it's items.
  43. *
  44. * @param int $id Skill group identifier.
  45. * @global resource Database connection.
  46. */
  47. public function __construct($id){
  48. global $db;
  49. $statement = $db->prepare("
  50. SELECT
  51. id,
  52. name,
  53. description
  54. FROM k_guild_skill_group
  55. WHERE id = :id;
  56. ");
  57. $statement->bindValue(':id', $id, SQLITE3_TEXT);
  58. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  59. if ($r){
  60. $this->id = $r["id"];
  61. $this->name = HTML::e($r["name"]);
  62. $this->description = HTML::e($r["description"]);
  63. $statement = $db->prepare("
  64. SELECT id
  65. FROM k_guild_skill
  66. WHERE skill_group = :id;
  67. ");
  68. $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
  69. $q = $statement->execute();
  70. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  71. array_push($this->skills, new K_Guild_Skill($r["id"]));
  72. }
  73. }
  74. }
  75. /**
  76. * Gets the pathto the monster image. The image must be in the
  77. * img/skill_guild/ directory, and its name must be the monster id,
  78. * padded with '0' to 1 digits, and the extension must be '.png'.
  79. *
  80. * @return string Image URL, or a fixed unknown image.
  81. */
  82. public function get_image(){
  83. return APPLICATION::img("SKILL_GUILD", $this->id);
  84. }
  85. }
  86. ?>