<?php defined('KOBLOG') or die('Koblog CMS.');

class PageType
{
	protected $vars;

	function __construct($type)
	{
		global $pagetypes;

		$this->vars['type'] = $type;

		if (Text::isEmpty($type) || !$pagetypes->exists($type)) {
            $errorMessage = 'Page Type not found in the database [' . $type . ']';
            Log::set(__METHOD__ . LOG_SEP . $errorMessage);
            throw new Exception($errorMessage);
        }
        $row = $pagetypes->getTypeDB($type);

		foreach ($row as $field => $value) {
			$this->setField($field, $value);
		}
	}

	public function getValue($field)
	{
		if (isset($this->vars[$field])) {
			return $this->vars[$field];
		}
		return false;
	}

	public function setField($field, $value)
	{
		$this->vars[$field] = $value;
		return true;
	}

	public function getDB()
	{
		return $this->vars;
	}

    public function type()
    {
        return $this->getValue("type");
    }
    public function icon()
    {
        return $this->getValue("icon");
    }
    public function name()
    {
        return $this->getValue("name");
    }
    public function plural()
    {
        return $this->getValue("plural");
    }

}