Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Menu_Mixed Class Reference

This model is used to normalize P4Cms_Menu and Zend_Navigation_Page classes into a unifom model allowing them to be listed together. More...

Inheritance diagram for P4Cms_Menu_Mixed:
P4Cms_Model P4Cms_ModelInterface

List of all members.

Public Member Functions

 getDepth ()
 Returns the depth of this item in the heigharchy.
 getId ()
 Get the id of this record.
 getLabel ()
 Return the label for this model.
 getMenu ()
 Return the menu associated with this instance.
 getMenuId ()
 Returns the ID off of the menu if one has been set.
 getMenuItem ()
 Return the menu item associated with this instance.
 getMenuItemId ()
 Returns the ID off of the menu item if one has been set.
 getNextMenuItem ()
 Returns the nexdt menu item that lives at the same level as this models menu item.
 getParentContainer ()
 Return the parent container for this menu item be it another page or a menu.
 getParentId ()
 Return the parent P4Cms_Menu_Mixed id if any.
 getParentMenuItem ()
 The Zend_Navigation_Page based object which is our parent or null.
 getPreviousMenuItem ()
 Returns the previous menu item that lives at the same level as this models menu item.
 getType ()
 Retrieve the identifier for this menu or menu item type.
 hasMenu ()
 Determine if this instance has a menu object set on it.
 hasMenuItem ()
 Determine if this instance has a menu item object set on it.
 hasParentMenuItem ()
 Determine if this instance has a parent menu item object set on it.
 setDepth ($depth)
 Set the depth of this item.
 setMenu (P4Cms_Menu $menu=null)
 Set a menu on this instance.
 setMenuItem (Zend_Navigation_Page $menuItem=null)
 Set a menu item on this instance.
 setParentMenuItem (Zend_Navigation_Page $menuItem=null)
 Set a new parent menu item on this instance or null.

Protected Attributes

 $_menu = null
 $_menuItem = null
 $_parentMenuItem = null

Static Protected Attributes

static $_fields
static $_idField = 'id'

Detailed Description

This model is used to normalize P4Cms_Menu and Zend_Navigation_Page classes into a unifom model allowing them to be listed together.

Please note a number of the fields in this model are read only: id, menuId, menuItemId, label

All of these are derived from the assiciated Menu and, optionally, Menu Item.

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

P4Cms_Menu_Mixed::getDepth ( )

Returns the depth of this item in the heigharchy.

It is intended all Menu's will be a depth of 0 and all Menu Items will be a depth of >= 1. In practice implementors could violate this intent.

Returns:
int The depth
    {
        return $this->_getValue('depth');
    }
P4Cms_Menu_Mixed::getId ( )

Get the id of this record.

Extends parent to dynamically generate the ID based on the Menu and Menu Item.

This is a read only field calculated off of the menu and menu item.

Returns:
mixed the value of the id field.

Reimplemented from P4Cms_Model.

    {
        if (!$this->hasMenu() || !$this->getMenuId()) {
            return null;
        }

        if (!$this->hasMenuItem()) {
            return $this->getMenuId();
        }

        return $this->getMenuId() . '/' . $this->getMenuItemId();
    }
P4Cms_Menu_Mixed::getLabel ( )

Return the label for this model.

If a menu item has been set the label is returned from that. Otherwise, we fall back to the menu's name and lastly empty string.

This is a read only field calculated off of the menu item or menu.

Returns:
string The label for this instance.
    {
        if ($this->hasMenuItem()) {
            return $this->getMenuItem()->getLabel();
        }

        if ($this->hasMenu()) {
            return $this->getMenu()->getLabel();
        }

        return '';
    }
P4Cms_Menu_Mixed::getMenu ( )

Return the menu associated with this instance.

Returns:
P4Cms_Menu|null The associated menu or null if none
    {
        return $this->_menu;
    }
P4Cms_Menu_Mixed::getMenuId ( )

Returns the ID off of the menu if one has been set.

Safe to call even if no menu has been set.

This is a read only field calculated off of the menu.

Returns:
string|null The associated Menu's ID or null
    {
        if (!$this->hasMenu()) {
            return null;
        }

        return $this->getMenu()->getId();
    }
P4Cms_Menu_Mixed::getMenuItem ( )

Return the menu item associated with this instance.

Returns:
Zend_Navigation_Page|null The associated menu item or null if none
    {
        return $this->_menuItem;
    }
P4Cms_Menu_Mixed::getMenuItemId ( )

Returns the ID off of the menu item if one has been set.

Safe to call even if no menu item has been set.

This is a read only field calculated off of the menu item.

Returns:
string|null The associated Menu Item's UUID or null
    {
        if (!$this->hasMenuItem()) {
            return null;
        }

        return $this->getMenuItem()->uuid;
    }
P4Cms_Menu_Mixed::getNextMenuItem ( )

Returns the nexdt menu item that lives at the same level as this models menu item.

For non-menu item mixed models or when no next item exists null is returned.

Returns:
P4Cms_Menu_Mixed|null The next menu item or null
    {
        $container = $this->getParentContainer();
        if (!$container || !$this->hasMenuItem()) {
            return null;
        }

        foreach ($container as $page) {
            if ($page->uuid == $this->getMenuItem()->uuid) {
                break;
            }
        }

        $container->next();

        if (!$container->valid()) {
            return null;
        }

        $next = $container->current();

        $mixed = new static;
        $mixed->setMenu($this->getMenu())
              ->setParentMenuItem($this->getParentMenuItem())
              ->setMenuItem($next);
        
        return $mixed;
    }
