/**
  * @param Location $location
  * @return mixed
  */
 public function getContentDecorator(Location $location)
 {
     $mappingEntities = $this->configResolver->getParameter('class_mapping', 'ezcontentdecorator');
     $contentTypeIdentifier = $this->repository->getContentTypeService()->loadContentType($location->contentInfo->contentTypeId)->identifier;
     $className = array_key_exists($contentTypeIdentifier, $mappingEntities) ? $mappingEntities[$contentTypeIdentifier] : $this->defaultClassName;
     return new $className($this->container, $location, $contentTypeIdentifier);
 }
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->get('is_rest_request')) {
         return;
     }
     if (($contentTypeHeaderValue = $request->headers->get('content-type')) === null) {
         return;
     }
     list($mediaType) = explode('+', $contentTypeHeaderValue);
     if (strtolower($mediaType) == !'application/vnd.ez.api.contentcreate') {
         return;
     }
     $message = $this->buildMessage($request);
     if (!$message->body) {
         return;
     }
     $result = $this->restInputDispatcher->parse($message);
     if (!$result instanceof RestContentCreateStruct) {
         return;
     }
     // Not a user
     if (($userCreateData = $this->mapContentCreateToUserCreate($result)) === false) {
         return;
     }
     list($userCreateStruct, $userGroup) = $userCreateData;
     $createdUser = $this->repository->getUserService()->createUser($userCreateStruct, [$userGroup]);
     $createdContentInfo = $createdUser->contentInfo;
     $createdLocation = $this->repository->getLocationService()->loadLocation($createdContentInfo->mainLocationId);
     $contentType = $this->repository->getContentTypeService()->loadContentType($createdContentInfo->contentTypeId);
     $result = new CreatedContent(array('content' => new RestContent($createdContentInfo, $createdLocation, $this->repository->getContentService()->loadContent($createdContentInfo->id), $contentType, $this->repository->getContentService()->loadRelations($createdUser->getVersionInfo()))));
     $event->setResponse($this->viewDispatcher->dispatch($event->getRequest(), $result));
 }
Пример #3
0
 public function castContentInfo(ContentInfo $info, array $a, Stub $stub, $isNested, $filter = 0)
 {
     $a = [Caster::PREFIX_PROTECTED . 'id' => $info->id, Caster::PREFIX_PROTECTED . 'name' => $info->name] + $a;
     if (!$filter & Caster::EXCLUDE_VERBOSE) {
         $contentType = $this->repository->getContentTypeService()->loadContentType($info->contentTypeId);
         $a[Caster::PREFIX_VIRTUAL . 'contentTypeName'] = $contentType->getName($info->mainLanguageCode);
     }
     return $a;
 }
 /**
  * Gets content type identifier of field corresponding with the given node
  *
  * @param TreeNodeInterface $node
  * @return string
  */
 public function getContentTypeIdentifier(TreeNodeInterface $node)
 {
     $parent = $node->getParent();
     $fieldName = $parent->getName();
     $grandPa = $parent->getParent()->getParent();
     $contentTypeNode = $grandPa->getChildByName('content_type');
     $contentType = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($contentTypeNode->getValue());
     $fieldDefinition = $contentType->getFieldDefinition($fieldName);
     return $fieldDefinition->fieldTypeIdentifier;
 }
 /**
  * @param \eZ\Publish\API\Repository\Repository $repository
  * @param ConfigResolverInterface|\Psr\Log\LoggerInterface $resolver
  */
 public function __construct(Repository $repository, ConfigResolverInterface $resolver)
 {
     $this->repository = $repository;
     $this->searchService = $this->repository->getSearchService();
     $this->locationService = $this->repository->getLocationService();
     $this->contentService = $this->repository->getContentService();
     $this->languageService = $this->repository->getContentLanguageService();
     $this->userService = $this->repository->getUserService();
     $this->contentTypeService = $this->repository->getContentTypeService();
     $this->configResolver = $resolver;
 }
 /**
  * @param $login
  * @param $email
  * @param $firstName
  * @param $lastName
  * @return User
  */
 public function createNewUser($login, $email, $firstName, $lastName)
 {
     $userService = $this->repository->getUserService();
     $userCreateStruct = $userService->newUserCreateStruct($login, $email, md5($email . $login . time() . rand(1, 10000)), 'eng-GB', $this->repository->getContentTypeService()->loadContentTypeByIdentifier('user'));
     $userCreateStruct->setField('first_name', $firstName);
     $userCreateStruct->setField('last_name', $lastName);
     $user = $this->repository->sudo(function () use($userService, $userCreateStruct) {
         $userGroup = $userService->loadUserGroup('11');
         // guest accounts
         return $userService->createUser($userCreateStruct, array($userGroup));
     });
     return $user;
 }
