Guild.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. require_once($path["entity"] . "Entity.php");
  3. require_once($path["entity"] . "Guild_Member.php");
  4. /**
  5. * Guild.
  6. *
  7. * Represents an object from the table 'guild'.
  8. */
  9. class Guild extends Entity{
  10. /**
  11. * Guild identifier.
  12. */
  13. public $id;
  14. /**
  15. * Guild name.
  16. */
  17. public $name;
  18. /**
  19. * Guild level.
  20. */
  21. public $level;
  22. /**
  23. * Guild total experience.
  24. */
  25. public $experience;
  26. /**
  27. * Indicates if the guild is ecruiting.
  28. */
  29. public $recruiting;
  30. /**
  31. * Number of members.
  32. */
  33. public $total_members;
  34. /**
  35. * Leader {@see Guild_Member}.
  36. */
  37. public $leader;
  38. /**
  39. * Guild comment.
  40. */
  41. public $comment;
  42. /**
  43. * Guild notice.
  44. */
  45. public $notice;
  46. /**
  47. * List of {@see Guild_Member}s.
  48. */
  49. public $members = [];
  50. /**
  51. * Constructor.
  52. *
  53. * Searches the database and retrieves the information about the
  54. * guild, populating it and it's items.
  55. *
  56. * @param SQLite3 $db Connection to the database.
  57. * @param int $id Guild identifier.
  58. */
  59. public function __construct($db, $id){
  60. global $path;
  61. parent::__construct($db);
  62. $s =
  63. "SELECT " .
  64. " id, " .
  65. " name, " .
  66. " name, " .
  67. " level, " .
  68. " experience, " .
  69. " recruiting, " .
  70. " members, " .
  71. " leader, " .
  72. " comment, " .
  73. " notice " .
  74. "FROM guild " .
  75. "WHERE id = $id; ";
  76. $q = $this->db->query($s);
  77. $r = $q->fetchArray(SQLITE3_ASSOC);
  78. if ($r){
  79. $this->id = $r["id"];
  80. $this->name = $r["name"];
  81. $this->level = $r["level"];
  82. $this->experience = $r["experience"];
  83. $this->recruiting = $r["recruiting"];
  84. $this->total_members = $r["members"];
  85. $this->leader = $r["leader"];
  86. $this->comment = $r["comment"];
  87. $this->notice = $r["notice"];
  88. }
  89. $s =
  90. "SELECT id " .
  91. "FROM guild_member " .
  92. "WHERE guild = $this->id " .
  93. "ORDER BY " .
  94. " grade = 1 DESC, " .
  95. " grade = 3 DESC, " .
  96. " grade = 2 DESC, " .
  97. " arena_score DESC; ";
  98. $q = $this->db->query($s);
  99. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  100. array_push($this->members, new Guild_Member($db, $r["id"]));
  101. }
  102. }
  103. }
  104. ?>