<?php
/**
 * Article day archive model.
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */

/**
 * Article day archive
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
class ArticleDayArchive extends Model
{
    /**
     * month part for the archive date
     * @var int (1-12)
     */
    private $_month;

    /**
     * year part for the archive date
     * @var int (1970-2038 ?)
     */
    private $_year;

    /**
     * day part for the archive date
     * @var int (1-31)
     */
    private $_day;

    /**
     * array for the artiles in the particular archive day
     * @var array array of Article objects
     */
    private $_articles;

    /**
     * Initialize date
     * @param int $year (1970 - 2038 ?)
     * @param int $month (1 - 12)
     * @param int $day (1-31)
     */
    public function __construct($year,$month,$day)
    {
        $this->_year=$year;
        $this->_month=$month;
        $this->_day=$day;

        parent::__construct();
    }

    /**
     * Gets articles for the day archive
     * @return array
     * @see ArticleDayArchive::_articles
     */
    public function getArticles()
    {
        return $this->_articles;
    }

    /**
     * Add article into the day archive
     * @param Article $article
     */
    public function addArticle(Article $article)
    {
        $this->_articles[]=$article;
    }

    protected function _setDefaultDao()
    {
        $this->setDao(new Dao_Article());
    }

    protected function _setPropFromArray(&$arr)
    {
        $ignoreKeys=array("yearMonth");
        foreach($arr as $key=>$val) {
            if (in_array($key,$ignoreKeys)) continue;
            $this->{"_".$key}=$val;
        }
    }

    protected function _inflectDaoRowIndexes(&$arr)
    {
        $keys=array_keys($arr);
        foreach($keys as $key) {
            switch ($key) {
            case "artcnt":
                Utils::renameKey($arr,$key,"articleCount");
                break;
            default:
                break;
            }
        }
    }

}
