K_Guild_Skill_Group.php 2.7 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 resource $db Connection to the database.
  45. * @param int $id Skill group identifier.
  46. */
  47. public function __construct($db, $id){
  48. parent::__construct($db);
  49. $s =
  50. "SELECT " .
  51. " id, " .
  52. " name, " .
  53. " description " .
  54. "FROM k_guild_skill_group " .
  55. "WHERE id = $id; ";
  56. $q = $this->db->query($s);
  57. $r = $q->fetchArray(SQLITE3_ASSOC);
  58. if ($r){
  59. $this->id = $r["id"];
  60. $this->name = HTML::e($r["name"]);
  61. $this->description = HTML::e($r["description"]);
  62. }
  63. $s =
  64. "SELECT id " .
  65. "FROM k_guild_skill " .
  66. "WHERE skill_group = $this->id; ";
  67. $q = $this->db->query($s);
  68. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  69. array_push($this->skills, new K_Guild_Skill($db, $r["id"]));
  70. }
  71. }
  72. /**
  73. * Gets the pathto the monster image. The image must be in the
  74. * img/skill_guild/ directory, and its name must be the monster id,
  75. * padded with '0' to 1 digits, and the extension must be '.png'.
  76. *
  77. * @return string Image URL, or a fixed unknown image.
  78. */
  79. public function get_image(){
  80. if (file_exists(PATH::BASE . "img/skill_guild/" . str_pad($this->id, 1, '0', STR_PAD_LEFT) . ".png")){
  81. return URL::IMG["SKILL_GUILD"] . str_pad($this->id, 1, '0', STR_PAD_LEFT) . ".png";
  82. }
  83. else{
  84. return URL::IMG["UNKNOWN"];
  85. }
  86. }
  87. }
  88. ?>