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

loadSubUserGroups() public method

Loads the sub groups of a user group.
public loadSubUserGroups ( eZ\Publish\API\Repository\Values\User\UserGroup $userGroup, integer $offset, integer $limit = 25 ) : eZ\Publish\API\Repository\Values\User\UserGroup[]
$userGroup eZ\Publish\API\Repository\Values\User\UserGroup
$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 loadSubUserGroups(APIUserGroup $userGroup, $offset = 0, $limit = 25)
    {
        $locationService = $this->repository->getLocationService();
        $loadedUserGroup = $this->loadUserGroup($userGroup->id);
        if (!$this->repository->canUser('content', 'read', $loadedUserGroup)) {
            throw new UnauthorizedException('content', 'read');
        }
        if ($loadedUserGroup->getVersionInfo()->getContentInfo()->mainLocationId === null) {
            return array();
        }
        $mainGroupLocation = $locationService->loadLocation($loadedUserGroup->getVersionInfo()->getContentInfo()->mainLocationId);
        $searchResult = $this->searchSubGroups($mainGroupLocation, $offset, $limit);
        if ($searchResult->totalCount == 0) {
            return array();
        }
        $subUserGroups = array();
        foreach ($searchResult->searchHits as $searchHit) {
            $subUserGroups[] = $this->buildDomainUserGroupObject($this->repository->getContentService()->internalLoadContent($searchHit->valueObject->contentInfo->id));
        }
        return $subUserGroups;
    }