Exemple #1
0
 /**
  * Updates a tag.
  *
  * @param string $tagPath
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Netgen\TagsBundle\Core\REST\Server\Values\RestTag
  */
 public function updateTag($tagPath, Request $request)
 {
     $tagUpdateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
     $tag = $this->tagsService->loadTag($this->extractTagIdFromPath($tagPath));
     $updatedTag = $this->tagsService->updateTag($tag, $tagUpdateStruct);
     $childrenCount = 0;
     $synonymsCount = 0;
     if (empty($updatedTag->mainTagId)) {
         $childrenCount = $this->tagsService->getTagChildrenCount($updatedTag);
         $synonymsCount = $this->tagsService->getTagSynonymCount($updatedTag);
     }
     return new Values\RestTag($updatedTag, $childrenCount, $synonymsCount);
 }
Exemple #2
0
 /**
  * @covers \Netgen\TagsBundle\Core\Repository\TagsService::convertToSynonym
  * @depends testLoadTag
  * @depends testGetTagSynonymCount
  * @depends testGetTagChildrenCount
  */
 public function testConvertToSynonym()
 {
     $tag = $this->tagsService->loadTag(16);
     $mainTag = $this->tagsService->loadTag(40);
     $convertedSynonym = $this->tagsService->convertToSynonym($tag, $mainTag);
     $this->assertInstanceOf('\\Netgen\\TagsBundle\\API\\Repository\\Values\\Tags\\Tag', $convertedSynonym);
     $this->assertPropertiesCorrect(array('id' => $tag->id, 'parentTagId' => $mainTag->parentTagId, 'mainTagId' => $mainTag->id, 'keyword' => $tag->keyword, 'depth' => $mainTag->depth, 'pathString' => $this->getSynonymPathString($convertedSynonym->id, $mainTag->pathString), 'remoteId' => $tag->remoteId), $convertedSynonym);
     $this->assertInstanceOf('\\DateTime', $convertedSynonym->modificationDate);
     $this->assertGreaterThan($tag->modificationDate->getTimestamp(), $convertedSynonym->modificationDate->getTimestamp());
     $synonymsCount = $this->tagsService->getTagSynonymCount($mainTag);
     $this->assertEquals(3, $synonymsCount);
     $childrenCount = $this->tagsService->getTagChildrenCount($mainTag);
     $this->assertEquals(6, $childrenCount);
 }
 /**
  * Returns the number of synonyms of a tag object.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to read tags
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the tag is already a synonym
  *
  * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag
  * @param array|null $languages A language filter for keywords. If not given all languages are returned.
  * @param bool $useAlwaysAvailable Add main language to $languages if true (default) and if tag is always available
  *
  * @return int
  */
 public function getTagSynonymCount(Tag $tag, array $languages = null, $useAlwaysAvailable = true)
 {
     return $this->service->getTagSynonymCount($tag, $languages, $useAlwaysAvailable);
 }