/**
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 public function getContent()
 {
     if ($this->content == null) {
         $this->content = $this->repository->getContentService()->loadContent($this->location->contentId);
     }
     return $this->content;
 }
 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));
 }
 /**
  * Converts eZ Publish legacy objects and nodes to content and locations
  *
  * @param mixed $object
  *
  * @return mixed
  */
 public function convert($object)
 {
     if ($object instanceof eZContentObject) {
         return $this->repository->getContentService()->loadContent($object->attribute('id'));
     } else {
         if ($object instanceof eZContentObjectTreeNode) {
             return $this->repository->getLocationService()->loadLocation($object->attribute('node_id'));
         }
     }
     return $object;
 }
 /**
  * @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;
 }
Пример #5
0
 /**
  * Returns field relations data for the current version of the given $contentInfo.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  *
  * @return mixed
  */
 public function getFieldRelations(ContentInfo $contentInfo)
 {
     $relations = array();
     $locationIdToContentIdMapping = array();
     $content = $this->repository->getContentService()->loadContentByContentInfo($contentInfo);
     foreach ($content->getFields() as $field) {
         $fieldDefinition = $content->contentType->getFieldDefinition($field->fieldDefIdentifier);
         $fieldType = $this->repository->getFieldTypeService()->buildFieldType($fieldDefinition->fieldTypeIdentifier);
         $this->appendFieldRelations($relations, $locationIdToContentIdMapping, $fieldType, $fieldType->acceptValue($field->value), $fieldDefinition->id);
     }
     return $relations;
 }
Пример #6
0
 /**
  * Builds the domain user object from provided persistence user object
  *
  * @param \eZ\Publish\SPI\Persistence\User $spiUser
  * @param \eZ\Publish\API\Repository\Values\Content\Content|null $content
  *
  * @return \eZ\Publish\API\Repository\Values\User\User
  */
 protected function buildDomainUserObject(SPIUser $spiUser, APIContent $content = null)
 {
     if ($content === null) {
         $content = $this->repository->getContentService()->internalLoadContent($spiUser->id);
     }
     return new User(array('content' => $content, 'login' => $spiUser->login, 'email' => $spiUser->email, 'passwordHash' => $spiUser->passwordHash, 'hashAlgorithm' => (int) $spiUser->hashAlgorithm, 'enabled' => $spiUser->isEnabled, 'maxLogin' => (int) $spiUser->maxLogin));
 }
Пример #7
0
 /**
  * Get Content Service
  *
  * Get service object to perform operations on Content objects and it's aggregate members.
  *
  * @return \eZ\Publish\API\Repository\ContentService
  */
 public function getContentService()
 {
     if ($this->contentService !== null) {
         return $this->contentService;
     }
     $this->contentService = new ContentService($this->repository->getContentService(), $this->signalDispatcher);
     return $this->contentService;
 }
Пример #8
0
 /**
  * Builds domain location object from provided persistence location
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location $spiLocation
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location
  */
 public function buildLocationDomainObject(SPILocation $spiLocation)
 {
     // TODO: this is hardcoded workaround for missing ContentInfo on root location
     if ($spiLocation->id == 1) {
         $contentInfo = new ContentInfo(array('id' => 0, 'name' => 'Top Level Nodes', 'sectionId' => 1, 'mainLocationId' => 1, 'contentTypeId' => 1));
     } else {
         $contentInfo = $this->repository->getContentService()->internalLoadContentInfo($spiLocation->contentId);
     }
     return new Location(array('contentInfo' => $contentInfo, 'id' => $spiLocation->id, 'priority' => $spiLocation->priority, 'hidden' => $spiLocation->hidden, 'invisible' => $spiLocation->invisible, 'remoteId' => $spiLocation->remoteId, 'parentLocationId' => $spiLocation->parentId, 'pathString' => $spiLocation->pathString, 'depth' => $spiLocation->depth, 'sortField' => $spiLocation->sortField, 'sortOrder' => $spiLocation->sortOrder));
 }
