K_Guild_Skill_Group.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "K_Guild_Skill.php");
  4. /**
  5. * Guild skill group.
  6. *
  7. * Represents an object from the table 'k_guild_skill_group'.
  8. */
  9. class K_Guild_Skill_Group extends Entity{
  10. /**
  11. * Group identifier.
  12. */
  13. public $id;
  14. /**
  15. * Group name.
  16. */
  17. public $name;
  18. /**
  19. * Group description.
  20. */
  21. public $description;
  22. /**
  23. * List of {@see K_Guild_Skill}s in the group.
  24. */
  25. public $skills = [];
  26. /**
  27. * Constructor.
  28. *
  29. * Searches the database and retrieves the information about the
  30. * skill group, populating it and it's items.
  31. *
  32. * @param SQLite3 $db Connection to the database.
  33. * @param int $id Skill group identifier.
  34. */
  35. public function __construct($db, $id){
  36. global $path;
  37. parent::__construct($db);
  38. $s =
  39. "SELECT " .
  40. " id, " .
  41. " name, " .
  42. " description " .
  43. "FROM k_guild_skill_group " .
  44. "WHERE id = $id; ";
  45. $q = $this->db->query($s);
  46. $r = $q->fetchArray(SQLITE3_ASSOC);
  47. if ($r){
  48. $this->id = $r["id"];
  49. $this->name = $r["name"];
  50. $this->description = $r["description"];
  51. }
  52. $s =
  53. "SELECT id " .
  54. "FROM k_guild_skill " .
  55. "WHERE skill_group = $this->id; ";
  56. $q = $this->db->query($s);
  57. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  58. array_push($this->skills, new K_Guild_Skill($db, $r["id"]));
  59. }
  60. }
  61. /**
  62. * Gets the pathto the monster image. The image must be in the
  63. * img/skill_guild/ directory, and its name must be the monster id,
  64. * padded with '0' to 1 digits, and the extension must be '.png'.
  65. *
  66. * @return path to the image, or a path to a fixed unknown image if it
  67. * doesn't exist.
  68. */
  69. public function get_image(){
  70. global $base_dir;
  71. global $path;
  72. if (file_exists($base_dir . "img/skill_guild/" . str_pad($this->id, 1, '0', STR_PAD_LEFT) . ".png")){
  73. return $path["img"]["skill_guild"] . str_pad($this->id, 1, '0', STR_PAD_LEFT) . ".png";
  74. }
  75. else{
  76. return $path["img"]["root"] . "unknown.png";
  77. }
  78. }
  79. }
  80. ?>