<?php
    /**
     * Guild member entity file.
     *
     * Creates the entity and makes it available.
     *
     * @category Entity
     */

    /**
     * Require dependent entities if not present.
     */
    require_once(PATH::ENTITY . "Entity.php");

    /**
     * Guild.
     *
     * Represents an object from the table 'guild'.
     *
     * @category Entity
     */
    class Guild_Member extends Entity{

        /**
         * @var int Member identifier.
         */
        public $id;

        /**
         * @var int Guild id.
         */
        public $guild;

        /**
         * @var string Member name.
         */
        public $name;

        /**
         * @var int Member level.
         */
        public $level;

        /**
         * @var int Member grade.
         */
        public $grade;

        /**
         * @var int Memeber rating.
         */
        public $rating;

        /**
         * @var int Memebr arena score.
         */
        public $arena_score;

        /**
         * @var DateTime Time the user joined the guild at.
         */
        public $joined;

        /**
         * @var Datetime Time the user last log on at.
         */
        public $last_login;

        /**
         * @var bool Indicates if the member is included in guild wars.
         */
        public $in_war;

        /**
         * @var bool Indicates if the member has set guild wars defenses.
         */
        public $has_defense;


        /**
         * Constructor.
         *
         * Searches the database and retrieves the information about the
         * guild, populating it and it's items.
         *
         * @param resource $db Connection to the database.
         * @param int $id Guild identifier.
         */
        public function __construct($db, $id){
            global $path;
            parent::__construct($db);
            $s =
              "SELECT " .
              "  id, " .
              "  guild, " .
              "  name, " .
              "  level, " .
              "  grade, " .
              "  rating, " .
              "  arena_score, " .
              "  joined, " .
              "  last_login, " .
              "  in_war, " .
              "  has_defense " .
              "FROM guild_member " .
              "WHERE id = $id; ";
            $q = $this->db->query($s);
            $r = $q->fetchArray(SQLITE3_ASSOC);
            if ($r){
                $this->id = $r["id"];
                $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 = $r["joined"];
                $this->last_login = $r["last_login"];
                $this->in_war = $r["in_war"];
                $this->has_defense = $r["has_defense"];
            }
        }

    }
?>
