/** * Returns true if the role of the current user has the given privilege * * @param string $privilege * @return bool */ public function hasPrivilege($privilege) { return !$this->acl || $this->acl->isAllowed($this->getRole(), null, $privilege); }
/** * Set the visibility of the menu item and any sub items in accordance * with the specified user role. * * @param \Zend_Acl $acl * @param string $userRole * @return \Gems_Menu_MenuAbstract (continuation pattern) */ protected function applyAcl(\MUtil_Acl $acl, $userRole) { if ($this->_subItems) { foreach ($this->_subItems as $item) { $allowed = $item->get('allowed', true); if ($allowed && ($privilege = $item->get('privilege'))) { $allowed = $acl->isAllowed($userRole, null, $privilege); } if ($allowed) { $item->applyAcl($acl, $userRole); } else { // As an item can be invisible but allowed, // but not disallowed but visible we need to // set both. $item->set('allowed', false); $item->set('visible', false); $item->setForChildren('allowed', false); $item->setForChildren('visible', false); } } } return $this; }