Пример #9
0
 /**
  * Renders $location by selecting the right template for $viewType.
  * $content and $location will be injected in the selected template.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param string $viewType Variation of display for your content. Default is 'full'.
  * @param array $parameters Parameters to pass to the template called to
  *        render the view. By default, it's empty. 'location' and 'content'
  *        entries are reserved for the Location (and its Content) that is
  *        viewed.
  *
  * @throws \RuntimeException
  *
  * @return string
  */
 public function renderLocation(Location $location, $viewType = ViewManagerInterface::VIEW_TYPE_FULL, $parameters = array())
 {
     if (!isset($parameters['location'])) {
         $parameters['location'] = $location;
     }
     if (!isset($parameters['content'])) {
         $parameters['content'] = $this->repository->getContentService()->loadContentByContentInfo($location->contentInfo, $this->configResolver->getParameter('languages'));
     }
     return $this->renderContent($parameters['content'], $viewType, $parameters);
 }
 /**
  * Builds domain location object from provided persistence location
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location $spiLocation
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location
  */
 public function buildLocationDomainObject(SPILocation $spiLocation)
 {
     // TODO: this is hardcoded workaround for missing ContentInfo on root location
     if ($spiLocation->id == 1) {
         $contentInfo = new ContentInfo(array('id' => 57, 'name' => 'Home', 'sectionId' => 1, 'mainLocationId' => 1, 'currentVersionNo' => 1, 'contentTypeId' => 1, 'published' => true, 'ownerId' => 14, 'alwaysAvailable' => true, 'remoteId' => "8a9c9c761004866fb458d89910f52bee", 'mainLanguageCode' => "ger-DE"));
     } else {
         $contentInfo = $this->repository->getContentService()->internalLoadContentInfo($spiLocation->contentId);
     }
     return new Location(array('contentInfo' => $contentInfo, 'id' => $spiLocation->id, 'priority' => $spiLocation->priority, 'hidden' => $spiLocation->hidden, 'invisible' => $spiLocation->invisible, 'remoteId' => $spiLocation->remoteId, 'parentLocationId' => $spiLocation->parentId, 'pathString' => $spiLocation->pathString, 'depth' => $spiLocation->depth, 'sortField' => $spiLocation->sortField, 'sortOrder' => $spiLocation->sortOrder));
 }
Пример #11
0
 /**
  * Renders $location by selecting the right template for $viewType.
  * $content and $location will be injected in the selected template.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @param string $viewType Variation of display for your content. Default is 'full'.
  * @param array $parameters Parameters to pass to the template called to
  *        render the view. By default, it's empty. 'location' and 'content'
  *        entries are reserved for the Location (and its Content) that is
  *        viewed.
  * @throws \RuntimeException
  *
  * @return string
  */
 public function renderLocation(Location $location, $viewType = ViewManagerInterface::VIEW_TYPE_FULL, $parameters = array())
 {
     foreach ($this->getAllLocationViewProviders() as $viewProvider) {
         $view = $viewProvider->getView($location, $viewType);
         if ($view instanceof ContentViewInterface) {
             $parameters['location'] = $location;
             return $this->renderContentView($view, $parameters + array('content' => $this->repository->getContentService()->loadContentByContentInfo($location->getContentInfo(), $this->configResolver->getParameter('languages'))));
         }
     }
     throw new RuntimeException("Unable to find a view for location #{$location->id}");
 }
 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();
 }