Пример #7
0
 /**
  * Instantiate a user group create class
  *
  * @param string $mainLanguageCode The main language for the underlying content object
  * @param null|\eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration
  *
  * @return \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct
  */
 public function newUserGroupCreateStruct($mainLanguageCode, $contentType = null)
 {
     if ($contentType === null) {
         $contentType = $this->repository->getContentTypeService()->loadContentType($this->settings['userGroupClassID']);
     }
     return new UserGroupCreateStruct(array('contentType' => $contentType, 'mainLanguageCode' => $mainLanguageCode, 'fields' => array()));
 }
 /**
  * Convenience method for resolving name schema
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Content $content
  * @param array $fieldMap
  * @param array $languageCodes
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType
  *
  * @return array
  */
 public function resolveNameSchema(Content $content, array $fieldMap = array(), array $languageCodes = array(), ContentType $contentType = null)
 {
     if ($contentType === null) {
         $contentType = $this->repository->getContentTypeService()->loadContentType($content->contentInfo->contentTypeId);
     }
     $languageCodes = $languageCodes ?: $content->versionInfo->languageCodes;
     return $this->resolve($contentType->nameSchema, $contentType, $this->mergeFieldMap($content, $fieldMap, $languageCodes), $languageCodes);
 }
Пример #9
0
 /**
  * Get Content Type Service
  *
  * Get service object to perform operations on Content Type objects and it's aggregate members.
  * ( Group, Field & FieldCategory )
  *
  * @return \eZ\Publish\API\Repository\ContentTypeService
  */
 public function getContentTypeService()
 {
     if ($this->contentTypeService !== null) {
         return $this->contentTypeService;
     }
     $this->contentTypeService = new ContentTypeService($this->repository->getContentTypeService(), $this->signalDispatcher);
     return $this->contentTypeService;
 }
Пример #10
0
 /**
  * Get ContentType by Content/ContentInfo.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Content|\eZ\Publish\API\Repository\Values\Content\ContentInfo $content
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType|null
  */
 private function getContentType(ValueObject $content)
 {
     if ($content instanceof Content) {
         return $this->repository->getContentTypeService()->loadContentType($content->getVersionInfo()->getContentInfo()->contentTypeId);
     } elseif ($content instanceof ContentInfo) {
         return $this->repository->getContentTypeService()->loadContentType($content->contentTypeId);
     }
 }
Пример #11
0
 /**
  * Returns a field value for the given value
  * $version->fields[$fieldDefId][$languageCode] is an equivalent call
  * if no language is given on a translatable field this method returns
  * the value of the initial language of the version if present, otherwise null.
  * On non translatable fields this method ignores the languageCode parameter.
  *
  * @param string $fieldDefIdentifier
  * @param string $languageCode
  *
  * @return mixed a primitive type or a field type Value object depending on the field type.
  */
 public function getFieldValue($fieldDefIdentifier, $languageCode = null)
 {
     $contentType = $this->repository->getContentTypeService()->loadContentType($this->contentTypeId);
     $translatable = $contentType->getFieldDefinition($fieldDefIdentifier)->isTranslatable;
     if (null === $languageCode) {
         $languageCode = $this->getVersionInfo()->getContentInfo()->mainLanguageCode;
     }
     foreach ($this->getFields() as $field) {
         if ($field->fieldDefIdentifier !== $fieldDefIdentifier) {
             continue;
         }
         if ($translatable && $field->languageCode !== $languageCode) {
             continue;
         }
         return $field->value;
     }
     return null;
 }
 public function __construct(Repository $repository, CategoryServiceInterface $categoryService, PostServiceInterface $postService)
 {
     $this->repository = $repository;
     $this->categoryService = $categoryService;
     $this->postService = $postService;
     $this->searchService = $repository->getSearchService();
     $this->contentService = $repository->getContentService();
     $this->locationService = $repository->getLocationService();
     $this->contentTypeService = $repository->getContentTypeService();
     $this->userService = $repository->getUserService();
 }
 /**
  * Builds API Relation object from provided SPI Relation object
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Relation $spiRelation
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $sourceContentInfo
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContentInfo
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Relation
  */
 public function buildRelationDomainObject(SPIRelation $spiRelation, ContentInfo $sourceContentInfo, ContentInfo $destinationContentInfo)
 {
     $sourceFieldDefinitionIdentifier = null;
     if ($spiRelation->sourceFieldDefinitionId !== null) {
         /** @var \eZ\Publish\Core\Repository\Values\ContentType\ContentType $contentType */
         $contentType = $this->repository->getContentTypeService()->loadContentType($sourceContentInfo->contentTypeId);
         // Note: getFieldDefinitionById() is not part of API
         $sourceFieldDefinitionIdentifier = $contentType->getFieldDefinitionById($spiRelation->sourceFieldDefinitionId)->identifier;
     }
     return new Relation(array("id" => $spiRelation->id, "sourceFieldDefinitionIdentifier" => $sourceFieldDefinitionIdentifier, "type" => $spiRelation->type, "sourceContentInfo" => $sourceContentInfo, "destinationContentInfo" => $destinationContentInfo));
 }
