public function getRoleAssignments(APIRole $role)
    {
        if ($this->repository->hasAccess('role', 'read') !== true) {
            throw new UnauthorizedException('role', 'read');
        }

        $userService = $this->repository->getUserService();
        $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByRoleId($role->id);
        $roleAssignments = array();

        foreach ($spiRoleAssignments as $spiRoleAssignment) {
            // First check if the Role is assigned to a User
            // If no User is found, see if it belongs to a UserGroup
            try {
                $user = $userService->loadUser($spiRoleAssignment->contentId);
                $roleAssignments[] = $this->roleDomainMapper->buildDomainUserRoleAssignmentObject(
                    $spiRoleAssignment,
                    $user,
                    $role
                );
            } catch (APINotFoundException $e) {
                try {
                    $userGroup = $userService->loadUserGroup($spiRoleAssignment->contentId);
                    $roleAssignments[] = $this->roleDomainMapper->buildDomainUserGroupRoleAssignmentObject(
                        $spiRoleAssignment,
                        $userGroup,
                        $role
                    );
                } catch (APINotFoundException $e) {
                    // Do nothing
                }
            }
        }

        return $roleAssignments;
    }
public function getRoleAssignments(APIRole $role)
    {
        if ($this->repository->hasAccess('role', 'read') !== true) {
            throw new UnauthorizedException('role', 'read');
        }

        $userService = $this->repository->getUserService();
        $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByRoleId($role->id);
        $roleAssignments = array();

        foreach ($spiRoleAssignments as $spiRoleAssignment) {
            // First check if the Role is assigned to a User
            // If no User is found, see if it belongs to a UserGroup
            try {
                $user = $userService->loadUser($spiRoleAssignment->contentId);
                $roleAssignments[] = $this->roleDomainMapper->buildDomainUserRoleAssignmentObject(
                    $spiRoleAssignment,
                    $user,
                    $role
                );
            } catch (APINotFoundException $e) {
                try {
                    $userGroup = $userService->loadUserGroup($spiRoleAssignment->contentId);
                    $roleAssignments[] = $this->roleDomainMapper->buildDomainUserGroupRoleAssignmentObject(
                        $spiRoleAssignment,
                        $userGroup,
                        $role
                    );
                } catch (APINotFoundException $e) {
                    // Do nothing
                }
            }
        }

        return $roleAssignments;
    }
public function getRoleAssignments ( APIRole $ role ) { if ( $ this -> repository -> hasAccess ( 'role' , 'read' ) !== true ) { throw new UnauthorizedException ( 'role' , 'read' ) ; } $ userService = $ this -> repository -> getUserService ( ) ; $ spiRoleAssignments = $ this -> userHandler -> loadRoleAssignmentsByRoleId ( $ role -> id ) ; $ roleAssignments = array ( ) ; foreach ( $ spiRoleAssignments as $ spiRoleAssignment ) { // First check if the Role is assigned to a User // If no User is found, see if it belongs to a UserGroup try { $ user = $ userService -> loadUser ( $ spiRoleAssignment -> contentId ) ; $ roleAssignments [ ] = $ this -> roleDomainMapper -> buildDomainUserRoleAssignmentObject ( $ spiRoleAssignment , $ user , $ role ) ; } catch ( APINotFoundException $ e ) { try { $ userGroup = $ userService -> loadUserGroup ( $ spiRoleAssignment -> contentId ) ; $ roleAssignments [ ] = $ this -> roleDomainMapper -> buildDomainUserGroupRoleAssignmentObject ( $ spiRoleAssignment , $ userGroup , $ role ) ; } catch ( APINotFoundException $ e ) { // Do nothing } } } return $ roleAssignments ; }
Returns the assigned user and user groups to this role.

@throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role

@param \eZ\Publish\API\Repository\Values\User\Role $role

@return \eZ\Publish\API\Repository\Values\User\RoleAssignment[]
Returns the assigned user and user groups to this role .