<?php

class Option {
    private $id     = NULL;
    private $key    = NULL;
    private $value  = NULL;

    public function __construct($id, $key, $value) {
        $this->id       = $id;
        $this->key      = $key;
        $this->value    = $value;
    }

    /**
     * Get the value of Id
     *
     *
     * @return int
     *
     */

    public function getID() {
        return $this->id;
    }

    /**
     * Set the value of Id
     *
     *
     * @param int id
     *
     */

    public function setID($id) {
        $this->id = $id;
     }

    /**
     * Get the value of Key
     *
     *
     * @return string
     *
     */

    public function getKey() {
        return $this->key;
    }

    /**
     * Set the value of Key
     *
     *
     * @param string key
     *
     */

    public function setKey($key) {
        $this->key = $key;
     }

    /**
     * Get the value of Value
     *
     *
     * @return string
     *
     */

    public function getValue() {
        return $this->value;
    }

    /**
     * Set the value of Value
     *
     *
     * @param string value
     *
     */

    public function setValue($value) {
        $this->value = $value;
     }

     /*
      *
      * Save current option
      *
      */

     public function save() {
         global $db;

         $db->insertQuery("INSERT INTO `options` (`id`, `key`, `value`) VALUES (" . $this->id . ", '" . $this->key . "', '" . $this->value . "') ON DUPLICATE KEY UPDATE `id` = " . $this->id . ", `key` = '" . $this->key . "', `value` = '" . $this->value . "';");
     }

     /**
     * Get Option by Key
     *
     * @param string $key  Key
     *
     * @return Option Selected Option
     *
     */

     public static function getOptionByKey($key) {
         global $db;

         $option = $db->selectQuery("SELECT * FROM `options` WHERE `key` = '" . $key . "';");

         if(!$option) {
             return false;
         }

         return new Option($option[0]->id, $option[0]->key, $option[0]->value);

     }

}

?>