Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Navigation Class Reference

Extend Zend_Navigation to return pages in sorted order. More...

List of all members.

Public Member Functions

 addPage ($page)
 Add a page to the raw navigation container in this menu.
 addPages ($pages)
 Adds several pages at once Extends parent to accept a navigation container.
 getPages ()
 Extend parent to return pages in sorted order.

Static Public Member Functions

static expandMacros ($value, Zend_Navigation_Page $page)
 Utility method to assist with expanding macros in page properties.
static inferPageType ($page)
 A function to infer types of navigation items so that specifying the type is optional - operates recursively (on sub-pages).

Static Protected Member Functions

static _detectPageType (array $page)
 Determine the appropriate page type for a given page definition.

Detailed Description

Extend Zend_Navigation to return pages in sorted order.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

static P4Cms_Navigation::_detectPageType ( array $  page) [static, protected]

Determine the appropriate page type for a given page definition.

Parameters:
array$pagearray definition of a page.
Returns:
string the detected page type.
    {
        // if the entry specifies a 'handler', it is a dynamic menu item.
        if (isset($page['handler'])) {
            return 'P4Cms_Navigation_Page_Dynamic';
        }

        // a contentId param intidactes content page type.
        if (isset($page['contentId'])) {
            return 'P4Cms_Navigation_Page_Content';
        }

        // any mvc parameters indicate mvc page type.
        if (isset($page['action'])
            || isset($page['controller'])
            || isset($page['module'])
            || isset($page['route'])
        ) {
            return 'P4Cms_Navigation_Page_Mvc';
        }

        // presence of uri param indicates uri type.
        if (isset($page['uri'])) {
            return 'P4Cms_Navigation_Page_Uri';
        }

        // a label of only -'s, it is a seperator.
        if (isset($page['label']) && preg_match('/^-+$/', $page['label'])) {
            return 'P4Cms_Navigation_Page_Separator';
        }

        // fallback to heading type.
        return 'P4Cms_Navigation_Page_Heading';
    }
P4Cms_Navigation::addPage ( page)

Add a page to the raw navigation container in this menu.

Parameters:
array | Zend_Navigation_Page | Zend_Config$pagea page to add to the menu.
Returns:
P4Cms_Navigation provides fluent interface.
    {
        parent::addPage(static::inferPageType($page));

        return $this;
    }
P4Cms_Navigation::addPages ( pages)

Adds several pages at once Extends parent to accept a navigation container.

Parameters:
array | Zend_Config | Zend_Navigation_Container$pagespages to add
Returns:
Zend_Navigation_Container fluent interface, returns self
Exceptions:
Zend_Navigation_Exceptionif $pages is not array or Zend_Config
    {
        if ($pages instanceof Zend_Navigation_Container) {
            $pages = iterator_to_array($pages);
        }

        return parent::addPages($pages);
    }
static P4Cms_Navigation::expandMacros ( value,
Zend_Navigation_Page $  page 
) [static]

Utility method to assist with expanding macros in page properties.

Only expands macros in given value if page has expandMacros = true

Parameters:
string$valuethe value to expand macros in
Zend_Navigation_Page$pagethe page for context
Returns:
string the value with macros expanded (if enabled)
    {
        if (!$page->get('expandMacros')) {
            return $value;
        }

        $macro = new P4Cms_Filter_Macro;
        $macro->setContext(array('page' => $page));

        return $macro->filter($value);
    }
P4Cms_Navigation::getPages ( )

Extend parent to return pages in sorted order.

Returns:
array Zend_Navigation_Page instances
    {
        $this->_sort();
        $pages = array();
        foreach ($this->_index as $hash => $order) {
            $pages[] = $this->_pages[$hash];
        }
        return $pages;
    }
static P4Cms_Navigation::inferPageType ( page) [static]

A function to infer types of navigation items so that specifying the type is optional - operates recursively (on sub-pages).

Parameters:
mixed$pagea page definition array to set the type on. note: non-array inputs are returned as-is.
Returns:
mixed the given page definition updated with types set.
    {
        if (!is_array($page)) {
            return $page;
        }

        // if page has an invalid type, clear it.
        if (isset($page['type']) && !class_exists($page['type'])) {
            unset($page['type']);
        }

        // if page doesn't have a valid type, detect one.
        // note: we record that the type was inferred for future
        // reference (e.g. so we know if it's ok to re-assess the type)
        if (!isset($page['type'])) {
            $page['type']         = static::_detectPageType($page);
            $page['typeInferred'] = true;
        }

        // process sub pages if any
        if (array_key_exists('pages', $page) && is_array($page['pages'])) {
            foreach ($page['pages'] as $key => $subPage) {
                $page['pages'][$key] = static::inferPageType($subPage);
            }
        }

        return $page;
    }

The documentation for this class was generated from the following file: