本文整理汇总了PHP中eZ\Publish\API\Repository\LocationService::loadLocation方法的典型用法代码示例。如果您正苦于以下问题:PHP LocationService::loadLocation方法的具体用法?PHP LocationService::loadLocation怎么用?PHP LocationService::loadLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\API\Repository\LocationService
的用法示例。
在下文中一共展示了LocationService::loadLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onContentCacheClear
public function onContentCacheClear(ContentCacheClearEvent $event)
{
$contentInfo = $event->getContentInfo();
foreach ($this->locationService->loadLocations($contentInfo) as $location) {
$event->addLocationToClear($this->locationService->loadLocation($location->parentLocationId));
}
}
示例2: 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;
}
示例3: filterLimitationValues
public function filterLimitationValues(Limitation $limitation)
{
if (!is_array($limitation->limitationValues)) {
return;
}
// UDW returns an array of location IDs. If we haven't used UDW, the value is as stored: an array of path strings.
foreach ($limitation->limitationValues as $key => $limitationValue) {
if (preg_match('/\\A\\d+\\z/', $limitationValue) === 1) {
$limitation->limitationValues[$key] = $this->locationService->loadLocation($limitationValue)->pathString;
}
}
}
示例4: getPlaceListSorted
/**
* Returns all places contained in a place_list that are located between the range defined in
* the default configuration. A sort clause array can be provided in order to sort the results.
*
* @param int|string $locationId
* @param float $latitude
* @param float $longitude
* @param string|string[] $contentTypes to be retrieved
* @param int $maxDist Maximum distance for the search in km
* @param array $sortClauses
* @param string|string[] $languages to be retrieved
*
* @return \eZ\Publish\API\Repository\Values\Content\Content[]
*/
public function getPlaceListSorted($locationId, $latitude, $longitude, $contentTypes, $maxDist = null, $sortClauses = array(), $languages = array())
{
$location = $this->locationService->loadLocation($locationId);
if ($maxDist === null) {
$maxDist = $this->placeListMaxDist;
}
$query = new Query();
$query->filter = new Criterion\LogicalAnd(array(new Criterion\ContentTypeIdentifier($contentTypes), new Criterion\Subtree($location->pathString), new Criterion\LanguageCode($languages), new Criterion\MapLocationDistance("location", Criterion\Operator::BETWEEN, array($this->placeListMinDist, $maxDist), $latitude, $longitude)));
$query->sortClauses = $sortClauses;
$searchResults = $this->searchService->findContent($query);
return $this->searchHelper->buildListFromSearchResult($searchResults);
}
示例5: getChildNodesAction
/**
* Renders top menu with child items.
*
* @param string $template
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function getChildNodesAction($template)
{
$query = new LocationQuery();
$query->query = $this->menuCriteria->generateChildCriterion($this->locationService->loadLocation($this->topMenuLocationId), $this->configResolver->getParameter('languages'));
$query->sortClauses = [new SortClause\Location\Priority(LocationQuery::SORT_ASC)];
$query->performCount = false;
$content = $this->searchService->findLocations($query);
$menuItems = [];
foreach ($content->searchHits as $hit) {
$menuItems[] = $hit->valueObject;
}
return $this->templating->renderResponse($template, ['menuItems' => $menuItems], new Response());
}
示例6: 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;
}
示例7: assignUserToUserGroup
/**
* Assigns the user to a user group
*
* @param $userId
*
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
* @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList
*/
public function assignUserToUserGroup($userId)
{
$user = $this->userService->loadUser($userId);
try {
$userGroupLocation = $this->locationService->loadLocation($this->extractLocationIdFromPath($this->request->query->get('group')));
} catch (APINotFoundException $e) {
throw new Exceptions\ForbiddenException($e->getMessage());
}
try {
$userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId);
} catch (APINotFoundException $e) {
throw new Exceptions\ForbiddenException($e->getMessage());
}
try {
$this->userService->assignUserToUserGroup($user, $userGroup);
} catch (InvalidArgumentException $e) {
throw new Exceptions\ForbiddenException($e->getMessage());
}
$userGroups = $this->userService->loadUserGroupsOfUser($user);
$restUserGroups = array();
foreach ($userGroups as $userGroup) {
$userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
$userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
$contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
$restUserGroups[] = new Values\RestUserGroup($userGroup, $contentType, $userGroupContentInfo, $userGroupLocation, $this->contentService->loadRelations($userGroup->getVersionInfo()));
}
return new Values\UserGroupRefList($restUserGroups, $this->router->generate('ezpublish_rest_loadUserGroupsOfUser', array('userId' => $userId)), $userId);
}
示例8: 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');
}
示例9: fetchItems
/**
* Returns array of child content objects from given $locationId.
*
* @param int $locationId
* @param int $limit
*
* @return array
*/
private function fetchItems($locationId, $limit)
{
$languages = $this->configResolver->getParameter('languages');
$query = new Query();
$location = $this->locationService->loadLocation($locationId);
$query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
$query->performCount = false;
$query->limit = $limit;
$query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)];
$results = $this->searchService->findContent($query);
$items = [];
foreach ($results->searchHits as $item) {
$items[] = $item->valueObject;
}
return $items;
}
示例10: 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;
}
示例11: restoreTrashItem
/**
* Restores a trashItem.
*
* @param $trashItemId
*
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
*
* @return \eZ\Publish\Core\REST\Server\Values\ResourceCreated
*/
public function restoreTrashItem($trashItemId, Request $request)
{
$requestDestination = null;
try {
$requestDestination = $request->headers->get('Destination');
} catch (InvalidArgumentException $e) {
// No Destination header
}
$parentLocation = null;
if ($request->headers->has('Destination')) {
$locationPathParts = explode('/', $this->requestParser->parseHref($request->headers->get('Destination'), 'locationPath'));
try {
$parentLocation = $this->locationService->loadLocation(array_pop($locationPathParts));
} catch (NotFoundException $e) {
throw new ForbiddenException($e->getMessage());
}
}
$trashItem = $this->trashService->loadTrashItem($trashItemId);
if ($requestDestination === null) {
// If we're recovering under the original location
// check if it exists, to return "403 Forbidden" in case it does not
try {
$this->locationService->loadLocation($trashItem->parentLocationId);
} catch (NotFoundException $e) {
throw new ForbiddenException($e->getMessage());
}
}
$location = $this->trashService->recover($trashItem, $parentLocation);
return new Values\ResourceCreated($this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => trim($location->pathString, '/'))));
}
示例12: visit
/**
* Visit struct returned by controllers.
*
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
* @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
* @param \eZ\Publish\Core\REST\Server\Values\RestExecutedView $data
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
$generator->startObjectElement('View');
$visitor->setHeader('Content-Type', $generator->getMediaType('View'));
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_views_load', array('viewId' => $data->identifier)));
$generator->endAttribute('href');
$generator->startValueElement('identifier', $data->identifier);
$generator->endValueElement('identifier');
// BEGIN Query
$generator->startObjectElement('Query');
$generator->endObjectElement('Query');
// END Query
// BEGIN Result
$generator->startObjectElement('Result', 'ViewResult');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_views_load_results', array('viewId' => $data->identifier)));
$generator->endAttribute('href');
// BEGIN Result metadata
$generator->startValueElement('count', $data->searchResults->totalCount);
$generator->endValueElement('count');
$generator->startValueElement('time', $data->searchResults->time);
$generator->endValueElement('time');
$generator->startValueElement('timedOut', $generator->serializeBool($data->searchResults->timedOut));
$generator->endValueElement('timedOut');
$generator->startValueElement('maxScore', $data->searchResults->maxScore);
$generator->endValueElement('maxScore');
// END Result metadata
// BEGIN searchHits
$generator->startHashElement('searchHits');
$generator->startList('searchHit');
foreach ($data->searchResults->searchHits as $searchHit) {
$generator->startObjectElement('searchHit');
$generator->startAttribute('score', 0);
$generator->endAttribute('score');
$generator->startAttribute('index', 0);
$generator->endAttribute('index');
$generator->startObjectElement('value');
// @todo Refactor
if ($searchHit->valueObject instanceof ApiValues\Content) {
/** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */
$contentInfo = $searchHit->valueObject->contentInfo;
$valueObject = new RestContentValue($contentInfo, $this->locationService->loadLocation($contentInfo->mainLocationId), $searchHit->valueObject, $this->contentTypeService->loadContentType($contentInfo->contentTypeId), $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo()));
} elseif ($searchHit->valueObject instanceof ApiValues\Location) {
$valueObject = $searchHit->valueObject;
} elseif ($searchHit->valueObject instanceof ApiValues\ContentInfo) {
$valueObject = new RestContentValue($searchHit->valueObject);
} else {
throw new Exceptions\InvalidArgumentException('Unhandled object type');
}
$visitor->visitValueObject($valueObject);
$generator->endObjectElement('value');
$generator->endObjectElement('searchHit');
}
$generator->endList('searchHit');
$generator->endHashElement('searchHits');
// END searchHits
$generator->endObjectElement('Result');
// END Result
$generator->endObjectElement('View');
}
示例13: convert
/**
* Converts internal links (eznode:// and ezobject://) to URLs.
*
* @param \DOMDocument $xmlDoc
*
* @return string|null
*/
public function convert(DOMDocument $xmlDoc)
{
$xpath = new DOMXPath($xmlDoc);
$elements = $xpath->query('//link|//embed|//embed-inline');
/** @var \DOMElement $element */
foreach ($elements as $element) {
$location = null;
if ($this->elementHasAttribute($element, 'object_id')) {
try {
$contentInfo = $this->contentService->loadContentInfo($this->getElementAttribute($element, 'object_id'));
$location = $this->locationService->loadLocation($contentInfo->mainLocationId);
} catch (APINotFoundException $e) {
if ($this->logger) {
$this->logger->warning('While generating links for xmltext, could not locate ' . 'Content object with ID ' . $this->getElementAttribute($element, 'object_id'));
}
} catch (APIUnauthorizedException $e) {
if ($this->logger) {
$this->logger->notice('While generating links for xmltext, unauthorized to load ' . 'Content object with ID ' . $this->getElementAttribute($element, 'object_id'));
}
}
}
if ($this->elementHasAttribute($element, 'node_id')) {
try {
$location = $this->locationService->loadLocation($this->getElementAttribute($element, 'node_id'));
} catch (APINotFoundException $e) {
if ($this->logger) {
$this->logger->warning('While generating links for xmltext, could not locate ' . 'Location with ID ' . $this->getElementAttribute($element, 'node_id'));
}
} catch (APIUnauthorizedException $e) {
if ($this->logger) {
$this->logger->notice('While generating links for xmltext, unauthorized to load ' . 'Location with ID ' . $this->getElementAttribute($element, 'node_id'));
}
}
}
if ($location !== null) {
$element->setAttribute('url', $this->urlAliasRouter->generate($location));
}
// Copy temporary URL if it exists and is not set at this point
if (!$element->hasAttribute('url') && $element->hasAttribute(EmbedLinking::TEMP_PREFIX . 'url')) {
$element->setAttribute('url', $element->getAttribute(EmbedLinking::TEMP_PREFIX . 'url'));
}
if ($this->elementHasAttribute($element, 'anchor_name')) {
$element->setAttribute('url', $element->getAttribute('url') . '#' . $this->getElementAttribute($element, 'anchor_name'));
}
}
}
示例14: showBlogPostAction
/**
* Displays blog post content with random selected blog posts.
*
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
*
* @return \eZ\Publish\Core\MVC\Symfony\View\ContentView
*/
public function showBlogPostAction(ContentView $view)
{
$languages = $this->configResolver->getParameter('languages');
$location = $this->locationService->loadLocation($view->getLocation()->parentLocationId);
$query = new Query();
$query->query = $this->childrenCriteria->generateChildCriterion($location, $languages);
$query->performCount = false;
$query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)];
$results = $this->searchService->findContent($query);
$randomPosts = [];
foreach ($results->searchHits as $item) {
$randomPosts[] = $item->valueObject;
}
shuffle($randomPosts);
$view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'randomPosts' => array_slice($randomPosts, 0, $this->randomPostsLimit, true)]);
return $view;
}
示例15: getMenuItems
/**
* Queries the repository for menu items, as locations filtered on the list in TopIdentifierList in menu.ini
* @param int|string $rootLocationId Root location for menu items. Only two levels below this one are searched
* @return SearchHit[]
*/
private function getMenuItems($rootLocationId)
{
$rootLocation = $this->locationService->loadLocation($rootLocationId);
$query = new LocationQuery();
$query->query = new Criterion\LogicalAnd(array(new Criterion\ContentTypeIdentifier($this->getTopMenuContentTypeIdentifierList()), new Criterion\Visibility(Criterion\Visibility::VISIBLE), new Criterion\Location\Depth(Criterion\Operator::BETWEEN, array($rootLocation->depth + 1, $rootLocation->depth + 2)), new Criterion\Subtree($rootLocation->pathString), new Criterion\LanguageCode($this->configResolver->getParameter('languages'))));
$query->sortClauses = array(new Query\SortClause\Location\Path());
return $this->searchService->findLocations($query)->searchHits;
}