/** * Returns list of role assignments for specific role and content. * * @param \eZ\Publish\API\Repository\Values\User\Role $role * @param int $contentId * * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[] */ private function getRoleAssignmentsForRoleAndContent(Role $role, $contentId) { $contentService = $this->repository->getContentService(); $contentTypeService = $this->repository->getContentTypeService(); $userService = $this->repository->getUserService(); $contentType = $contentTypeService->loadContentType($contentService->loadContent($contentId)->contentTypeId); if ($contentType->identifier != 'user_group' && $contentType->identifier != 'user') { throw new \ErrorException("Implementation error, unknown contentType '{$contentType->identifier}'."); } $roleAssignments = array(); foreach ($this->roleLimitations as $limit) { if ($limit['roleId'] == $role->id && $limit['contentId'] == $contentId) { $limitIdentifier = $limit['identifier']; if (!isset($roleAssignments[$limitIdentifier])) { if ('user_group' === $contentType->identifier) { $roleAssignments[$limitIdentifier] = new UserGroupRoleAssignmentStub(array('role' => $role, 'userGroup' => $userService->loadUserGroup($contentId), 'limitation' => $this->getOptionalRoleLimitation($role->id, $contentId, $limitIdentifier))); } else { if ('user' === $contentType->identifier) { $roleAssignments[$limitIdentifier] = new UserRoleAssignmentStub(array('role' => $role, 'user' => $userService->loadUser($contentId), 'limitation' => $this->getOptionalRoleLimitation($role->id, $contentId, $limitIdentifier))); } } } } } if (empty($roleAssignments)) { if ('user_group' === $contentType->identifier) { $roleAssignments[] = new UserGroupRoleAssignmentStub(array('role' => $role, 'userGroup' => $userService->loadUserGroup($contentId), 'limitation' => null)); } else { if ('user' === $contentType->identifier) { $roleAssignments[] = new UserRoleAssignmentStub(array('role' => $role, 'user' => $userService->loadUser($contentId), 'limitation' => null)); } } } return array_values($roleAssignments); }