<?php
/**
 * Implementation for the helper for one month archive link.
 *
 * @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
 */

/**
 * The helper for one archive links. The link has the article count.
 *
 * @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 HomeWebApp_View_Helper_MonthArchiveLink extends Zend_View_Helper_Abstract
{
    /**
     * locale
     * @var Zend_Locale
     */
    private $_locale;

    /**
     * Sets the locale from main application instance
     */
    public function __construct()
    {
        $this->_locale = Zend_Controller_Front::getInstance()
            ->getParam('bootstrap')
            ->getPluginResource('locale')
            ->getLocale();
    }

    /**
     * Renders the archive hyperlink for a month. 
     * @param Blog_Model_ArticleMonthArchive $archive articles in a particular
     *  month
     * @return string xhtml markup for the link
     */
    public function monthArchiveLink(Blog_Model_ArticleMonthArchive $archive)
    {
        $xHtml="";

        $monthName = MKLib_Utils::getMonthFirstCaseName($archive->getMonth(),$this->_locale);

        $xHtml.= "<a href=\""
            . $this->view->url(
                array(
                    "year" => $archive->getYear(),
                    "month" => $archive->getMonth()
                ),"blogArchiveMonth")
            . "\">"
            . $monthName
            . " "
            . $archive->getYear() . " "
            . "(" . $archive->getArticleCount() . ")"
            . "</a>";

        return $xHtml;
    }
}
