Perforce Chronicle 2012.2/486814
API Documentation

Ui_View_Helper_DijitMenu Class Reference

Implementation of the Zend Navigation HelperAbstract that provides output in p4cms.ui.Menu / dijit.MenuItem format. More...

List of all members.

Public Member Functions

 htmlify (Zend_Navigation_Page $page)
 This function detect what type of page is passed and then calls through to htmlify(Separator|Page|SubMenu).
 menu (Zend_Navigation_Container $container=null)
 View helper entry point: Retrieves helper and optionally sets container to operate on.
 render (Zend_Navigation_Container $container=null)
 Renders menu.
 renderMenu (Zend_Navigation_Container $container=null, array $options=array())
 Renders helper.

Protected Member Functions

 _htmlifyPage ($page)
 Returns an HTML string containing an 'div' element for the given page.
 _htmlifySeparator ($page)
 Used to render seperator pages.
 _htmlifySubMenu ($page)
 Used to render pages with sub-pages.
 _normalizeOptions (array $options=array())
 Normalizes given render options.
 _renderMenu (Zend_Navigation_Container $container, $indent, $attribs, $minDepth, $maxDepth)
 Renders a normal menu (called from renderMenu())

Static Protected Attributes

static $_menuDijit = 'p4cms.ui.Menu'
static $_menuItemDijit = 'dijit.MenuItem'
static $_menuSeparatorDijit = 'dijit.MenuSeparator'
static $_popupMenuItemDijit = 'dijit.PopupMenuItem'

Detailed Description

Implementation of the Zend Navigation HelperAbstract that provides output in p4cms.ui.Menu / dijit.MenuItem format.

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

Ui_View_Helper_DijitMenu::_htmlifyPage ( page) [protected]

Returns an HTML string containing an 'div' element for the given page.

If an 'onClick' property is present it will be rendered out and the href will be ignored. If no onClick is set the href will be converted to javascript and rendered. The 'class' property will appear as 'iconClass'. If specified, the 'onShow' property will be rendered.

Overrides Zend_View_Helper_Navigation_Abstract::htmlify().

Parameters:
Zend_Navigation_Page$pagepage to generate HTML for
Returns:
string HTML string for the given page
    {
        // get label and title for translating
        $label = $page->getLabel();
        $title = $page->getTitle();

        // get attribs for element
        $attribs = array(
            'id'        => $page->getId(),
            'iconClass' => $page->getClass(),
            'disabled'  => $page->disabled
        );

        // if no onClick is set but we have an href, convert to js
        if (!($onClick = $page->get('onClick')) && $page->getHref()) {
            $onClick = 'window.location = ' . Zend_Json::encode($page->getHref());
        }

        if ($onClick) {
            $onClick = '<script type="dojo/connect" event="onClick">'
                     . $onClick
                     . '</script>';
        }

        if (($onShow = $page->get('onShow'))) {
            $onShow = '<script type="dojo/connect" event="onShow" args="menuItem,menu">'
                     . $onShow
                     . '</script>';
        }

        return '<div dojotype="' . static::$_menuItemDijit . '"'
             . $this->_htmlAttribs($attribs) . '>'
             . $onClick
             . $onShow
             . $this->view->escape($label)
             . '</div>';
    }
Ui_View_Helper_DijitMenu::_htmlifySeparator ( page) [protected]

Used to render seperator pages.

Will return the HTML representing the passed page entry.

Parameters:
Zend_Navigation_Page$pagepage to generate HTML for
Returns:
string HTML string for the given page
    {
        if (($onShow = $page->get('onShow'))) {
            $onShow = '<script type="dojo/connect" event="onShow" args="menuItem,menu">'
                     . $onShow
                     . '</script>';
        }

        return '<div dojotype="' . static::$_menuSeparatorDijit . '">' . $onShow . '</div>';
    }
Ui_View_Helper_DijitMenu::_htmlifySubMenu ( page) [protected]

Used to render pages with sub-pages.

Will return the HTML representing the passed page entry.

Parameters:
Zend_Navigation_Page$pagepage to generate HTML for
Returns:
string HTML string for the given page
    {
        // render a PopupMenuItem and our label if children present
        return '<div dojotype="' . static::$_popupMenuItemDijit . '">'
             . '<span>' . $this->view->escape($page->getLabel()) . '</span>';
    }
Ui_View_Helper_DijitMenu::_normalizeOptions ( array $  options = array()) [protected]

Normalizes given render options.

Parameters:
array$options[optional] options to normalize
Returns:
array normalized options
    {
        if (isset($options['indent'])) {
            $options['indent'] = $this->_getWhitespace($options['indent']);
        } else {
            $options['indent'] = $this->getIndent();
        }

        if (!isset($options['attribs']) || !is_array($options['attribs'])) {
            $options['attribs'] = array();
        }

        if (array_key_exists('minDepth', $options)) {
            if (null !== $options['minDepth']) {
                $options['minDepth'] = (int) $options['minDepth'];
            }
        } else {
            $options['minDepth'] = $this->getMinDepth();
        }

        if ($options['minDepth'] < 0 || $options['minDepth'] === null) {
            $options['minDepth'] = 0;
        }

        if (array_key_exists('maxDepth', $options)) {
            if (null !== $options['maxDepth']) {
                $options['maxDepth'] = (int) $options['maxDepth'];
            }
        } else {
            $options['maxDepth'] = $this->getMaxDepth();
        }

        return $options;
    }
Ui_View_Helper_DijitMenu::_renderMenu ( Zend_Navigation_Container $  container,
indent,
attribs,
minDepth,
maxDepth 
) [protected]

