Guild.php 3.2 KB

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