public function assignUserToUserGroup($userId, Request $request)
    {
        $user = $this->userService->loadUser($userId);

        try {
            $userGroupLocation = $this->locationService->loadLocation(
                $this->extractLocationIdFromPath($request->query->get('group'))
            );
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        try {
            $userGroup = $this->userService->loadUserGroup(
                $userGroupLocation->contentId
            );
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        try {
            $this->userService->assignUserToUserGroup($user, $userGroup);
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        $userGroups = $this->userService->loadUserGroupsOfUser($user);
        $restUserGroups = array();
        foreach ($userGroups as $userGroup) {
            $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
            $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
            $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);

            $restUserGroups[] = new Values\RestUserGroup(
                $userGroup,
                $contentType,
                $userGroupContentInfo,
                $userGroupLocation,
                $this->contentService->loadRelations($userGroup->getVersionInfo())
            );
        }

        return new Values\UserGroupRefList(
            $restUserGroups,
            $this->router->generate(
                'ezpublish_rest_loadUserGroupsOfUser',
                array('userId' => $userId)
            ),
            $userId
        );
    }
public function assignUserToUserGroup($userId, Request $request)
    {
        $user = $this->userService->loadUser($userId);

        try {
            $userGroupLocation = $this->locationService->loadLocation(
                $this->extractLocationIdFromPath($request->query->get('group'))
            );
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        try {
            $userGroup = $this->userService->loadUserGroup(
                $userGroupLocation->contentId
            );
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        try {
            $this->userService->assignUserToUserGroup($user, $userGroup);
        } catch (ApiExceptions\NotFoundException $e) {
            throw new Exceptions\ForbiddenException($e->getMessage());
        }

        $userGroups = $this->userService->loadUserGroupsOfUser($user);
        $restUserGroups = array();
        foreach ($userGroups as $userGroup) {
            $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
            $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
            $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);

            $restUserGroups[] = new Values\RestUserGroup(
                $userGroup,
                $contentType,
                $userGroupContentInfo,
                $userGroupLocation,
                $this->contentService->loadRelations($userGroup->getVersionInfo())
            );
        }

        return new Values\UserGroupRefList(
            $restUserGroups,
            $this->router->generate(
                'ezpublish_rest_loadUserGroupsOfUser',
                array('userId' => $userId)
            ),
            $userId
        );
    }
public function assignUserToUserGroup ( $ userId , Request $ request ) { $ user = $ this -> userService -> loadUser ( $ userId ) ; try { $ userGroupLocation = $ this -> locationService -> loadLocation ( $ this -> extractLocationIdFromPath ( $ request -> query -> get ( 'group' ) ) ) ; } catch ( ApiExceptions \ NotFoundException $ e ) { throw new Exceptions \ ForbiddenException ( $ e -> getMessage ( ) ) ; } try { $ userGroup = $ this -> userService -> loadUserGroup ( $ userGroupLocation -> contentId ) ; } catch ( ApiExceptions \ NotFoundException $ e ) { throw new Exceptions \ ForbiddenException ( $ e -> getMessage ( ) ) ; } try { $ this -> userService -> assignUserToUserGroup ( $ user , $ userGroup ) ; } catch ( ApiExceptions \ NotFoundException $ e ) { throw new Exceptions \ ForbiddenException ( $ e -> getMessage ( ) ) ; } $ userGroups = $ this -> userService -> loadUserGroupsOfUser ( $ user ) ; $ restUserGroups = array ( ) ; foreach ( $ userGroups as $ userGroup ) { $ userGroupContentInfo = $ userGroup -> getVersionInfo ( ) -> getContentInfo ( ) ; $ userGroupLocation = $ this -> locationService -> loadLocation ( $ userGroupContentInfo -> mainLocationId ) ; $ contentType = $ this -> contentTypeService -> loadContentType ( $ userGroupContentInfo -> contentTypeId ) ; $ restUserGroups [ ] = new Values \ RestUserGroup ( $ userGroup , $ contentType , $ userGroupContentInfo , $ userGroupLocation , $ this -> contentService -> loadRelations ( $ userGroup -> getVersionInfo ( ) ) ) ; } return new Values \ UserGroupRefList ( $ restUserGroups , $ this -> router -> generate ( 'ezpublish_rest_loadUserGroupsOfUser' , array ( 'userId' => $ userId ) ) , $ userId ) ; }
Assigns the user to a user group.

@param $userId

@throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException

@return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList
Assigns the user to a user group .