protected function assignRole(Role $role, RoleService $roleService, UserService $userService, array $assignments)
    {
        foreach ($assignments as $assign) {
            switch ($assign['type']) {
                case 'user':
                    foreach ($assign['ids'] as $userId) {
                        $userId = $this->referenceResolver->resolveReference($userId);

                        $user = $userService->loadUser($userId);

                        if (!isset($assign['limitations'])) {
                            $roleService->assignRoleToUser($role, $user);
                        } else {
                            foreach ($assign['limitations'] as $limitation) {
                                $limitationObject = $this->createLimitation($roleService, $limitation);
                                $roleService->assignRoleToUser($role, $user, $limitationObject);
                            }
                        }
                    }
                    break;
                case 'group':
                    foreach ($assign['ids'] as $groupId) {
                        $groupId = $this->referenceResolver->resolveReference($groupId);

                        $group = $userService->loadUserGroup($groupId);

                        if (!isset($assign['limitations'])) {
                            // q: why are we swallowing exceptions here ?
                            //try {
                                $roleService->assignRoleToUserGroup($role, $group);
                            //} catch (InvalidArgumentException $e) {}
                        } else {
                            foreach ($assign['limitations'] as $limitation) {
                                $limitationObject = $this->createLimitation($roleService, $limitation);
                                // q: why are we swallowing exceptions here ?
                                //try {
                                    $roleService->assignRoleToUserGroup($role, $group, $limitationObject);
                                //} catch (InvalidArgumentException $e) {}
                            }
                        }
                    }
                    break;
            }
        }
    }
protected function assignRole(Role $role, RoleService $roleService, UserService $userService, array $assignments)
    {
        foreach ($assignments as $assign) {
            switch ($assign['type']) {
                case 'user':
                    foreach ($assign['ids'] as $userId) {
                        $userId = $this->referenceResolver->resolveReference($userId);

                        $user = $userService->loadUser($userId);

                        if (!isset($assign['limitations'])) {
                            $roleService->assignRoleToUser($role, $user);
                        } else {
                            foreach ($assign['limitations'] as $limitation) {
                                $limitationObject = $this->createLimitation($roleService, $limitation);
                                $roleService->assignRoleToUser($role, $user, $limitationObject);
                            }
                        }
                    }
                    break;
                case 'group':
                    foreach ($assign['ids'] as $groupId) {
                        $groupId = $this->referenceResolver->resolveReference($groupId);

                        $group = $userService->loadUserGroup($groupId);

                        if (!isset($assign['limitations'])) {
                            // q: why are we swallowing exceptions here ?
                            //try {
                                $roleService->assignRoleToUserGroup($role, $group);
                            //} catch (InvalidArgumentException $e) {}
                        } else {
                            foreach ($assign['limitations'] as $limitation) {
                                $limitationObject = $this->createLimitation($roleService, $limitation);
                                // q: why are we swallowing exceptions here ?
                                //try {
                                    $roleService->assignRoleToUserGroup($role, $group, $limitationObject);
                                //} catch (InvalidArgumentException $e) {}
                            }
                        }
                    }
                    break;
            }
        }
    }
protected function assignRole ( Role $ role , RoleService $ roleService , UserService $ userService , array $ assignments ) { foreach ( $ assignments as $ assign ) { switch ( $ assign [ 'type' ] ) { case 'user' : foreach ( $ assign [ 'ids' ] as $ userId ) { $ userId = $ this -> referenceResolver -> resolveReference ( $ userId ) ; $ user = $ userService -> loadUser ( $ userId ) ; if ( ! isset ( $ assign [ 'limitations' ] ) ) { $ roleService -> assignRoleToUser ( $ role , $ user ) ; } else { foreach ( $ assign [ 'limitations' ] as $ limitation ) { $ limitationObject = $ this -> createLimitation ( $ roleService , $ limitation ) ; $ roleService -> assignRoleToUser ( $ role , $ user , $ limitationObject ) ; } } } break ; case 'group' : foreach ( $ assign [ 'ids' ] as $ groupId ) { $ groupId = $ this -> referenceResolver -> resolveReference ( $ groupId ) ; $ group = $ userService -> loadUserGroup ( $ groupId ) ; if ( ! isset ( $ assign [ 'limitations' ] ) ) { // q: why are we swallowing exceptions here ? //try { $ roleService -> assignRoleToUserGroup ( $ role , $ group ) ; //} catch (InvalidArgumentException $e) {} } else { foreach ( $ assign [ 'limitations' ] as $ limitation ) { $ limitationObject = $ this -> createLimitation ( $ roleService , $ limitation ) ; // q: why are we swallowing exceptions here ? //try { $ roleService -> assignRoleToUserGroup ( $ role , $ group , $ limitationObject ) ; //} catch (InvalidArgumentException $e) {} } } } break ; } } }
Assign a role to users and groups in the assignment array.

<pre>
$assignments = array(
array(
'type' => 'user',
'ids' => array(user ids),
'limitation' => array(limitations)
)
)
</pre>

@param \eZ\Publish\API\Repository\Values\User\Role $role
@param \eZ\Publish\API\Repository\RoleService $roleService
@param \eZ\Publish\API\Repository\UserService $userService
@param array $assignments
Assign a role to users and groups in the assignment array .