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

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

    /**
     * Monster skill level.
     *
     * Represents an object from the table 'k_monster_skill_upgrade'.
     *
     * @category Entity
     */
    class K_Skill_Level extends Entity{

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

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

        /**
         * @var string Upgrade description.
         */
        public $description;

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

