<?php

    require_once($path["entity"] . "Entity.php");


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

        /**
         * Member identifier.
         */
        public $id;

        /**
         * Guild id.
         */
        public $guild;

        /**
         * Member name.
         */
        public $name;

        /**
         * Member level.
         */
        public $level;

        /**
         * Member grade.
         */
        public $grade;

        /**
         * Memeber rating.
         */
        public $rating;

        /**
         * Memebr arena score.
         */
        public $arena_score;

        /**
         * Timestam the user joined the guild.
         */
        public $joined;

        /**
         * Timestamp the user last log on.
         */
        public $last_login;

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

        /**
         * 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 SQLite3 $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 = $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"];
            }
        }


    }
?>
