Artifact_Stat.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /**
  22. * @var int Stat of the artifact.
  23. *
  24. * @see ARTIFACT_STAT_ID
  25. */
  26. public $stat;
  27. /**
  28. * @var string Stat name (uppercase).
  29. */
  30. public $name = "";
  31. /**
  32. * @var int Stat value of the rune.
  33. */
  34. public $value;
  35. /**
  36. * Constructor.
  37. *
  38. * Searches the database and retrieves the information about the
  39. * artifact stat, populating it and it's items.
  40. *
  41. * @param int $id Artifact id.
  42. * @global resource Database connection.
  43. */
  44. public function __construct($artifact){
  45. global $db;
  46. $statement = $db->prepare("
  47. SELECT
  48. stat,
  49. value
  50. FROM artifact_stat
  51. WHERE
  52. artifact = :artifact
  53. ");
  54. $statement->bindValue(':artifact', $artifact, SQLITE3_TEXT);
  55. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  56. if ($r){
  57. $this->stat = $r["stat"];
  58. $this->value = $r["value"];
  59. switch ($this->stat){
  60. case ARTIFACT_STAT_ID::HP:
  61. $this->name = "HP";
  62. break;
  63. case ARTIFACT_STAT_ID::ATK:
  64. $this->name = "ATK";
  65. break;
  66. case ARTIFACT_STAT_ID::DEF:
  67. $this->name = "DEF";
  68. break;
  69. }
  70. }
  71. }
  72. }
  73. ?>