| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- /**
- * Guild member entity file.
- *
- * Creates the entity and makes it available.
- *
- * @author Iñigo Valentin <i@inigovalentin.com>
- * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
- * @package SWDB
- */
- require_once(PATH::ENTITY . "Entity.php");
- /**
- * Guild member.
- *
- * Represents amember of a guild.
- *
- * @category Entity
- */
- class Guild_Member extends Entity{
- /**
- * @var int Member's player ID.
- */
- private $id;
- /**
- * @var int Guild ID.
- */
- private $guild;
- /**
- * @var string Member's player name.
- */
- private $name;
- /**
- * @var int Member's level.
- */
- private $level;
- /**
- * @var int Member's grade in the guild ({@see GUILD_MEMBER_GRADE_ID}).
- */
- private $grade;
- /**
- * @var int Member's rating.
- */
- private $rating;
- /**
- * @var int Member's arena score.
- */
- private $arena_score;
- /**
- * @var DateTime Date the member joined the guild.
- */
- private $joined;
- /**
- * @var DateTime The time the user last loged in.
- */
- private $last_login;
- /**
- * @var bool Indicates if the member is in the Guild Wars.
- */
- private $in_war;
- /**
- * @var bool Indicates if the member has set up defenses in the Guild War.
- */
- private $has_defense;
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * guild, populating it and it's items.
- *
- * @param int $id Guild identifier.
- */
- public function __construct($id){
- $statement = get_context()->get_db()->prepare("
- SELECT
- member,
- guild,
- name,
- level,
- grade,
- rating,
- arena_score,
- joined,
- last_login,
- in_war,
- has_defense
- FROM guild_member
- WHERE member = :member;
- ");
- $statement->bindValue(':member', $id, SQLITE3_TEXT);
- $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
- if ($r){
- $this->id = $r["member"];
- $this->guild = $r["guild"];
- $this->name = HTML::e($r["name"]);
- $this->level = $r["level"];
- $this->grade = $r["grade"];
- $this->rating = $r["rating"];
- $this->arena_score = $r["arena_score"];
- $this->joined = new Datetime();
- $this->joined->setTimestamp($r["joined"]);
- $this->last_login = new Datetime();
- $this->last_login->setTimestamp($r["last_login"]);
- if ($r["in_war"] == 1){
- $this->in_war = true;
- }
- else{
- $this->in_war = false;
- }
- if ($r["has_defense"] == 1){
- $this->has_defense = true;
- }
- else{
- $this->has_defense = false;
- }
- }
- }
- /**
- * Retrieves the player identifier of the member.
- *
- * @return int Member ID.
- */
- public function get_id(){
- return $this->id;
- }
- /**
- * Retrieves the guild identifier.
- *
- * @return int Guild ID.
- */
- public function get_guild_id(){
- return $this->guild;
- }
- /**
- * Retrieves the member name.
- *
- * @return string Member name.
- */
- public function get_name(){
- return $this->name;
- }
- /**
- * Retrieves the member's level.
- *
- * @return int Member level.
- */
- public function get_level(){
- return $this->level;
- }
- /**
- * Retrieves the grade of the member in the guild.
- *
- * @return int Member grade.
- */
- public function get_grade(){
- return $this->grade;
- }
- /**
- * Retrieves the member's rating.
- *
- * @return int The members rating.
- */
- public function get_rating(){
- return $this->rating;
- }
- /**
- * Retrieves the member's arena score.
- *
- * @return int Arena score.
- */
- public function get_arena_score(){
- return $this->arena_score;
- }
- /**
- * Retrieves $joined
- *
- * @return DateTime
- */
- public function get_joined(){
- return $this->joined;
- }
- /**
- * Gets the date the member joined the guild.
- *
- * If $format is supplied, a string in the desired format will be returned. If not, the raw
- * DateTime object will e returned.
- *
- * @param string $format A date format (optional).
- * @return DateTime | string The raw date, or a formatted version.
- */
- public function get_join_time($format = null){
- if (null == $format){
- return $this->joined;
- }
- else{
- return $this->joined->format($format);
- }
- }
- /**
- * Gets the time the member las logged in.
- *
- * If $format is supplied, a string in the desired format will be returned. If not, the raw
- * DateTime object will e returned.
- *
- * @param string $format A date format (optional).
- * @return DateTime | string The raw date, or a formatted version.
- */
- public function get_last_login($format = null){
- if (null == $format){
- return $this->last_login;
- }
- else{
- return $this->last_login->format($format);
- }
- }
- /**
- * Checks if the member is inscribed in Guild Wars.
- *
- * @return bool True if inscribed, false otherwise.
- */
- public function is_in_war(){
- return $this->in_war;
- }
- /**
- * Checks if the member has defenses set in Guild War.
- *
- * @return bool True if defenses are set, false otherwise.
- */
- public function has_defense(){
- return $this->has_defense;
- }
- }
|