Renders a normal menu (called from renderMenu())

Parameters:
Zend_Navigation_Container$containercontainer to render
string$indentinitial indentation
array$attribsattribs for the outer-most Menu div
int | null$minDepthminimum depth
int | null$maxDepthmaximum depth
Returns:
string
    {
        $html = '';

        // pull the wrapper class out of the attributes
        // so we can add it to submenus as well
        $wrapperClass = isset($attribs['wrapperClass']) ? $attribs['wrapperClass'] : '';

        // find deepest active
        if (($found = $this->findActive($container, $minDepth, $maxDepth))) {
            $foundPage = $found['page'];
            $foundDepth = $found['depth'];
        } else {
            $foundPage = null;
        }

        // create iterator
        $iterator = new RecursiveIteratorIterator($container,
                            RecursiveIteratorIterator::SELF_FIRST);
        if (is_int($maxDepth)) {
            $iterator->setMaxDepth($maxDepth);
        }

        // iterate container
        $prevDepth = -1;
        foreach ($iterator as $page) {
            $depth = $iterator->getDepth();
            $isActive = $page->isActive(true);
            if ($depth < $minDepth || !$this->accept($page)) {
                // page is below minDepth or not accepted by acl/visibilty
                continue;
            }

            // make sure indentation is correct
            $depth   -= $minDepth;
            $myIndent = $indent . str_repeat('        ', $depth);

            if ($depth > $prevDepth) {
                // start new menu tag
                $attribs['wrapperClass'] = $wrapperClass . ' level-' . $depth;
                $html .= $myIndent . '<div dojoType="' .  static::$_menuDijit . '"'
                      . $this->_htmlAttribs($attribs) . '>' .  self::EOL;
                $attribs = array();
            } else if ($prevDepth > $depth) {
                // close menu tags until we're at current depth
                for ($i = $prevDepth; $i > $depth; $i--) {
                    $ind = $indent . str_repeat('        ', $i);
                    $html .= $ind . '</div>' . self::EOL;

                    // also close the popupMenuItem
                    $html .= $myIndent . '        ' . '</div>' . self::EOL;
                }
            }

            // render the actual item if no children
            $html .= $myIndent . '        ' . $this->htmlify($page) . self::EOL;

            // store as previous depth for next iteration
            $prevDepth = $depth;
        }

        if ($html) {
            // done iterating container; close open div tags
            for ($i = $prevDepth+1; $i > 0; $i--) {
                $myIndent = $indent . str_repeat('        ', $i-1);
                $html .= $myIndent . '</div>' . self::EOL;

                // also close the popupMenuItem if we are a sub-menu
                if ($i > 1) {
                    $html .= $myIndent . '</div>' . self::EOL;
                }
            }
            $html = rtrim($html, self::EOL);
        }

        return $html;
    }
Ui_View_Helper_DijitMenu::htmlify ( Zend_Navigation_Page $  page)

This function detect what type of page is passed and then calls through to htmlify(Separator|Page|SubMenu).

Overrides Zend_View_Helper_Navigation_Abstract::htmlify().

Parameters:
Zend_Navigation_Page$pagepage to generate HTML for
Returns:
string HTML string for the given page
    {
        if ($page->hasChildren()) {
            return $this->_htmlifySubMenu($page);
        } else if ($page instanceof P4Cms_Navigation_Page_Separator) {
            return $this->_htmlifySeparator($page);
        } else {
            return $this->_htmlifyPage($page);
        }
    }
Ui_View_Helper_DijitMenu::menu ( Zend_Navigation_Container $  container = null)

View helper entry point: Retrieves helper and optionally sets container to operate on.

Parameters:
Zend_Navigation_Container$container[optional] container to operate on
Returns:
Zend_View_Helper_Navigation_Menu fluent interface, returns self
    {
        if (null !== $container) {
            $this->setContainer($container);
        }

        return $this;
    }
Ui_View_Helper_DijitMenu::render ( Zend_Navigation_Container $  container = null)

Renders menu.

Implements Zend_View_Helper_Navigation_Helper::render().

see renderMenu()

Parameters:
Zend_Navigation_Container$container[optional] container to render. Default is to render the container registered in the helper.
Returns:
string helper output
    {
        return $this->renderMenu($container);
    }
Ui_View_Helper_DijitMenu::renderMenu ( Zend_Navigation_Container $  container = null,
array $  options = array() 
)

Renders helper.

Renders a Menu dijit 'div' for the given $container with child MenuItem divs for any pages present. If $container is not given, the container registered in the helper will be used.

Available $options: indent attribs - html attribs that will apply to the outer-most Menu div minDepth maxDepth

Parameters:
Zend_Navigation_Container$container[optional] container to create menu from. Default is to use the container retrieved from getContainer().
array$options[optional] options for controlling rendering
Returns:
string rendered menu
    {
        if (null === $container) {
            $container = $this->getContainer();
        }

        $options = $this->_normalizeOptions($options);

        $html = $this->_renderMenu(
            $container,
            $options['indent'],
            $options['attribs'],
            $options['minDepth'],
            $options['maxDepth']
        );

        return $html;
    }

Member Data Documentation

Ui_View_Helper_DijitMenu::$_menuDijit = 'p4cms.ui.Menu' [static, protected]
Ui_View_Helper_DijitMenu::$_menuItemDijit = 'dijit.MenuItem' [static, protected]
Ui_View_Helper_DijitMenu::$_menuSeparatorDijit = 'dijit.MenuSeparator' [static, protected]
Ui_View_Helper_DijitMenu::$_popupMenuItemDijit = 'dijit.PopupMenuItem' [static, protected]

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