Пример #14
0
 /**
  * Uses a content type identifier + a hash of fields values
  * to create and publish a draft below the root location.
  *
  * @param string $contentTypeIdentifier
  * @param array $fields Hash of field def identifier => field value
  *
  * @return Content the created draft.
  */
 public function createDraft($contentTypeIdentifier, array $fields)
 {
     $contentService = $this->repository->getContentService();
     $createStruct = $contentService->newContentCreateStruct($this->repository->getContentTypeService()->loadContentTypeByIdentifier($contentTypeIdentifier), 'eng-GB');
     foreach ($fields as $fieldDefIdentifier => $fieldValue) {
         $createStruct->setField($fieldDefIdentifier, $fieldValue);
     }
     $locationCreateStruct = $this->repository->getLocationService()->newLocationCreateStruct(2);
     $this->currentDraft = $this->repository->sudo(function () use($createStruct, $locationCreateStruct) {
         return $this->repository->getContentService()->createContent($createStruct, [$locationCreateStruct]);
     });
     return $this->currentDraft;
 }
 /**
  * Helper to quickly create content.
  *
  * @see https://github.com/ezsystems/CookbookBundle/blob/master/Command/CreateContentCommand.php eZ Publish Cookbook
  *
  * Usage:
  * <code>
  * $this->createContent(2, 'folder', 'eng-GB', [
  *     'title' => 'Folder Title',
  * ]);
  * </code>
  *
  * @param int    $parentLocationId
  * @param string $contentTypeIdentifier
  * @param string $languageCode
  * @param array  $fields
  *
  * @throws NotFoundException               If the content type or parent location could not be found
  * @throws ContentFieldValidationException If an invalid field value has been provided
  * @throws ContentValidationException      If a required field is missing or empty
  *
  * @return Content
  */
 protected function createContent($parentLocationId, $contentTypeIdentifier, $languageCode, array $fields)
 {
     $contentService = $this->repository->getContentService();
     $locationService = $this->repository->getLocationService();
     $contentTypeService = $this->repository->getContentTypeService();
     $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
     $contentCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode);
     foreach ($fields as $key => $value) {
         $contentCreateStruct->setField($key, $value);
     }
     $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);
     $draft = $contentService->createContent($contentCreateStruct, [$locationCreateStruct]);
     $content = $contentService->publishVersion($draft->getVersionInfo());
     return $content;
 }
 /**
  * @param $contentTypeId
  * @return bool|string
  */
 public function getContentTypeIdentifier($contentTypeId)
 {
     if (isset($this->cacheContentTypeIdentifier[$contentTypeId])) {
         return $this->cacheContentTypeIdentifier[$contentTypeId];
     }
     $cs = $this->repository->getContentTypeService();
     try {
         $ct = $cs->loadContentType($contentTypeId);
         $contentTypeIdentifier = $ct->identifier;
         $this->cacheContentTypeIdentifier[$contentTypeId] = $contentTypeIdentifier;
         return $contentTypeIdentifier;
     } catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $error) {
         return false;
     }
 }
 /**
  * Get the ContentType depending on the input arguments
  *
  * @param InputInterface     $input
  *
  * @return ContentType[]
  */
 protected function getContentTypes(InputInterface $input)
 {
     $contentTypes = [];
     $contentTypeService = $this->eZPublishRepository->getContentTypeService();
     if ($contentTypeGroupIdentifier = $input->getOption('group_identifier')) {
         $contentTypeGroup = $contentTypeService->loadContentTypeGroupByIdentifier($contentTypeGroupIdentifier);
         $contentTypes = $contentTypeService->loadContentTypes($contentTypeGroup);
     }
     if ($contentTypeIdentifiers = explode(",", $input->getOption('identifiers'))) {
         foreach ($contentTypeIdentifiers as $identifier) {
             if ($identifier != "") {
                 $contentTypes[] = $contentTypeService->loadContentTypeByIdentifier($identifier);
             }
         }
     }
     if ($contentTypeIdentifier = $input->getOption('identifier')) {
         $contentTypes[] = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
     }
     return $contentTypes;
 }
