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

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

    /**
     * Guild skill.
     *
     * Represents an object from the table 'k_guild_skill'.
     *
     * @category Entity
     */
    class K_Guild_Skill extends Entity{

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

        /**
         * @var int Skill group id.
         */
        public $group;

        /**
         * @var int Level at which the skill becames available.
         */
        public $level;

        /**
         * @var string Skill description.
         */
        public $effect;

        /**
         * Constructor.
         *
         * Searches the database and retrieves the information about the
         * skill, populating it and it's items.
         *
         * @param resource $db Connection to the database.
         * @param int $id Skill identifier.
         */
        public function __construct($db, $id){
            parent::__construct($db);
            $s =
              "SELECT " .
              "  id, " .
              "  skill_group, " .
              "  level, " .
              "  effect " .
              "FROM k_guild_skill " .
              "WHERE id = $id; ";
            $q = $this->db->query($s);
            $r = $q->fetchArray(SQLITE3_ASSOC);
            if ($r){
                $this->id = $r["id"];
                $this->group = $r["skill_group"];
                $this->level = $r["level"];
                $this->effect = HTML::e($r["effect"]);
            }
        }

    }
?>
