/** * Determines whether a page should be accepted when iterating using ACL * * Validates that the role set in helper inherits or is the same as * the role(s) found in the page * * @param Zym_Navigation_Page $page page to check * @param bool $recursive [optional] whether it should check recursively * @return bool */ protected function _acceptAcl(Zym_Navigation_Page $page, $recursive = true) { if (!($acl = $this->getAcl())) { // no acl registered means don't use acl return true; } // do not accept by default $accept = false; // do not accept if helper has no role if ($role = $this->getRole()) { $resource = $page->getResource(); $privilege = $page->getPrivilege(); if ($resource || $privilege) { // determine using helper role and page resource/privilege $accept = $this->getAcl()->isAllowed($role, $resource, $privilege); } else { // accept if page has no resource or privilege $accept = true; } } // loop parent(s) recursively if page is accepted and recurisve is true if ($accept && $recursive) { $parent = $page->getParent(); if ($parent instanceof Zym_Navigation_Page) { $accept = $this->_acceptAcl($parent, true); } } return $accept; }
/** * Determines whether a page should be accepted when iterating using ACL * * Validates that the role set in helper inherits or is the same as * the role(s) found in the page * * @return bool */ protected function _acceptAcl(Zym_Navigation_Page $page, $recursive = true) { // do not accept by default $accept = false; if (!($helperRole = $this->getRole())) { // don't accept if helper has no role return false; } if (!($pageRole = $page->getRole())) { // accept it if page has no role $accept = true; } else { // loop all roles foreach ($helperRole as $hRole) { foreach ($pageRole as $pRole) { if ($hRole == $pRole || $this->_acl->inheritsRole($hRole, $pRole)) { $accept = true; break; } } if ($accept) { break; } } } // loop parent(s) recursively if page is accepted and recurisve is true if ($accept && $recursive) { $parent = $page->getParent(); if ($parent instanceof Zym_Navigation_Page) { $accept = $this->_acceptAcl($parent, true); } } return $accept; }