/**
  * Extract content seo urls.
  *
  * @param Content         $content
  * @param ContentDocument $document
  */
 private function extractUrls(Content $content, $document)
 {
     $urls = [];
     $seoUrls = $content->getSeoUrls();
     if (count($seoUrls) > 0) {
         foreach ($seoUrls as $seo) {
             if ($seo->getLang() === $this->languageId) {
                 /** @var Seo $seo */
                 $urlObject = new UrlNested();
                 $urlObject->setUrl($seo->getSeoUrl());
                 $urls[] = $urlObject;
             }
         }
     }
     $document->setUrls(new \ArrayIterator($urls));
     $document->setExpiredUrls([]);
 }
示例#2
0
 /**
  * @param Category|Content|Article $entity
  * @param int|null                 $languageId
  *
  * @return Seo[]
  *
  * @throws \InvalidArgumentException
  */
 public function getEntitySeo($entity, $languageId = null)
 {
     if ($entity instanceof Category) {
         $type = 'oxcategory';
     } elseif ($entity instanceof Article) {
         $type = 'oxarticle';
     } elseif ($entity instanceof Content) {
         $type = 'oxcontent';
     } else {
         throw new \InvalidArgumentException();
     }
     $queryBuilder = $this->getEntityManager()->getRepository($this->getRepository())->createQueryBuilder('s');
     $queryBuilder->where('s.type = :type')->andWhere('s.objectId = :id')->andWhere('s.shopId = :shopId');
     $parameters = ['type' => $type, 'id' => $entity->getId(), 'shopId' => $this->getShopId()];
     if ($languageId !== null) {
         $queryBuilder->andWhere('s.lang = :lang');
         $parameters['lang'] = $languageId;
     }
     $query = $queryBuilder->getQuery()->setParameters($parameters);
     return $query->getResult();
 }
 /**
  * Transforms Content entity into ES document.
  *
  * @param Content         $content
  * @param ContentDocument $document
  */
 public function transformContentToDocument(Content $content, ContentDocument $document)
 {
     $document->setId($content->getId());
     $document->setTitle($content->getTitle());
     $document->setContent($content->getContent());
     $document->setFolder($content->getFolder());
     $document->setSlug($content->getLoadId());
     $document->setSnippet($content->isSnippet());
     $document->setType($content->getType());
     $document->setActive($content->isActive());
     $document->setPosition($content->getPosition());
     $this->extractUrls($content, $document);
 }