eZ\Publish\Core\Repository\UserService::loadUserGroupsOfUser PHP Method

loadUserGroupsOfUser() public method

Loads the user groups the user belongs to.
public loadUserGroupsOfUser ( eZ\Publish\API\Repository\Values\User\User $user, integer $offset, integer $limit = 25 ) : eZ\Publish\API\Repository\Values\User\UserGroup[]
$user eZ\Publish\API\Repository\Values\User\User
$offset integer the start offset for paging
$limit integer the number of user groups returned
return eZ\Publish\API\Repository\Values\User\UserGroup[]
    public function loadUserGroupsOfUser(APIUser $user, $offset = 0, $limit = 25)
    {
        $locationService = $this->repository->getLocationService();
        if (!$this->repository->canUser('content', 'read', $user)) {
            throw new UnauthorizedException('content', 'read');
        }
        $userLocations = $locationService->loadLocations($user->getVersionInfo()->getContentInfo());
        $parentLocationIds = array();
        foreach ($userLocations as $userLocation) {
            if ($userLocation->parentLocationId !== null) {
                $parentLocationIds[] = $userLocation->parentLocationId;
            }
        }
        $searchQuery = new LocationQuery();
        $searchQuery->offset = $offset;
        $searchQuery->limit = $limit;
        $searchQuery->performCount = false;
        $searchQuery->filter = new CriterionLogicalAnd(array(new CriterionContentTypeId($this->settings['userGroupClassID']), new CriterionLocationId($parentLocationIds)));
        $searchResult = $this->repository->getSearchService()->findLocations($searchQuery);
        $userGroups = array();
        foreach ($searchResult->searchHits as $resultItem) {
            $userGroups[] = $this->buildDomainUserGroupObject($this->repository->getContentService()->internalLoadContent($resultItem->valueObject->contentInfo->id));
        }
        return $userGroups;
    }