Guild_Member.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. /**
  3. * Guild member entity file.
  4. *
  5. * Creates the entity and makes it available.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::ENTITY . "Entity.php");
  12. /**
  13. * Guild member.
  14. *
  15. * Represents amember of a guild.
  16. *
  17. * @category Entity
  18. */
  19. class Guild_Member extends Entity{
  20. /**
  21. * @var int Member's player ID.
  22. */
  23. private $id;
  24. /**
  25. * @var int Guild ID.
  26. */
  27. private $guild;
  28. /**
  29. * @var string Member's player name.
  30. */
  31. private $name;
  32. /**
  33. * @var int Member's level.
  34. */
  35. private $level;
  36. /**
  37. * @var int Member's grade in the guild ({@see GUILD_MEMBER_GRADE_ID}).
  38. */
  39. private $grade;
  40. /**
  41. * @var int Member's rating.
  42. */
  43. private $rating;
  44. /**
  45. * @var int Member's arena score.
  46. */
  47. private $arena_score;
  48. /**
  49. * @var DateTime Date the member joined the guild.
  50. */
  51. private $joined;
  52. /**
  53. * @var DateTime The time the user last loged in.
  54. */
  55. private $last_login;
  56. /**
  57. * @var bool Indicates if the member is in the Guild Wars.
  58. */
  59. private $in_war;
  60. /**
  61. * @var bool Indicates if the member has set up defenses in the Guild War.
  62. */
  63. private $has_defense;
  64. /**
  65. * Constructor.
  66. *
  67. * Searches the database and retrieves the information about the
  68. * guild, populating it and it's items.
  69. *
  70. * @param int $id Guild identifier.
  71. */
  72. public function __construct($id){
  73. $statement = get_context()->get_db()->prepare("
  74. SELECT
  75. member,
  76. guild,
  77. name,
  78. level,
  79. grade,
  80. rating,
  81. arena_score,
  82. joined,
  83. last_login,
  84. in_war,
  85. has_defense
  86. FROM guild_member
  87. WHERE member = :member;
  88. ");
  89. $statement->bindValue(':member', $id, SQLITE3_TEXT);
  90. $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
  91. if ($r){
  92. $this->id = $r["member"];
  93. $this->guild = $r["guild"];
  94. $this->name = HTML::e($r["name"]);
  95. $this->level = $r["level"];
  96. $this->grade = $r["grade"];
  97. $this->rating = $r["rating"];
  98. $this->arena_score = $r["arena_score"];
  99. $this->joined = new Datetime();
  100. $this->joined->setTimestamp($r["joined"]);
  101. $this->last_login = new Datetime();
  102. $this->last_login->setTimestamp($r["last_login"]);
  103. if ($r["in_war"] == 1){
  104. $this->in_war = true;
  105. }
  106. else{
  107. $this->in_war = false;
  108. }
  109. if ($r["has_defense"] == 1){
  110. $this->has_defense = true;
  111. }
  112. else{
  113. $this->has_defense = false;
  114. }
  115. }
  116. }
  117. /**
  118. * Retrieves the player identifier of the member.
  119. *
  120. * @return int Member ID.
  121. */
  122. public function get_id(){
  123. return $this->id;
  124. }
  125. /**
  126. * Retrieves the guild identifier.
  127. *
  128. * @return int Guild ID.
  129. */
  130. public function get_guild_id(){
  131. return $this->guild;
  132. }
  133. /**
  134. * Retrieves the member name.
  135. *
  136. * @return string Member name.
  137. */
  138. public function get_name(){
  139. return $this->name;
  140. }
  141. /**
  142. * Retrieves the member's level.
  143. *
  144. * @return int Member level.
  145. */
  146. public function get_level(){
  147. return $this->level;
  148. }
  149. /**
  150. * Retrieves the grade of the member in the guild.
  151. *
  152. * @return int Member grade.
  153. */
  154. public function get_grade(){
  155. return $this->grade;
  156. }
  157. /**
  158. * Retrieves the member's rating.
  159. *
  160. * @return int The members rating.
  161. */
  162. public function get_rating(){
  163. return $this->rating;
  164. }
  165. /**
  166. * Retrieves the member's arena score.
  167. *
  168. * @return int Arena score.
  169. */
  170. public function get_arena_score(){
  171. return $this->arena_score;
  172. }
  173. /**
  174. * Retrieves $joined
  175. *
  176. * @return DateTime
  177. */
  178. public function get_joined(){
  179. return $this->joined;
  180. }
  181. /**
  182. * Gets the date the member joined the guild.
  183. *
  184. * If $format is supplied, a string in the desired format will be returned. If not, the raw
  185. * DateTime object will e returned.
  186. *
  187. * @param string $format A date format (optional).
  188. * @return DateTime | string The raw date, or a formatted version.
  189. */
  190. public function get_join_time($format = null){
  191. if (null == $format){
  192. return $this->joined;
  193. }
  194. else{
  195. return $this->joined->format($format);
  196. }
  197. }
  198. /**
  199. * Gets the time the member las logged in.
  200. *
  201. * If $format is supplied, a string in the desired format will be returned. If not, the raw
  202. * DateTime object will e returned.
  203. *
  204. * @param string $format A date format (optional).
  205. * @return DateTime | string The raw date, or a formatted version.
  206. */
  207. public function get_last_login($format = null){
  208. if (null == $format){
  209. return $this->last_login;
  210. }
  211. else{
  212. return $this->last_login->format($format);
  213. }
  214. }
  215. /**
  216. * Checks if the member is inscribed in Guild Wars.
  217. *
  218. * @return bool True if inscribed, false otherwise.
  219. */
  220. public function is_in_war(){
  221. return $this->in_war;
  222. }
  223. /**
  224. * Checks if the member has defenses set in Guild War.
  225. *
  226. * @return bool True if defenses are set, false otherwise.
  227. */
  228. public function has_defense(){
  229. return $this->has_defense;
  230. }
  231. }