public function getPermissions($permission, $user, $creator = null)
{
if (is_string($permission)) {
try {
$permission = $this->getPermission($permission);
} catch (Horde_Perms_Exception $e) {
/* Ignore not exists errors. */
if ($this->_logger && $e->getCode() != Horde_Perms_Exception::NOT_EXIST) {
$this->_logger->log($e, 'DEBUG');
}
return false;
}
}
// If this is a guest user, only check guest permissions.
if (empty($user)) {
return $permission->getGuestPermissions();
}
// Combine all other applicable permissions.
$type = $permission->get('type');
$composite_perm = $type == 'matrix' ? 0 : array();
// If $creator was specified, check creator permissions.
// If the user is the creator of the event see if there are creator
// permissions.
if (!is_null($creator) && strlen($user) && $user === $creator && ($perms = $permission->getCreatorPermissions()) !== null) {
if ($type == 'matrix') {
$composite_perm |= $perms;
} else {
$composite_perm[] = $perms;
}
}
// Check user-level permissions.
$userperms = $permission->getUserPermissions();
if (isset($userperms[$user])) {
if ($type == 'matrix') {
$composite_perm |= $userperms[$user];
} else {
$composite_perm[] = $userperms[$user];
}
}
// If no user permissions are found, try group permissions.
if (isset($permission->data['groups']) && is_array($permission->data['groups']) && count($permission->data['groups'])) {
$groups = $GLOBALS['injector']->getInstance('Horde_Group')->listGroups($user);
foreach ($permission->data['groups'] as $group => $perms) {
if (isset($groups[$group])) {
if ($type == 'matrix') {
$composite_perm |= $perms;
} else {
$composite_perm[] = $perms;
}
}
}
}
// If there are default permissions, return them.
if (($perms = $permission->getDefaultPermissions()) !== null) {
if ($type == 'matrix') {
$composite_perm |= $perms;
} else {
$composite_perm[] = $perms;
}
}
// Return composed permissions.
if ($composite_perm) {
return $composite_perm;
}
// Otherwise, deny all permissions to the object.
return false;
}