예제 #1
0
 /**
  * Returns the number of content objects related to $tag.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to read tags
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified tag is not found
  *
  * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag
  *
  * @return int
  */
 public function getRelatedContentCount(Tag $tag)
 {
     if ($this->hasAccess('tags', 'read') !== true) {
         throw new UnauthorizedException('tags', 'read');
     }
     $spiTagInfo = $this->tagsHandler->loadTagInfo($tag->id);
     $relatedContentIds = $this->tagsHandler->loadRelatedContentIds($spiTagInfo->id);
     if (empty($relatedContentIds)) {
         return 0;
     }
     $searchResult = $this->repository->getSearchService()->findContent(new Query(array('limit' => 0, 'filter' => new ContentId($relatedContentIds))));
     return $searchResult->totalCount;
 }