/**
  * @param ContentInterface $content
  *
  * @return array
  */
 protected function extractMediasFromContent(ContentInterface $content)
 {
     $references = array();
     /** @var ContentAttributeInterface $attribute */
     foreach ($content->getAttributes() as $attribute) {
         $references = array_merge($references, $this->extractMediasFromElement($attribute->getValue()));
     }
     return $references;
 }
 /**
  * Transform the object to be indexed by Elasticsearch
  *
  * @param ContentInterface $content
  *
  * @return Document
  */
 public function transform($content)
 {
     $keywords = array();
     foreach ($content->getKeywords() as $keyword) {
         $keywords[] = $keyword->getLabel();
     }
     $documentData = array('id' => $content->getContentId() . '-' . $content->getLanguage(), 'elementId' => $content->getId(), 'contentId' => $content->getContentId(), 'name' => $content->getName(), 'siteId' => $content->getSiteId(), 'linkedToSite' => $content->isLinkedToSite(), 'language' => $content->getLanguage(), 'contentType' => $content->getContentType(), 'keywords' => implode(',', $keywords), 'updatedAt' => $content->getUpdatedAt()->getTimestamp());
     /** @var ContentAttributeInterface $attribute */
     foreach ($content->getAttributes() as $attribute) {
         if (null !== $attribute->getValue() && '' !== $attribute->getValue()) {
             $documentData['attribute_' . $attribute->getName()] = $attribute->getValue();
             $documentData['attribute_' . $attribute->getName() . '_stringValue'] = $attribute->getStringValue();
         }
     }
     return new Document($documentData['id'], $documentData);
 }
 /**
  * @param ContentInterface $content
  *
  * @return FacadeInterface
  *
  * @throws TransformerParameterTypeException
  */
 public function transform($content)
 {
     if (!$content instanceof ContentInterface) {
         throw new TransformerParameterTypeException();
     }
     $contentType = $this->contentTypeRepository->findOneByContentTypeIdInLastVersion($content->getContentType());
     $facade = $this->newFacade();
     $facade->id = $content->getContentId();
     $facade->contentType = $content->getContentType();
     $facade->name = $content->getName();
     $facade->version = $content->getVersion();
     $facade->contentTypeVersion = $content->getContentTypeVersion();
     $facade->language = $content->getLanguage();
     $facade->status = $this->getTransformer('status')->transform($content->getStatus());
     $facade->statusLabel = $facade->status->label;
     $facade->createdAt = $content->getCreatedAt();
     $facade->updatedAt = $content->getUpdatedAt();
     $facade->createdBy = $content->getCreatedBy();
     $facade->updatedBy = $content->getUpdatedBy();
     $facade->deleted = $content->isDeleted();
     $facade->linkedToSite = $content->isLinkedToSite();
     foreach ($content->getAttributes() as $attribute) {
         $contentAttribute = $this->getTransformer('content_attribute')->transform($attribute);
         $facade->addAttribute($contentAttribute);
     }
     if ($this->authorizationChecker->isGranted(ContentTypeForContentPanelStrategy::ROLE_ACCESS_CONTENT_TYPE_FOR_CONTENT)) {
         if ($this->authorizationChecker->isGranted(ContentTypeForContentPanelStrategy::ROLE_ACCESS_UPDATE_CONTENT_TYPE_FOR_CONTENT) && !$content->getStatus()->isBlockedEdition()) {
             $facade->addLink('_self_form', $this->generateRoute('open_orchestra_backoffice_content_form', array('contentId' => $content->getContentId(), 'language' => $content->getLanguage(), 'version' => $content->getVersion())));
         }
         if ($this->authorizationChecker->isGranted(ContentTypeForContentPanelStrategy::ROLE_ACCESS_CREATE_CONTENT_TYPE_FOR_CONTENT) && $contentType->isDefiningVersionable()) {
             $facade->addLink('_self_new_version', $this->generateRoute('open_orchestra_api_content_new_version', array('contentId' => $content->getContentId(), 'language' => $content->getLanguage(), 'version' => $content->getVersion())));
             $facade->addLink('_self_duplicate', $this->generateRoute('open_orchestra_api_content_duplicate', array('contentId' => $content->getContentId())));
         }
         if ($this->authorizationChecker->isGranted(ContentTypeForContentPanelStrategy::ROLE_ACCESS_DELETE_CONTENT_TYPE_FOR_CONTENT) && !$content->isUsed()) {
             $facade->addLink('_self_delete', $this->generateRoute('open_orchestra_api_content_delete', array('contentId' => $content->getId())));
         }
     }
     if ($contentType->isDefiningVersionable()) {
         $facade->addLink('_self_version', $this->generateRoute('open_orchestra_api_content_list_version', array('contentId' => $content->getContentId(), 'language' => $content->getLanguage())));
     }
     $facade->addLink('_self', $this->generateRoute('open_orchestra_api_content_show_or_create', array('contentId' => $content->getContentId(), 'version' => $content->getVersion(), 'language' => $content->getLanguage())));
     $facade->addLink('_self_without_parameters', $this->generateRoute('open_orchestra_api_content_show_or_create', array('contentId' => $content->getContentId())));
     $facade->addLink('_language_list', $this->generateRoute('open_orchestra_api_parameter_languages_show'));
     $facade->addLink('_status_list', $this->generateRoute('open_orchestra_api_content_list_status', array('contentMongoId' => $content->getId())));
     $facade->addLink('_self_status_change', $this->generateRoute('open_orchestra_api_content_update', array('contentMongoId' => $content->getId())));
     return $facade;
 }
 /**
  * @param ContentInterface $content
  *
  * @return ContentInterface
  */
 protected function cloneContent(ContentInterface $content)
 {
     $newContent = clone $content;
     $newContent->setCurrentlyPublished(false);
     $newContent->setStatus(null);
     foreach ($content->getKeywords() as $keyword) {
         $newContent->addKeyword($keyword);
     }
     foreach ($content->getAttributes() as $attribute) {
         $newAttribute = clone $attribute;
         $newContent->addAttribute($newAttribute);
     }
     return $newContent;
 }