/** * {@inheritdoc} */ public function loadOrCreateTags(array $names) { foreach ($names as $key => $tag) { $names[$key] = mb_strtolower($tag, 'UTF8'); } return parent::loadOrCreateTags($names); }
public function saveTagging(BaseTaggable $resource) { $tags = clone $resource->getTags(); parent::saveTagging($resource); if (sizeof($tags) !== sizeof($resource->getTags())) { // parent::saveTagging uses getTags by reference and removes elements, so it ends up empty :-/ // this causes all tags to be deleted when an entity is persisted more than once in a request // Restore: $this->replaceTags($tags->toArray(), $resource); } }
/** * Удалить кампанию * * @param Campaign $campaign * * @Rest\Delete("campaigns/{id}", requirements={"id"="\d+"}) * @ParamConverter("campaign", class="VifeedCampaignBundle:Campaign") * @ApiDoc( * section="Campaign API", * requirements={ * {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="id кампании"} * }, * statusCodes={ * 204="Returned when successful", * 403="Returned when the user is not authorized to use this method", * 404="Returned when campaign not found" * } * ) * * @return Response */ public function deleteCampaignAction(Campaign $campaign) { if ($campaign->getUser() != $this->getUser()) { throw new AccessDeniedHttpException('Можно удалять только свои кампании'); } $this->tagManager->deleteTagging($campaign); $this->em->remove($campaign); $this->em->flush(); $view = new View('', 204); return $this->handleView($view); }
/** * Удалить площадку * * @param Platform $platform * * @Rest\Delete("platforms/{id}", requirements={"id"="\d+"}) * @ParamConverter("platform", class="VifeedPlatformBundle:Platform") * @ApiDoc( * section="Platform API", * requirements={ * {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="id площадки"} * }, * statusCodes={ * 204="Returned when successful", * 403="Returned when the user is not authorized to use this method", * 404="Returned when platform not found" * } * ) * * @return Response */ public function deletePlatformAction(Platform $platform) { if ($platform->getUser() != $this->getUser()) { throw new AccessDeniedHttpException('Можно удалять только свои площадки'); } $this->tagManager->deleteTagging($platform); $this->em->remove($platform); $this->em->flush(); $view = new View('', 204); return $this->handleView($view); }
/** * Persist product (Add or update) * * @param Product $product * @param $tags * @return Product */ private function persistProduct(Product $product, $tags) { $tags = $this->tagManager->splitTagNames($tags); foreach ($tags as $tag) { $singleTag = $this->tagManager->loadOrCreateTag(trim($tag)); $this->tagManager->addTag($singleTag, $product); } $this->entityManager->persist($product); $this->entityManager->flush(); $this->tagManager->saveTagging($product); return $product; }
/** * @see DoctrineExtensions\Taggable\TagManager::createTag() */ protected function createTag($name) { $tag = parent::createTag($name); $tag->setSlug($this->slugifier->slugify($name)); return $tag; }