Guild_Member.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * Guild member 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. * Guild.
  15. *
  16. * Represents an object from the table 'guild'.
  17. *
  18. * @category Entity
  19. */
  20. class Guild_Member extends Entity{
  21. private $id;
  22. private $guild;
  23. private $name;
  24. private $level;
  25. private $grade;
  26. private $rating;
  27. private $arena_score;
  28. private $joined;
  29. private $last_login;
  30. private $in_war;
  31. private $has_defense;
  32. /**
  33. * Checks if the member has defenses set in Guild War.
  34. *
  35. * @return boolean True if defenses are set, false otherwise.
  36. */
  37. public function has_defense(){
  38. return $this->has_defense;
  39. }
  40. /**
  41. * Constructor.
  42. *
  43. * Searches the database and retrieves the information about the
  44. * guild, populating it and it's items.
  45. *
  46. * @param int $id Guild identifier.
  47. */
  48. public function __construct($id){
  49. $statement = get_context()->get_db()->prepare("
  50. SELECT
  51. member,
  52. guild,
  53. name,
  54. level,
  55. grade,
  56. rating,
  57. arena_score,
  58. joined,
  59. last_login,
  60. in_war,
  61. has_defense
  62. FROM guild_member
  63. WHERE member = :member;
  64. ");
  65. $statement->bindValue(':member', $id, SQLITE3_TEXT);
  66. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  67. if ($r){
  68. $this->id = $r["member"];
  69. $this->guild = $r["guild"];
  70. $this->name = HTML::e($r["name"]);
  71. $this->level = $r["level"];
  72. $this->grade = $r["grade"];
  73. $this->rating = $r["rating"];
  74. $this->arena_score = $r["arena_score"];
  75. $this->joined = new Datetime();
  76. $this->joined->setTimestamp($r["joined"]);
  77. $this->last_login = new Datetime();
  78. $this->last_login->setTimestamp($r["last_login"]);
  79. if ($r["in_war"] == 1){
  80. $this->in_war = true;
  81. }
  82. else{
  83. $this->in_war = false;
  84. }
  85. if ($r["has_defense"] == 1){
  86. $this->has_defense = true;
  87. }
  88. else{
  89. $this->has_defense = false;
  90. }
  91. }
  92. }
  93. /**
  94. * Retrieves the player identifier of the member.
  95. *
  96. * @return int Member ID.
  97. */
  98. public function get_id(){
  99. return $this->id;
  100. }
  101. /**
  102. * Retrieves the guild identifier.
  103. *
  104. * @return int Guild ID.
  105. */
  106. public function get_guild_id(){
  107. return $this->guild;
  108. }
  109. /**
  110. * Retrieves the member name.
  111. *
  112. * @return string Member name.
  113. */
  114. public function get_name(){
  115. return $this->name;
  116. }
  117. /**
  118. * Retrieves the member's level.
  119. *
  120. * @return int Member level.
  121. */
  122. public function get_level(){
  123. return $this->level;
  124. }
  125. /**
  126. * Retrieves the grade of the member in the guild.
  127. *
  128. * @return int Member grade.
  129. */
  130. public function get_grade(){
  131. return $this->grade;
  132. }
  133. /**
  134. * Retrieves the member's rating.
  135. *
  136. * @return int The members rating.
  137. */
  138. public function get_rating(){
  139. return $this->rating;
  140. }
  141. /**
  142. * Retrieves the member's arena score.
  143. *
  144. * @return int Arena score.
  145. */
  146. public function get_arena_score(){
  147. return $this->arena_score;
  148. }
  149. /**
  150. * Retrieves $joined
  151. *
  152. * @return DateTime
  153. */
  154. public function get_joined(){
  155. return $this->joined;
  156. }
  157. /**
  158. * Gets the date the member joined the guild.
  159. *
  160. * If $format is supplied, a string in the desired format will be returned. If not, the raw
  161. * DateTime object will e returned.
  162. *
  163. * @param string $format A date format (optional).
  164. * @return DateTime | string The raw date, or a formatted version.
  165. */
  166. public function get_join_time($format = null){
  167. if (null == $format){
  168. return $this->joined;
  169. }
  170. else{
  171. return $this->joined->format($format);
  172. }
  173. }
  174. /**
  175. * Gets the time the member las logged in.
  176. *
  177. * If $format is supplied, a string in the desired format will be returned. If not, the raw
  178. * DateTime object will e returned.
  179. *
  180. * @param string $format A date format (optional).
  181. * @return DateTime | string The raw date, or a formatted version.
  182. */
  183. public function get_last_login($format = null){
  184. if (null == $format){
  185. return $this->last_login;
  186. }
  187. else{
  188. return $this->last_login->format($format);
  189. }
  190. }
  191. /**
  192. * Checks if the member is inscribed in Guild Wars.
  193. *
  194. * @return boolean Tue if inscribed, false otherwise.
  195. */
  196. public function is_in_war(){
  197. return $this->in_war;
  198. }
  199. }
  200. ?>