Perforce Chronicle 2012.2/486814
API Documentation

Content_Acl_Assert_IsOwner Class Reference

Check if the active user owns the given content resource. More...

List of all members.

Public Member Functions

 assert (Zend_Acl $acl, Zend_Acl_Role_Interface $role=null, Zend_Acl_Resource_Interface $resource=null, $privilege=null)
 Checks if the active user owns the given content resource.

Detailed Description

Check if the active user owns the given content resource.

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

Content_Acl_Assert_IsOwner::assert ( Zend_Acl $  acl,
Zend_Acl_Role_Interface $  role = null,
Zend_Acl_Resource_Interface $  resource = null,
privilege = null 
)

Checks if the active user owns the given content resource.

Parameters:
Zend_Acl$aclthe acl instance
Zend_Acl_Role_Interface$rolethe role to check access for
Zend_Acl_Resource_Interface$resourcethe resource (should be content/*)
string$privilegethe privilege (should be edit)
Returns:
boolean true if the active user owns the given content resource.
    {
        // early exit if resource doesn't match content/*
        if (!preg_match('#^content/(.+)$#', $resource->getResourceId(), $matches)) {
            return false;
        }

        // grab active user, or return false if no named active user.
        if (P4Cms_User::hasActive() && !P4Cms_User::fetchActive()->isAnonymous()) {
            $user = P4Cms_User::fetchActive();
        } else {
            return false;
        }

        // fetch content entry, or return false if entry does not exist.
        $id      = $matches[1];
        $options = array('includeDeleted' => true);
        if (P4Cms_Content::exists($id, $options)) {
            $entry = P4Cms_Content::fetch($id, $options);
        } else {
            return false;
        }

        // check if user is owner of content entry.
        if ($entry->getOwner() == $user->getId()) {
            return true;
        } else {
            return false;
        }
    }

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