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

class Kinds extends dbList {

	function __construct()
	{
		parent::__construct(DB_KINDS);
	}

	function numberOfPages($key)
	{
		return $this->countItems($key);
	}

	public function reindex()
	{
		global $pages;
		global $L;

        $kindArray = array();

        foreach ($GLOBALS['POST_KINDS'] as $kind) {
            $kindArray[$kind]['name'] = $GLOBALS['POST_KINDS_EMOJI'][$kind]." ".$L->g($kind);
			$kindArray[$kind]['list'] = array();
        }


		$db = $pages->getDB($onlyKeys=false);
		foreach ($db as $pageKey=>$pageFields) {
			if ($pageFields['state'] == "published" && isset($pageFields['kinds']) && $pageFields !== '') {
				$kind = $pageFields['kind'];

                // Index by years
				if (isset($kindArray[$kind])) {
					array_push($kindArray[$kind]['list'], $pageKey);
				}

			}
		}

		$this->db = $kindArray;
		return $this->save();
	}

}