Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Navigation_Page_Content Class Reference

Provides a facility for content entry links. More...

List of all members.

Public Member Functions

 getContentAction ()
 Returns the action name for the content.
 getContentId ()
 Returns the id of the content entry associated with this item.
 getHref ()
 The url of our content entry or an empty string.
 getLabel ()
 If we have a content entry set, and no label has been set on this page, returns the entries title.
 getPrivilege ()
 Returns ACL privilege associated with this page Extended to always return 'access' privilege.
 getResource ()
 Returns ACL resource assoicated with this page.
 isActive ($recursive=false)
 Returns whether page should be considered active or not.
 isVisible ($recursive=false)
 Extend parent to make this entry invisble if it isn't valid.
 setContentAction ($action)
 Set the content action name.
 setContentId ($id)
 Set the id of the content entry associated with this item.
 toArray ()
 Returns an array representation of the page.

Public Attributes

const ACL_PRIVILEGE = 'access'
const ACL_RESOURCE = 'content'

Protected Member Functions

 _getEntry ()
 If a content entry id has been set and it can be fetched this will return it.

Protected Attributes

 $_contentAction
 $_contentEntry = false
 $_contentId

Detailed Description

Provides a facility for content entry links.

These links store the content entry id they are associated with to dynamically generate a URL. Also, they will defer to the content entry's title if no label is provided.

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_Navigation_Page_Content::_getEntry ( ) [protected]

If a content entry id has been set and it can be fetched this will return it.

Otherwise if no id has been set or fetch fails null is returned.

Deleted entries will be returned if possible; it is up to caller to screen them if needed.

Returns:
P4Cms_Content|null The associated content entry or null
    {
        // attempt to fetch content entry if we haven't already done so.
        if ($this->_contentEntry === false) {
            $this->_contentEntry = null;
            try {
                $id = $this->getContentId();
                if ($id) {
                    $this->_contentEntry = P4Cms_Content::fetch($id, array('includeDeleted' => true));
                }
            } catch (Exception $e) {
                // eat any exceptions we don't want to break
                // menu management or menu display
            }
        }

        return $this->_contentEntry;
    }
P4Cms_Navigation_Page_Content::getContentAction ( )

Returns the action name for the content.

'View' action will be returned by default if no action has been previously set.

Returns:
string action name for the content
    {
        return $this->_contentAction ?: 'view';
    }
P4Cms_Navigation_Page_Content::getContentId ( )

Returns the id of the content entry associated with this item.

Returns:
string|null id of the associated content entry or null
    {
        return is_string($this->_contentId) ? $this->_contentId : null;
    }
P4Cms_Navigation_Page_Content::getHref ( )

The url of our content entry or an empty string.

Returns:
string the page's href
    {
        $entry = $this->_getEntry();

        // we only return a link if we have a non-deleted entry
        if (!$entry || $entry->isDeleted()) {
            return "";
        }

        // return link to content with specified action (defaults to view if no action was specified)
        $action = $this->get('contentAction') ?: 'view';
        return $entry->getUri($action);
    }
P4Cms_Navigation_Page_Content::getLabel ( )

If we have a content entry set, and no label has been set on this page, returns the entries title.

Otherwise returns the label as per normal.

Returns:
string|null page label or null
    {
        if ($this->_label) {
            return $this->_label;
        }

        $entry = $this->_getEntry();
        if (!$entry) {
            return $this->getContentId();
        }

        return $entry->getTitle();
    }
P4Cms_Navigation_Page_Content::getPrivilege ( )

Returns ACL privilege associated with this page Extended to always return 'access' privilege.

Returns:
string|null ACL privilege or null
    {
        return static::ACL_PRIVILEGE;
    }
P4Cms_Navigation_Page_Content::getResource ( )

Returns ACL resource assoicated with this page.

Extended to always incorporate associated content id.

Returns:
string|Zend_Acl_Resource_Interface|null ACL resource or null
    {
        return static::ACL_RESOURCE . ($this->_contentId
            ? '/' . $this->_contentId
            : '');
    }
P4Cms_Navigation_Page_Content::isActive ( recursive = false)

Returns whether page should be considered active or not.

A content link is considered active if the content entry is currently being viewed. We determine this by looking for an active (default) entry on the content entry view helper.

Parameters:
bool$recursive[optional] whether page should be considered active if any child pages are active. Default is false.
Returns:
bool whether page should be considered active
    {
        $layout = Zend_Layout::getMvcInstance();
        $view   = $layout ? $layout->getView() : null;
        if (!$view || $this->_active) {
            return parent::isActive($recursive);
        }

        // if we have a content entry view helper, check it for an active entry.
        $helpers = $view->getPluginLoader('helper');
        $helper  = $helpers->load('contentEntry', false)
            ? $view->getHelper('contentEntry')
            : false;
        if ($helper
            && $helper->getDefaultEntry()
            && $helper->getDefaultEntry()->getId() == $this->getContentId()
        ) {
            return true;
        }

        // check the child pages if $recursive is set
        if ($recursive) {
            foreach ($this->_pages as $page) {
                if ($page->isActive(true)) {
                    return true;
                }
            }
        }

        return false;
    }
P4Cms_Navigation_Page_Content::isVisible ( recursive = false)

Extend parent to make this entry invisble if it isn't valid.

Parameters:
bool$recursive[optional] whether page should be considered invisible if parent is invisible. Default is false.
Returns:
bool whether page should be considered visible
    {
        // if no entry is accessible; hide
        if (!$this->_getEntry()) {
            return false;
        }

        // if our entry is deleted only show if we have children
        if ($this->_getEntry()->isDeleted() && !count($this->getPages())) {
            return false;
        }

        return parent::isVisible($recursive);
    }
P4Cms_Navigation_Page_Content::setContentAction ( action)

Set the content action name.

Parameters:
string | null$actioncontent action
Returns:
P4Cms_Navigation_Page_Content provides fluent interface
    {
        $this->_contentAction = $action;
        return $this;
    }
P4Cms_Navigation_Page_Content::setContentId ( id)

Set the id of the content entry associated with this item.

Parameters:
string | null$idid of the associated content entry or null
Returns:
P4Cms_Navigation_Page_Dynamic to maintain a fluent interface
    {
        $this->_contentId = $id;

        // reset instance copy of content entry.
        $this->_contentEntry = false;
        return $this;
    }
P4Cms_Navigation_Page_Content::toArray ( )

Returns an array representation of the page.

Returns:
array associative array containing all page properties
    {
        return array_merge(
            parent::toArray(),
            array(
                'contentId'     => $this->getContentId(),
                'contentAction' => $this->getContentAction(),
                'label'         => $this->_label,
                'visible'       => $this->_visible
            )
        );
    }

Member Data Documentation

P4Cms_Navigation_Page_Content::$_contentAction [protected]
P4Cms_Navigation_Page_Content::$_contentEntry = false [protected]
P4Cms_Navigation_Page_Content::$_contentId [protected]

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