Artifact_Stat.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Artifact stat 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. /**
  14. * Artifact_stat.
  15. *
  16. * Represents an object from the table 'artifact_stat'.
  17. *
  18. * @category Entity
  19. */
  20. class Artifact_Stat extends Entity{
  21. private $stat;
  22. private $name = "";
  23. private $value;
  24. /**
  25. * Constructor.
  26. *
  27. * Retrieves the artifact stat information from the database.
  28. *
  29. * @param int $artifact_id Artifact id.
  30. */
  31. public function __construct($artifact_id){
  32. $statement = get_context()->get_db()->prepare("
  33. SELECT
  34. stat,
  35. value
  36. FROM artifact_stat
  37. WHERE
  38. artifact = :artifact
  39. ");
  40. $statement->bindValue(':artifact', $artifact_id, SQLITE3_TEXT);
  41. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  42. if ($r){
  43. $this->stat = $r["stat"];
  44. $this->value = $r["value"];
  45. switch ($this->stat){
  46. case ARTIFACT_STAT_ID::HP:
  47. $this->name = "HP";
  48. break;
  49. case ARTIFACT_STAT_ID::ATK:
  50. $this->name = "ATK";
  51. break;
  52. case ARTIFACT_STAT_ID::DEF:
  53. $this->name = "DEF";
  54. break;
  55. }
  56. }
  57. }
  58. /**
  59. * Retrieves the artifact stat identifier.
  60. *
  61. * @see ARTIFACT_STAT_ID
  62. *
  63. * @return int Artifact stat ID.
  64. */
  65. public function get_stat(){
  66. return $this->stat;
  67. }
  68. /**
  69. * Retrieves the artifact stat name.
  70. *
  71. * @return string Artifact stat name.
  72. */
  73. public function get_name(){
  74. return $this->name;
  75. }
  76. /**
  77. * Retrieves the value of the artifact stat value.
  78. *
  79. * @return number Stat value.
  80. */
  81. public function get_value(){
  82. return $this->value;
  83. }
  84. }
  85. ?>