<?php
/**
 * Paginator action helper.
 * Simplifies access for pagination parameters from request and configures
 * the paginator object.
 */
class Controller_Helper_Paginator extends Zend_Controller_Action_Helper_Abstract
{
    /** common name for request parameter for current page number */
    const PARAM_NAME = "page";

    /**
     * current name for request parameter with page number
     * @var string
     */
    private $_paramName;

    /**
     * @return Helper_Paginator
     */
    public function __construct()
    {
        $this->_paramName = self::PARAM_NAME;

        //sets default settings for paginator
        Zend_Paginator::setDefaultScrollingStyle('Sliding');
        Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
    }

    /**
     * Sets name for request parameter with page number
     * @param string $name
     */
    public function setParamName($name)
    {
        $this->_paramName = $name;
    }

    /**
     * Gets current page number
     * @return int
     */
    public function getPageNumber()
    {
        $paramVal = $this->getRequest()->getParam($this->_paramName);
        return $paramVal ? $paramVal : 1;
    }
}