P4Cms_Menu_Mixed::getParentContainer ( )

Return the parent container for this menu item be it another page or a menu.

Falls back to returning null for non-menu items or items where parent cannot be determined.

Returns:
Zend_Navigation_Container|null The parent container or null
    {
        if ($this->hasParentMenuItem()) {
            return $this->getParentMenuItem();
        }
        
        if ($this->hasMenu()) {
            return $this->getMenu()->getContainer();
        }
        
        return null;
    }
P4Cms_Menu_Mixed::getParentId ( )

Return the parent P4Cms_Menu_Mixed id if any.

This is a read only field calculated off of the parent menu item, menu item and menu.

Returns:
string|null The parent's mixed ID
    {
        if ($this->hasParentMenuItem() && $this->hasMenu()) {
            return $this->getMenuId() . '/' . $this->getParentMenuItem()->uuid;
        }

        if ($this->hasMenu() && $this->hasMenuItem()) {
            return $this->getMenuId();
        }

        return null;
    }
P4Cms_Menu_Mixed::getParentMenuItem ( )

The Zend_Navigation_Page based object which is our parent or null.

Returns:
Zend_Navigation_Page|null The parent page that was set on this model.
    {
        return $this->_parentMenuItem;
    }
P4Cms_Menu_Mixed::getPreviousMenuItem ( )

Returns the previous menu item that lives at the same level as this models menu item.

For non-menu item mixed models or when no previous item exists null is returned.

Returns:
P4Cms_Menu_Mixed|null The previous menu item or null
    {
        $container = $this->getParentContainer();
        if (!$container || !$this->hasMenuItem()) {
            return null;
        }
        
        $previous = null;
        foreach ($container as $page) {
            if ($page->uuid == $this->getMenuItem()->uuid) {
                break;
            }
            
            $previous = $page;
        }

        if (!$previous) {
            return null;
        }

        $mixed = new static;
        $mixed->setMenu($this->getMenu())
              ->setParentMenuItem($this->getParentMenuItem())
              ->setMenuItem($previous);
        
        return $mixed;
    }
P4Cms_Menu_Mixed::getType ( )

Retrieve the identifier for this menu or menu item type.

The class name is used to id the type of each entry.

Returns:
string|null the id for this entry type.
    {
        if ($this->hasMenuItem()) {
            return get_class($this->getMenuItem());
        } else if ($this->hasMenu()) {
            return get_class($this->getMenu());
        }
        
        return null;
    }
P4Cms_Menu_Mixed::hasMenu ( )

Determine if this instance has a menu object set on it.

Returns:
bool True if a menu has been set false otherwise.
    {
        return $this->_menu !== null;
    }
P4Cms_Menu_Mixed::hasMenuItem ( )

Determine if this instance has a menu item object set on it.

Returns:
bool True if a menu item has been set false otherwise.
    {
        return $this->_menuItem !== null;
    }
P4Cms_Menu_Mixed::hasParentMenuItem ( )

Determine if this instance has a parent menu item object set on it.

Returns:
bool True if a parent menu item has been set false otherwise.
    {
        return $this->_parentMenuItem !== null;
    }
P4Cms_Menu_Mixed::setDepth ( depth)

Set the depth of this item.

See getDepth for more details.

Parameters:
int$depthThe depth to use
Returns:
P4Cms_Menu_Mixed To maintain a fluent interface
    {
        if (!is_int($depth)) {
            throw new InvalidArgumentException('Depth must be an int');
        }

        return $this->_setValue('depth', $depth);
    }
P4Cms_Menu_Mixed::setMenu ( P4Cms_Menu menu = null)

Set a menu on this instance.

Parameters:
P4Cms_Menu | null$menuA menu or null.
Returns:
P4Cms_Menu_Mixed To maintain a fluent interface
    {
        $this->_menu = $menu;

        return $this;
    }
P4Cms_Menu_Mixed::setMenuItem ( Zend_Navigation_Page $  menuItem = null)

Set a menu item on this instance.

Parameters:
Zend_Navigation_Page | null$menuItemA menu item or null.
Returns:
P4Cms_Menu_Mixed To maintain a fluent interface
    {
        $this->_menuItem = $menuItem;
    }
P4Cms_Menu_Mixed::setParentMenuItem ( Zend_Navigation_Page $  menuItem = null)

Set a new parent menu item on this instance or null.

Parameters:
Zend_Navigation_Page | null$menuItemThe parent menu item or null
Returns:
P4Cms_Menu_Mixed To maintain a fluent interface
    {
        $this->_parentMenuItem = $menuItem;

        return $this;
    }

Member Data Documentation

P4Cms_Menu_Mixed::$_fields [static, protected]

Reimplemented from P4Cms_Model.

P4Cms_Menu_Mixed::$_idField = 'id' [static, protected]

Reimplemented from P4Cms_Model.

P4Cms_Menu_Mixed::$_menu = null [protected]
P4Cms_Menu_Mixed::$_menuItem = null [protected]
P4Cms_Menu_Mixed::$_parentMenuItem = null [protected]

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