/**
  * Returns an slice of the results.
  *
  * @param int $offset The offset.
  * @param int $length The length.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content[]
  */
 public function getSlice($offset, $length)
 {
     $relatedContent = $this->tagsService->getRelatedContent($this->tag, $offset, $length);
     if (!isset($this->nbResults)) {
         $this->nbResults = $this->tagsService->getRelatedContentCount($this->tag);
     }
     return $relatedContent;
 }
Exemplo n.º 2
0
 /**
  * Returns content related to a tag.
  *
  * @param string $tagPath
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Netgen\TagsBundle\Core\REST\Server\Values\CachedValue
  */
 public function getRelatedContent($tagPath, Request $request)
 {
     $offset = $request->query->has('offset') ? (int) $request->query->get('offset') : 0;
     $limit = $request->query->has('limit') ? (int) $request->query->get('limit') : 25;
     $tagId = $this->extractTagIdFromPath($tagPath);
     $relatedContent = $this->tagsService->getRelatedContent($this->tagsService->loadTag($tagId), $offset >= 0 ? $offset : 0, $limit >= 0 ? $limit : 25, true);
     $restContent = array();
     foreach ($relatedContent as $contentInfo) {
         $restContent[] = new BaseValues\RestContent($contentInfo);
     }
     return new Values\CachedValue(new Values\ContentList($restContent, $request->getPathInfo()), array('tagId' => $tagId));
 }
Exemplo n.º 3
0
 /**
  * Loads content 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
  * @param int $offset The start offset for paging
  * @param int $limit The number of content objects returned. If $limit = -1 all content objects starting at $offset are returned
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content[]
  */
 public function getRelatedContent(Tag $tag, $offset = 0, $limit = -1)
 {
     return $this->service->getRelatedContent($tag, $offset, $limit);
 }
Exemplo n.º 4
0
 /**
  * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
  *
  * @covers \Netgen\TagsBundle\Core\Repository\TagsService::getRelatedContent
  */
 public function testGetRelatedContentThrowsUnauthorizedException()
 {
     $this->repository->setCurrentUser($this->getStubbedUser(10));
     $this->tagsService->getRelatedContent(new Tag(array('id' => 40)));
 }
Exemplo n.º 5
0
 /**
  * Loads content 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
  * @param int $offset The start offset for paging
  * @param int $limit The number of content objects returned. If $limit = -1 all content objects starting at $offset are returned
  * @param bool $returnContentInfo
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content[]|\eZ\Publish\API\Repository\Values\Content\ContentInfo[]
  */
 public function getRelatedContent(Tag $tag, $offset = 0, $limit = -1, $returnContentInfo = false)
 {
     return $this->service->getRelatedContent($tag, $offset, $limit, $returnContentInfo);
 }