/**
  * @param ContentInterface $content
  */
 public function restore($content)
 {
     $contents = $this->contentRepository->findByContentId($content->getContentId());
     /** @var ContentInterface $content */
     foreach ($contents as $content) {
         $content->setDeleted(false);
     }
     $this->eventDispatcher->dispatch(ContentEvents::CONTENT_RESTORE, new ContentEvent($content));
 }
 /**
  * @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;
 }
 /**
  * Vote for $action on $content not owned by $user
  * A user can act on someone else's content if he has the matching super role and the content is in his perimeter
  *
  * @param string           $action
  * @param ContentInterface $content
  * @param UserInterface    $user
  *
  * @return bool
  */
 protected function voteForSomeoneElseSubject($action, $content, UserInterface $user)
 {
     $requiredRole = ContributionRoleInterface::CONTENT_CONTRIBUTOR;
     switch ($action) {
         case ContributionActionInterface::EDIT:
             $requiredRole = ContributionRoleInterface::CONTENT_SUPER_EDITOR;
             break;
         case ContributionActionInterface::DELETE:
             $requiredRole = ContributionRoleInterface::CONTENT_SUPER_SUPRESSOR;
             break;
     }
     return $user->hasRole($requiredRole) && $this->isSubjectInPerimeter($content->getContentType(), $user, ContentInterface::ENTITY_TYPE);
 }
 /**
  * @param ContentInterface $content
  *
  * @throws IndexorWrongParameterException
  */
 public function delete($content)
 {
     if (!$content instanceof ContentInterface) {
         throw new IndexorWrongParameterException();
     }
     $index = $this->client->getIndex($this->indexName);
     $type = $index->getType(ContentTypeSchemaGenerator::INDEX_TYPE . $content->getContentType());
     $document = $this->transformer->transform($content);
     try {
         $type->deleteDocument($document);
         $index->refresh();
     } catch (NotFoundException $e) {
     }
 }
 /**
  * @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;
 }
 /**
  * @param string           $message
  * @param ContentInterface $content
  */
 protected function sendLog($message, $content)
 {
     $this->logger->info($message, array('content_id' => $content->getContentId(), 'content_version' => $content->getVersion(), 'content_language' => $content->getLanguage()));
 }
 /**
  * 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
  * @param string           $fieldId
  *
  * @return ContentAttributeInterface
  */
 protected function getContentAttribute(ContentInterface $content, $fieldId)
 {
     $contentAttribute = $content->getAttributeByName($fieldId);
     if (!$contentAttribute instanceof ContentAttributeInterface) {
         $contentAttributeClass = $this->contentAttributeClass;
         /** @var ContentAttributeInterface $contentAttribute */
         $contentAttribute = new $contentAttributeClass();
         $contentAttribute->setName($fieldId);
         $content->addAttribute($contentAttribute);
     }
     return $contentAttribute;
 }
 /**
  * @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;
 }