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

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

    /**
     * A custom_Filter.
     *
     * Represents an object from the table 'filter'.
     *
     * @category Entity
     */
    class Custom_Filter extends Entity{

        /**
         * @var int Player identifier.
         */
        public $uid;

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

        /**
         * @var string Name of the pge the filter is for.
         */
        public $page;

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

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

        /**
         * @var string Filter condition (sql where clause).
         */
        public $condition;

        /**
         * Constructor.
         *
         * Searches the database and retrieves the information about the
         * run, populating it and it's items.
         *
         * @param resource $db Connection to the database.
         * @param int $id Filter identifier.
         */
        public function __construct($db, $id){
            parent::__construct($db);
            $s = "
                SELECT
                  uid,
                  id,
                  page,
                  name,
                  description,
                  condition
                FROM filter
                WHERE id = $id;
            ";
            $q = $this->db->query($s);
            $r = $q->fetchArray(SQLITE3_ASSOC);
            $this->id = $r["id"];
            $this->uid = $r["uid"];
            $this->page = $r["page"];
            $this->name = HTML::e($r["name"]);
            $this->description = $r["description"]; // Must be properly formated!
            $this->condition = $r["condition"];
        }

    }
?>