Пример #18
0
 /**
  * Compute Metas of the Field thanks to its Content and the Fallback
  *
  * @param Field       $field
  * @param ContentInfo $contentInfo
  *
  * @return string
  */
 public function computeMetas(Field $field, ContentInfo $contentInfo)
 {
     $fallback = false;
     $languages = $this->configResolver->getParameter('languages');
     $contentType = $this->eZRepository->getContentTypeService()->loadContentType($contentInfo->contentTypeId);
     $content = $this->eZRepository->getContentService()->loadContentByContentInfo($contentInfo, $languages);
     $contentMetas = $this->innerComputeMetas($content, $field, $contentType, $fallback);
     if ($fallback) {
         $rootNode = $this->eZRepository->getLocationService()->loadLocation($this->configResolver->getParameter("content.tree_root.location_id"));
         $rootContent = $this->eZRepository->getContentService()->loadContentByContentInfo($rootNode->contentInfo, $languages);
         $rootContentType = $this->eZRepository->getContentTypeService()->loadContentType($rootContent->contentInfo->contentTypeId);
         // We need to load the good field too
         $metasIdentifier = $this->configResolver->getParameter('fieldtype_metas_identifier', 'novae_zseo');
         $rootMetas = $this->innerComputeMetas($rootContent, $metasIdentifier, $rootContentType, $fallback);
         foreach ($contentMetas as $key => $metaContent) {
             if (array_key_exists($key, $rootMetas)) {
                 $metaContent->setContent($metaContent->isEmpty() ? $rootMetas[$key]->getContent() : $metaContent->getContent());
             }
         }
     }
     return '';
 }
 /**
  * Send message to admin(s)
  */
 public function sendMessage($data, $user, $contentId, $sessionId, $commentId)
 {
     if ($user === null) {
         $name = $data[$this->translator->trans('name')];
         $email = $data[$this->translator->trans('email')];
     } else {
         $name = $user->versionInfo->contentInfo->name;
         $email = $user->email;
     }
     $approve_url = $this->getModerationURL($contentId, $commentId, $sessionId, 'approve');
     $reject_url = $this->getModerationURL($contentId, $commentId, $sessionId, 'reject');
     $content = $this->repository->getContentService()->loadContent($contentId);
     $contentType = $this->repository->getContentTypeService()->loadContentType($content->getVersionInfo()->getContentInfo()->contentTypeId);
     if ($contentType->identifier == 'livre_or') {
         $this->moderate_template = 'DigitInnFrontBundle:Mail:livre_dor_comment_moderation.html.twig';
     }
     $article_nom = $content->getFieldValue('title')->text;
     $subject = $article_nom . ' - ' . $this->moderate_subject;
     $article_url = $this->router->generate('ez_urlalias', array('contentId' => $contentId), true);
     $message = \Swift_Message::newInstance()->setContentType('text/html')->setSubject($subject)->setFrom($this->moderate_from)->setTo($this->moderate_to)->setBody($this->templating->render($this->moderate_template, array("name" => $name, "email" => $email, "comment" => $data[$this->translator->trans('message')], "article_url" => $article_url, "article_nom" => $article_nom, "approve_url" => $approve_url, "reject_url" => $reject_url)));
     $this->mailer->send($message);
 }
Пример #20
0
 /**
  * Returns the field type identifier for $field
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Content $content
  * @param \eZ\Publish\API\Repository\Values\Content\Field $field
  *
  * @return string
  */
 protected function getFieldTypeIdentifier(Content $content, Field $field)
 {
     $contentType = $this->repository->getContentTypeService()->loadContentType($content->getVersionInfo()->getContentInfo()->contentTypeId);
     $key = $contentType->identifier . '  ' . $field->fieldDefIdentifier;
     if (!isset($this->fieldTypeIdentifiers[$key])) {
         $this->fieldTypeIdentifiers[$key] = $contentType->getFieldDefinition($field->fieldDefIdentifier)->fieldTypeIdentifier;
     }
     return $this->fieldTypeIdentifiers[$key];
 }
Пример #21
0
 /**
  * @return mixed
  */
 protected function getPlaceContentType()
 {
     return $this->apiRepository->getContentTypeService()->loadContentTypeByIdentifier('place');
 }
Пример #22
0
 /**
  * @param Repository $repository
  * @param int $parentLocationId
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 protected function createNewContentInPlaceTrashedOne(Repository $repository, $parentLocationId)
 {
     $contentService = $repository->getContentService();
     $locationService = $repository->getLocationService();
     $contentTypeService = $repository->getContentTypeService();
     $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
     $newContent = $contentService->newContentCreateStruct($contentType, 'eng-US');
     $newContent->setField('name', 'Media');
     $location = $locationService->newLocationCreateStruct($parentLocationId);
     $draftContent = $contentService->createContent($newContent, [$location]);
     return $contentService->publishVersion($draftContent->versionInfo);
 }