K_Rune_Set.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. /**
  4. * A rune set.
  5. *
  6. * Represents an object from the table 'k_rune_set'.
  7. */
  8. class K_Rune_Set extends Entity{
  9. /**
  10. * Set identifier.
  11. */
  12. public $id;
  13. /**
  14. * Set name.
  15. */
  16. public $name;
  17. /**
  18. * Required number of runes to activate the set.
  19. */
  20. public $amount;
  21. /**
  22. * Set description.
  23. */
  24. public $description;
  25. /**
  26. * Constructor.
  27. *
  28. * Searches the database and retrieves the information about the
  29. * skill level, populating it and it's items.
  30. *
  31. * @param SQLite3 $db Connection to the database.
  32. * @param int $skill Effect identifier.
  33. */
  34. public function __construct($db, $id){
  35. global $path;
  36. parent::__construct($db);
  37. $s =
  38. "SELECT " .
  39. " id, " .
  40. " name, " .
  41. " amount, " .
  42. " description " .
  43. "FROM k_rune_set " .
  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->amount = $r["amount"];
  51. $this->description = $r["description"];
  52. }
  53. }
  54. /**
  55. * Gets the path to the set image. The image must be in the
  56. * img/rune/ directory, and its name must be the set id,
  57. * padded with '0' to 2 digits, and the extension must be '.png'.
  58. *
  59. * @return Path to the image, or a path to a fixed unknown image if it
  60. * doesn't exist.
  61. */
  62. public function get_image(){
  63. global $base_dir;
  64. global $path;
  65. if (file_exists($base_dir . "img/rune/" . str_pad($this->id, 2, '0', STR_PAD_LEFT) . ".png")){
  66. return $path["img"]["rune"] . str_pad($this->id, 2, '0', STR_PAD_LEFT) . ".png";
  67. }
  68. else{
  69. return $path["img"]["root"] . "unknown.png";
  70. }
  71. }
  72. }
  73. ?>