Mvc.php #1

  • //
  • guest/
  • perforce_software/
  • chronicle/
  • main/
  • library/
  • P4Cms/
  • Navigation/
  • Page/
  • Mvc.php
  • View
  • Commits
  • Open Download .zip Download (3 KB)
<?php
/**
 * Extends Zend_Navigation_Page_Mvc to generate page href with optionally disabled encoding.
 *
 * @copyright   2011 Perforce Software. All rights reserved.
 * @license     Please see LICENSE.txt in top-level folder of this distribution.
 * @version     <release>/<patch>
 */
class P4Cms_Navigation_Page_Mvc extends Zend_Navigation_Page_Mvc
{
    protected $_encode = true;

    /**
     * Returns page label with support for macros.
     *
     * @return  string  page label or null
     */
    public function getLabel()
    {
        return P4Cms_Navigation::expandMacros(parent::getLabel(), $this);
    }

    /**
     * Returns page title with support for macros.
     *
     * @return  string|null     page title or null
     */
    public function getTitle()
    {
        return P4Cms_Navigation::expandMacros(parent::getTitle(), $this);
    }

    /**
     * Overwritten parent to allow assembling url with disabled encoding. Parent method
     * provided by Zend doesn't provide any option to disable href encoding, which is
     * needed in some cases (e.g. for category links).
     *
     * @return  string  page href
     */
    public function getHref()
    {
        if ($this->_hrefCache) {
            return $this->_hrefCache;
        }

        if (null === self::$_urlHelper) {
            self::$_urlHelper =
                Zend_Controller_Action_HelperBroker::getStaticHelper('Url');
        }

        $params = $this->getParams();

        if ($param = $this->getModule()) {
            $params['module'] = $param;
        }

        if ($param = $this->getController()) {
            $params['controller'] = $param;
        }

        if ($param = $this->getAction()) {
            $params['action'] = $param;
        }

        $url = self::$_urlHelper->url(
            $params,
            $this->getRoute(),
            $this->getResetParams(),
            $this->_encode
        );

        return $this->_hrefCache = $url;
    }

    /**
     * Set whether to encode page href generated by getHref() method.
     *
     * @param   boolean     $encode         if true then page href will be encoded,
     *                                      otherwise page href will not be encoded
     * @return  P4Cms_Navigation_Page_Mvc   provides fluent interface
     */
    public function setEncode($encode)
    {
        $this->_encode    = (bool) $encode;
        $this->_hrefCache = null;

        return $this;
    }

    /**
     * Returns an array representation of the page
     *
     * @return  array   associative array containing all page properties
     */
    public function toArray()
    {
        return array_merge(
            parent::toArray(),
            array(
                'label' => $this->_label,
                'title' => $this->_title
            )
        );
    }
}
# Change User Description Committed
#1 16170 perforce_software Move Chronicle files to follow new path scheme for branching.
//guest/perforce_software/chronicle/library/P4Cms/Navigation/Page/Mvc.php
#1 8972 Matt Attaway Initial add of the Chronicle source code