本文整理汇总了PHP中eZ\Publish\API\Repository\ContentService类的典型用法代码示例。如果您正苦于以下问题:PHP ContentService类的具体用法?PHP ContentService怎么用?PHP ContentService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentService类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getTranslatedContentNameByContentInfo
/**
* Returns content name, translated, from a ContentInfo object.
* By default this method uses prioritized languages, unless $forcedLanguage is provided.
*
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
* @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
*
* @todo Remove ContentService usage when translated names are available in ContentInfo (see https://jira.ez.no/browse/EZP-21755)
*
* @return string
*/
public function getTranslatedContentNameByContentInfo(ContentInfo $contentInfo, $forcedLanguage = null)
{
if (isset($forcedLanguage) && $forcedLanguage === $contentInfo->mainLanguageCode) {
return $contentInfo->name;
}
return $this->getTranslatedContentName($this->contentService->loadContentByContentInfo($contentInfo), $forcedLanguage);
}
开发者ID:dfritschy,项目名称:ezpublish-kernel,代码行数:18,代码来源:TranslationHelper.php
示例2: setUp
protected function setUp()
{
parent::setUp();
$this->matcherFactoryMock = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\Matcher\\MatcherFactoryInterface');
$this->configResolverMock = $this->getMock('eZ\\Publish\\Core\\MVC\\ConfigResolverInterface');
$this->contentServiceMock = $this->getMock('eZ\\Publish\\API\\Repository\\ContentService');
$this->contentServiceMock->expects($this->any())->method('loadContentByContentInfo')->will($this->returnValue(new Content()));
}
开发者ID:michalpipa,项目名称:CommentsBundle,代码行数:8,代码来源:CommentsRendererTest.php
示例3: getContentCreateStruct
/**
* Creates and prepares content create structure.
*
* @param array $data
* @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
*/
private function getContentCreateStruct($data)
{
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($data['content_type']);
$struct = $this->contentService->newContentCreateStruct($contentType, '');
$this->fillValueObject($struct, $data, ['content_type']);
return $struct;
}
开发者ID:silversolutions,项目名称:content-loader-bundle,代码行数:13,代码来源:Content.php
示例4: previewContentAction
public function previewContentAction( $contentId, $versionNo, $language, $siteAccessName = null )
{
try
{
$content = $this->contentService->loadContent( $contentId, array( $language ), $versionNo );
$location = $this->previewHelper->getPreviewLocation( $contentId );
}
catch ( UnauthorizedException $e )
{
throw new AccessDeniedException();
}
if ( !$this->securityContext->isGranted( new AuthorizationAttribute( 'content', 'versionread', array( 'valueObject' => $content ) ) ) )
{
throw new AccessDeniedException();
}
$siteAccess = $this->previewHelper->getOriginalSiteAccess();
// Only switch if $siteAccessName is set and different from original
if ( $siteAccessName !== null && $siteAccessName !== $siteAccess->name )
{
$siteAccess = $this->previewHelper->changeConfigScope( $siteAccessName );
}
$response = $this->kernel->handle(
$this->getForwardRequest( $location, $content, $siteAccess ),
HttpKernelInterface::SUB_REQUEST
);
$response->headers->remove( 'cache-control' );
$response->headers->remove( 'expires' );
$this->previewHelper->restoreConfigScope();
return $response;
}
开发者ID:ataxel,项目名称:tp,代码行数:35,代码来源:PreviewController.php
示例5: parse
/**
* Parse input structure
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
$contentUpdateStruct = $this->contentService->newContentUpdateStruct();
// Missing initial language code
if (array_key_exists('initialLanguageCode', $data)) {
$contentUpdateStruct->initialLanguageCode = $data['initialLanguageCode'];
}
// @todo Where to set the user?
// @todo Where to set modification date?
if (array_key_exists('fields', $data)) {
if (!is_array($data['fields']) || !array_key_exists('field', $data['fields']) || !is_array($data['fields']['field'])) {
throw new Exceptions\Parser("Invalid 'fields' element for VersionUpdate.");
}
$contentId = $this->requestParser->parseHref($data['__url'], 'contentId');
foreach ($data['fields']['field'] as $fieldData) {
if (!array_key_exists('fieldDefinitionIdentifier', $fieldData)) {
throw new Exceptions\Parser("Missing 'fieldDefinitionIdentifier' element in field data for VersionUpdate.");
}
if (!array_key_exists('fieldValue', $fieldData)) {
throw new Exceptions\Parser("Missing 'fieldValue' element for '{$fieldData['fieldDefinitionIdentifier']}' identifier in VersionUpdate.");
}
$fieldValue = $this->fieldTypeParser->parseFieldValue($contentId, $fieldData['fieldDefinitionIdentifier'], $fieldData['fieldValue']);
$languageCode = null;
if (array_key_exists('languageCode', $fieldData)) {
$languageCode = $fieldData['languageCode'];
}
$contentUpdateStruct->setField($fieldData['fieldDefinitionIdentifier'], $fieldValue, $languageCode);
}
}
return $contentUpdateStruct;
}
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:39,代码来源:VersionUpdate.php
示例6: parseFieldValue
/**
* Parses the given $value for the field $fieldDefIdentifier in the content
* identified by $contentInfoId.
*
* @param string $contentInfoId
* @param string $fieldDefIdentifier
* @param mixed $value
*
* @return mixed
*/
public function parseFieldValue($contentInfoId, $fieldDefIdentifier, $value)
{
$contentInfo = $this->contentService->loadContentInfo($contentInfoId);
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
$fieldDefinition = $contentType->getFieldDefinition($fieldDefIdentifier);
return $this->parseValue($fieldDefinition->fieldTypeIdentifier, $value);
}
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:17,代码来源:FieldTypeParser.php
示例7: convert
/**
* Converts internal links (ezcontent:// and ezlocation://) to URLs.
*
* @param \DOMDocument $document
*
* @return \DOMDocument
*/
public function convert(DOMDocument $document)
{
$document = clone $document;
$xpath = new DOMXPath($document);
$xpath->registerNamespace("docbook", "http://docbook.org/ns/docbook");
$linkAttributeExpression = "starts-with( @xlink:href, 'ezlocation://' ) or starts-with( @xlink:href, 'ezcontent://' )";
$xpathExpression = "//docbook:link[{$linkAttributeExpression}]|//docbook:ezlink";
/** @var \DOMElement $link */
foreach ($xpath->query($xpathExpression) as $link) {
// Set resolved href to number character as a default if it can't be resolved
$hrefResolved = "#";
$href = $link->getAttribute("xlink:href");
$location = null;
preg_match("~^(.+://)?([^#]*)?(#.*|\\s*)?\$~", $href, $matches);
list(, $scheme, $id, $fragment) = $matches;
if ($scheme === "ezcontent://") {
try {
$contentInfo = $this->contentService->loadContentInfo($id);
$location = $this->locationService->loadLocation($contentInfo->mainLocationId);
$hrefResolved = $this->urlAliasRouter->generate($location) . $fragment;
} catch (APINotFoundException $e) {
if ($this->logger) {
$this->logger->warning("While generating links for richtext, could not locate " . "Content object with ID " . $id);
}
} catch (APIUnauthorizedException $e) {
if ($this->logger) {
$this->logger->notice("While generating links for richtext, unauthorized to load " . "Content object with ID " . $id);
}
}
} else {
if ($scheme === "ezlocation://") {
try {
$location = $this->locationService->loadLocation($id);
$hrefResolved = $this->urlAliasRouter->generate($location) . $fragment;
} catch (APINotFoundException $e) {
if ($this->logger) {
$this->logger->warning("While generating links for richtext, could not locate " . "Location with ID " . $id);
}
} catch (APIUnauthorizedException $e) {
if ($this->logger) {
$this->logger->notice("While generating links for richtext, unauthorized to load " . "Location with ID " . $id);
}
}
} else {
$hrefResolved = $href;
}
}
$hrefAttributeName = "xlink:href";
// For embeds set the resolved href to the separate attribute
// Original href needs to be preserved in order to generate link parameters
// This will need to change with introduction of UrlService and removal of URL link
// resolving in external storage
if ($link->localName === "ezlink") {
$hrefAttributeName = "href_resolved";
}
$link->setAttribute($hrefAttributeName, $hrefResolved);
}
return $document;
}
开发者ID:nlescure,项目名称:ezpublish-kernel,代码行数:66,代码来源:Link.php
示例8: handleAction
public function handleAction(Request $request)
{
$user = $this->userService->loadUserByCredentials($request->username, $request->password);
$this->repository->setCurrentUser($user);
$contentCreateStruct = $this->contentProvider->newContentCreateStructFromRequest($request);
$locationCreateStruct = $this->contentProvider->newLocationCreateStructFromRequest($request);
$content = $this->contentService->createContent($contentCreateStruct, array($locationCreateStruct));
$this->contentService->publishVersion($content->versionInfo);
}
开发者ID:bdunogier,项目名称:eziftttbundle,代码行数:9,代码来源:Handler.php
示例9: renderForContentAction
/**
* Renders the comments list for content with id $contentId
* Comment form might also be included
*
* @param mixed $contentId
*/
public function renderForContentAction( $contentId )
{
return new Response(
$this->commentsRenderer->renderForContent(
$this->contentService->loadContentInfo( $contentId ),
$this->request
)
);
}
开发者ID:ataxel,项目名称:tp,代码行数:15,代码来源:CommentsRendererController.php
示例10: setPostCategories
public function setPostCategories($postId, Request $request)
{
$this->login($request->request->get('username'), $request->request->get('password'));
// @todo Replace categories instead of adding
$contentInfo = $this->contentService->loadContentInfo($postId);
foreach ($request->request->get('categories') as $category) {
$this->locationService->createLocation($contentInfo, $this->locationService->newLocationCreateStruct($category['categoryId']));
}
return new Response(true);
}
开发者ID:bdunogier,项目名称:wordpressapibundle,代码行数:10,代码来源:DefaultController.php
示例11: findNodes
public function findNodes(LocationQuery $query)
{
$searchResult = $this->searchService->findLocations($query, ['languages' => $this->prioritizedLanguages, 'useAlwaysAvailable' => $this->useAlwaysAvailable]);
foreach ($searchResult->searchHits as $searchHit) {
/** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
$location = $searchHit->valueObject;
$searchHit->valueObject = $this->domainObjectMapper->mapNode($location, $this->contentService->loadContent($location->contentInfo->id, [$searchHit->matchedTranslation], $location->contentInfo->currentVersionNo), $searchHit->matchedTranslation);
}
return $searchResult;
}
开发者ID:netgen,项目名称:ezplatform-site-api,代码行数:10,代码来源:FindService.php
示例12: redirectToContentDownloadAction
/**
* Used by the REST API to reference downloadable files.
* It redirects (permanently) to the standard ez_content_download route, based on the language of the field
* passed as an argument, using the language switcher.
*
* @param mixed $contentId
* @param int $fieldId
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function redirectToContentDownloadAction($contentId, $fieldId, Request $request)
{
$content = $this->contentService->loadContent($contentId);
$field = $this->findFieldInContent($fieldId, $content);
$params = array('content' => $content, 'fieldIdentifier' => $field->fieldDefIdentifier, 'language' => $field->languageCode);
if ($request->query->has('version')) {
$params['version'] = $request->query->get('version');
}
$downloadUrl = $this->router->generate($this->routeReferenceGenerator->generate('ez_content_download', $params));
return new RedirectResponse($downloadUrl, 301);
}
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:22,代码来源:DownloadRedirectionController.php
示例13: purgeForContent
public function purgeForContent($contentId)
{
$contentInfo = $this->contentService->loadContentInfo($contentId);
$event = new ContentCacheClearEvent($contentInfo);
$this->eventDispatcher->dispatch(MVCEvents::CACHE_CLEAR_CONTENT, $event);
$locationIds = [];
foreach ($event->getLocationsToClear() as $location) {
$locationIds[] = $location->id;
}
$this->purgeClient->purge(array_unique($locationIds));
}
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:11,代码来源:InstantCachePurger.php
示例14: displayGalleryAction
/**
* Displays the gallery.
*
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function displayGalleryAction(ContentView $view, Request $request)
{
$languages = $this->configResolver->getParameter('languages');
$location = $view->getLocation();
$query = new Query();
$query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
$pager = new Pagerfanta(new ContentSearchAdapter($query, $this->searchService));
$pager->setMaxPerPage($this->galleryImagesLimit);
$pager->setCurrentPage($request->get('page', 1));
$view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'images' => $pager]);
return $view;
}
开发者ID:clash82,项目名称:ezplatform-demo,代码行数:20,代码来源:GalleryController.php
示例15: purgeForContent
/**
* {@inheritdoc}
*/
public function purgeForContent($contentId, $locationIds = [])
{
$contentInfo = $this->contentService->loadContentInfo($contentId);
// Can only gather relevant locations using ContentCacheClearEvent on published content
if ($contentInfo->published) {
$event = new ContentCacheClearEvent($contentInfo);
$this->eventDispatcher->dispatch(MVCEvents::CACHE_CLEAR_CONTENT, $event);
foreach ($event->getLocationsToClear() as $location) {
$locationIds[] = $location->id;
}
}
$this->purgeClient->purge(array_unique($locationIds));
}
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:16,代码来源:InstantCachePurger.php
示例16: downloadBinaryFileAction
/**
* @param mixed $contentId ID of a valid Content
* @param string $fieldIdentifier Field Definition identifier of the Field the file must be downloaded from
* @param string $filename
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \eZ\Bundle\EzPublishIOBundle\BinaryStreamResponse
*/
public function downloadBinaryFileAction($contentId, $fieldIdentifier, $filename, Request $request)
{
if ($request->query->has('version')) {
$content = $this->contentService->loadContent($contentId, null, $request->query->get('version'));
} else {
$content = $this->contentService->loadContent($contentId);
}
$field = $this->translationHelper->getTranslatedField($content, $fieldIdentifier, $request->query->has('inLanguage') ? $request->query->get('inLanguage') : null);
if (!$field instanceof Field) {
throw new InvalidArgumentException("'{$fieldIdentifier}' field not present on content #{$content->contentInfo->id} '{$content->contentInfo->name}'");
}
$response = new BinaryStreamResponse($this->ioService->loadBinaryFile($field->value->id), $this->ioService);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
return $response;
}
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:23,代码来源:DownloadController.php
示例17: getPreviewLocation
/**
* Returns a valid Location object for $contentId.
* Will either load mainLocationId (if available) or build a virtual Location object.
*
* @param mixed $contentId
*
* @return \eZ\Publish\API\Repository\Values\Content\Location|null Null when content does not have location
*/
public function getPreviewLocation($contentId)
{
// contentInfo must be reloaded as content is not published yet (e.g. no mainLocationId)
$contentInfo = $this->contentService->loadContentInfo($contentId);
// mainLocationId already exists, content has been published at least once.
if ($contentInfo->mainLocationId) {
$location = $this->locationService->loadLocation($contentInfo->mainLocationId);
} else {
// @todo In future releases this will be a full draft location when this feature
// is implemented. Or it might return null when content does not have location,
// but for now we can't detect that so we return a virtual draft location
$location = new Location(array('contentInfo' => $contentInfo, 'status' => Location::STATUS_DRAFT));
}
return $location;
}
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:23,代码来源:ContentPreviewHelper.php
示例18: getPreviewLocation
/**
* Returns a valid Location object for $contentId.
* Will either load mainLocationId (if available) or build a virtual Location object.
*
* @param mixed $contentId
*
* @return \eZ\Publish\API\Repository\Values\Content\Location|null Null when content does not have location
*/
public function getPreviewLocation( $contentId )
{
// contentInfo must be reloaded as content is not published yet (e.g. no mainLocationId)
$contentInfo = $this->contentService->loadContentInfo( $contentId );
// mainLocationId already exists, content has been published at least once.
if ( $contentInfo->mainLocationId )
{
$location = $this->locationService->loadLocation( $contentInfo->mainLocationId );
}
// New Content, never published, create a virtual location object.
else
{
// @todo In future releases this will be a full draft location when this feature
// is implemented. Or it might return null when content does not have location,
// but for now we can't detect that so we return a virtual draft location
$location = new Location(
array(
// Faking using root locationId
'id' => $this->configResolver->getParameter( 'content.tree_root.location_id' ),
'contentInfo' => $contentInfo,
'status' => Location::STATUS_DRAFT
)
);
}
return $location;
}
开发者ID:ataxel,项目名称:tp,代码行数:35,代码来源:ContentPreviewHelper.php
示例19: setObjectStatesForContent
/**
* Updates object states of content
* An object state in the input overrides the state of the object state group.
*
* @param $contentId
*
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
*
* @return \eZ\Publish\Core\REST\Common\Values\ContentObjectStates
*/
public function setObjectStatesForContent($contentId, Request $request)
{
$newObjectStates = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
$countByGroups = array();
foreach ($newObjectStates as $newObjectState) {
$groupId = (int) $newObjectState->groupId;
if (array_key_exists($groupId, $countByGroups)) {
++$countByGroups[$groupId];
} else {
$countByGroups[$groupId] = 1;
}
}
foreach ($countByGroups as $groupId => $count) {
if ($count > 1) {
throw new ForbiddenException("Multiple object states provided for group with ID {$groupId}");
}
}
$contentInfo = $this->contentService->loadContentInfo($contentId);
$contentObjectStates = array();
foreach ($newObjectStates as $newObjectState) {
$objectStateGroup = $this->objectStateService->loadObjectStateGroup($newObjectState->groupId);
$this->objectStateService->setContentState($contentInfo, $objectStateGroup, $newObjectState->objectState);
$contentObjectStates[(int) $objectStateGroup->id] = $newObjectState;
}
return new ContentObjectStates($contentObjectStates);
}
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:36,代码来源:ObjectState.php
示例20: generate
/**
* Generates a URL for a location, from the given parameters.
*
* It is possible to directly pass a Location object as the route name, as the ChainRouter allows it through ChainedRouterInterface.
*
* If $name is a route name, the "location" key in $parameters must be set to a valid eZ\Publish\API\Repository\Values\Content\Location object.
* "locationId" can also be provided.
*
* If the generator is not able to generate the url, it must throw the RouteNotFoundException
* as documented below.
*
* @see UrlAliasRouter::supports()
*
* @param string|\eZ\Publish\API\Repository\Values\Content\Location $name The name of the route or a Location instance
* @param mixed $parameters An array of parameters
* @param int $referenceType The type of reference to be generated (one of the constants)
*
* @throws \LogicException
* @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
* @throws \InvalidArgumentException
*
* @return string The generated URL
*
* @api
*/
public function generate($name, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
// Direct access to Location
if ($name instanceof Location) {
return $this->generator->generate($name, $parameters, $referenceType);
}
// Normal route name
if ($name === self::URL_ALIAS_ROUTE_NAME) {
if (isset($parameters['location']) || isset($parameters['locationId'])) {
// Check if location is a valid Location object
if (isset($parameters['location']) && !$parameters['location'] instanceof Location) {
throw new LogicException("When generating an UrlAlias route, 'location' parameter must be a valid eZ\\Publish\\API\\Repository\\Values\\Content\\Location.");
}
$location = isset($parameters['location']) ? $parameters['location'] : $this->locationService->loadLocation($parameters['locationId']);
unset($parameters['location'], $parameters['locationId'], $parameters['viewType'], $parameters['layout']);
return $this->generator->generate($location, $parameters, $referenceType);
}
if (isset($parameters['contentId'])) {
$contentInfo = $this->contentService->loadContentInfo($parameters['contentId']);
unset($parameters['contentId'], $parameters['viewType'], $parameters['layout']);
if (empty($contentInfo->mainLocationId)) {
throw new LogicException('Cannot generate an UrlAlias route for content without main location.');
}
return $this->generator->generate($this->locationService->loadLocation($contentInfo->mainLocationId), $parameters, $referenceType);
}
throw new InvalidArgumentException("When generating an UrlAlias route, either 'location', 'locationId' or 'contentId' must be provided.");
}
throw new RouteNotFoundException('Could not match route');
}
开发者ID:kuborgh,项目名称:ezpublish-kernel,代码行数:54,代码来源:UrlAliasRouter.php
注:本文中的eZ\Publish\API\Repository\ContentService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论