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

class Authors extends dbList {

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

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

	public function reindex()
	{
		global $pages;
		$db = $pages->getDB($onlyKeys=false);
		$authorsIndex = array();
		foreach ($db as $pageKey=>$pageFields) {
			if (in_array($pageFields['type'], $GLOBALS['DB_TAGS_TYPES'])) {
				$authorName = $pageFields['username'];
				if (isset($authorsIndex[$authorName])) {
					array_push($authorsIndex[$authorName]['list'], $pageKey);
				} else {
					$user = new User($pageFields['username']);
					$authorsIndex[$authorName]['name'] = $user->displayName();
					$authorsIndex[$authorName]['list'] = array($pageKey);
				}
			}
		}

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

}