Пример #13
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;
 }
 /**
  * Assigns the content to the given section
  * this method overrides the current assigned section
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If user does not have access to view provided object
  *
  * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
  * @param \eZ\Publish\API\Repository\Values\Content\Section $section
  */
 public function assignSection(ContentInfo $contentInfo, Section $section)
 {
     $loadedContentInfo = $this->repository->getContentService()->loadContentInfo($contentInfo->id);
     $loadedSection = $this->loadSection($section->id);
     if ($this->repository->canUser('section', 'assign', $loadedContentInfo, $loadedSection) !== true) {
         throw new UnauthorizedException('section', 'assign', array('name' => $loadedSection->name, 'content-name' => $loadedContentInfo->name));
     }
     $this->repository->beginTransaction();
     try {
         $this->sectionHandler->assign($loadedSection->id, $loadedContentInfo->id);
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
 }
 /**
  *  render a viewtemplate with a twigfunction uses the ezpulish  override.yml
  *
  *     {{ cjw_render_location( {'locationId': locationObject.id, 'viewType': 'line'} ) }}
  *
  *     => faster is the following call
  *
  *     {{ cjw_render_location( {'location': locationObject, 'viewType': 'line'} ) }}
  *
  * @param array  $parameters  hash
  *
  * @return string
  */
 public function renderLocation(array $params)
 {
     $viewType = $params['viewType'];
     if (isset($params['location']) && $params['location'] instanceof Location) {
         $location = $params['location'];
         $locationId = $location->id;
     } elseif (isset($params['locationId'])) {
         $locationId = $params['locationId'];
         $location = $this->repository->getLocationService()->loadLocation($locationId);
         if ($location->invisible) {
             throw new NotFoundHttpException("Location #{$locationId} cannot be displayed as it is flagged as invisible.");
         }
     } else {
         // TODO Fehler wenn locationId nicht gesetzt oder location keine Location objekt
         return false;
     }
     $templateFileName = 'CjwPublishToolsBundle::line.html.twig';
     $this->template = $this->environment->loadTemplate($templateFileName);
     $locationObject = $this->repository->getLocationService()->loadLocation($locationId);
     $contentId = $locationObject->contentInfo->id;
     $contentObject = $this->repository->getContentService()->loadContent($contentId);
     // $view = 'CjwPublishToolsBundle::line.html.twig';
     // find override template
     $template = $this->getOverrideTemplate($locationObject, $contentObject, $viewType);
     //var_dump( $template );
     $params['location'] = $locationObject;
     $params['content'] = $contentObject;
     // name of the rendered template
     $params['_template'] = $template;
     // loop params array, and set as tpl var
     if (isset($params['params'])) {
         foreach ($params['params'] as $param => $value) {
             $params[$param] = $value;
         }
     }
     $temapleRenderedContent = $this->getTemplateEngine()->render($template, $params);
     // TODO  wenn templatedebug eingeschaltet ist dieses anzeigen
     if ($this->templateDebug == true) {
         $temapleContentDebug = "\n<!-- cjw_render_location: LocationId: {$locationId}, viewType: {$viewType}, Template: {$template} -->\n";
         $temapleRenderedContent = $temapleContentDebug . "\n" . $temapleRenderedContent;
     }
     return $temapleRenderedContent;
 }
Пример #17
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);
 }
Пример #19
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);
 }
Пример #20
0
 /**
  * Returns the content info for this concrete content.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
  */
 private function getContentInfo()
 {
     return $this->repository->getContentService()->loadContentInfo($this->id);
 }
Пример #21
0
 /**
  * @return \eZ\Publish\API\Repository\ContentService
  */
 protected function getContentService()
 {
     return $this->apiRepository->getContentService();
 }
 public function __construct(Repository $repository)
 {
     $this->repository = $repository;
     $this->contentService = $repository->getContentService();
     $this->locationService = $repository->getLocationService();
 }
 /**
  * Creates and returns content with given $fieldData.
  *
  * @param mixed $fieldData
  * @param \eZ\Publish\API\Repository\Repository $repository
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 protected function createTestSearchContent($fieldData, Repository $repository, $contentType)
 {
     $contentService = $repository->getContentService();
     $locationService = $repository->getLocationService();
     $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
     $createStruct->setField('name', 'Test object');
     $createStruct->setField('data', $fieldData);
     $locationCreateStruct = $locationService->newLocationCreateStruct(2);
     return $contentService->publishVersion($contentService->createContent($createStruct, array($locationCreateStruct))->versionInfo);
 }
 /**
  * Loads Content with id $contentId.
  *
  * @param mixed $contentId
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException
  */
 private function loadContent($contentId)
 {
     return $this->repository->getContentService()->loadContent($contentId);
 }
Пример #25
0
 /**
  * Builds the domain TrashItem object from provided persistence trash item
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location\Trashed $spiTrashItem
  *
  * @return \eZ\Publish\API\Repository\Values\Content\TrashItem
  */
 protected function buildDomainTrashItemObject(Trashed $spiTrashItem)
 {
     return new TrashItem(array('contentInfo' => $this->repository->getContentService()->loadContentInfo($spiTrashItem->contentId), 'id' => $spiTrashItem->id, 'priority' => $spiTrashItem->priority, 'hidden' => $spiTrashItem->hidden, 'invisible' => $spiTrashItem->invisible, 'remoteId' => $spiTrashItem->remoteId, 'parentLocationId' => $spiTrashItem->parentId, 'pathString' => $spiTrashItem->pathString, 'depth' => $spiTrashItem->depth, 'sortField' => $spiTrashItem->sortField, 'sortOrder' => $spiTrashItem->sortOrder));
 }
 /**
  * Content of the content this version belongs to.
  *
  * @return ContentInfo
  */
 public function getContentInfo()
 {
     return $this->repository->getContentService()->loadContentInfo($this->contentId);
 }