本文整理汇总了PHP中eZ\Publish\API\Repository\LocationService类的典型用法代码示例。如果您正苦于以下问题:PHP LocationService类的具体用法?PHP LocationService怎么用?PHP LocationService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocationService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onContentCacheClear
public function onContentCacheClear(ContentCacheClearEvent $event)
{
$contentInfo = $event->getContentInfo();
foreach ($this->locationService->loadLocations($contentInfo) as $location) {
$event->addLocationToClear($location);
}
}
示例2: parse
/**
* Parse input structure
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!array_key_exists('ParentLocation', $data) || !is_array($data['ParentLocation'])) {
throw new Exceptions\Parser("Missing or invalid 'ParentLocation' element for LocationCreate.");
}
if (!array_key_exists('_href', $data['ParentLocation'])) {
throw new Exceptions\Parser("Missing '_href' attribute for ParentLocation element in LocationCreate.");
}
$locationHrefParts = explode('/', $this->requestParser->parseHref($data['ParentLocation']['_href'], 'locationPath'));
$locationCreateStruct = $this->locationService->newLocationCreateStruct(array_pop($locationHrefParts));
if (array_key_exists('priority', $data)) {
$locationCreateStruct->priority = (int) $data['priority'];
}
if (array_key_exists('hidden', $data)) {
$locationCreateStruct->hidden = $this->parserTools->parseBooleanValue($data['hidden']);
}
if (array_key_exists('remoteId', $data)) {
$locationCreateStruct->remoteId = $data['remoteId'];
}
if (!array_key_exists('sortField', $data)) {
throw new Exceptions\Parser("Missing 'sortField' element for LocationCreate.");
}
$locationCreateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']);
if (!array_key_exists('sortOrder', $data)) {
throw new Exceptions\Parser("Missing 'sortOrder' element for LocationCreate.");
}
$locationCreateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);
return $locationCreateStruct;
}
示例3: 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;
}
示例4: testGetPreviewLocationNoLocation
public function testGetPreviewLocationNoLocation()
{
$contentId = 123;
$contentInfo = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo')->setConstructorArgs(array(array('id' => $contentId)))->getMockForAbstractClass();
$this->contentService->expects($this->once())->method('loadContentInfo')->with($contentId)->will($this->returnValue($contentInfo));
$this->locationHandler->expects($this->once())->method('loadParentLocationsForDraftContent')->with($contentId)->will($this->returnValue(array()));
$this->locationHandler->expects($this->never())->method('loadLocation');
$this->assertNull($this->provider->loadMainLocation($contentId));
}
示例5: 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);
}
示例6: 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;
}
}
}
示例7: parse
/**
* Parses input structure to a Criterion object.
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser
*
* @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ParentLocationId
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!array_key_exists('ParentLocationRemoteIdCriterion', $data)) {
throw new Exceptions\Parser('Invalid <ParentLocationRemoteIdCriterion> format');
}
$contentIdArray = array();
foreach (explode(',', $data['ParentLocationRemoteIdCriterion']) as $parentRemoteId) {
$location = $this->locationService->loadLocationByRemoteId($parentRemoteId);
$contentIdArray[] = $location->id;
}
return new ParentLocationIdCriterion($contentIdArray);
}
示例8: 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);
}
示例9: 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\API\Repository\Values\Content\Location $location
*/
public function visit(Visitor $visitor, Generator $generator, $location)
{
$generator->startObjectElement('Location');
$visitor->setHeader('Content-Type', $generator->getMediaType('Location'));
$visitor->setHeader('Accept-Patch', $generator->getMediaType('LocationUpdate'));
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => trim($location->pathString, '/'))));
$generator->endAttribute('href');
$generator->startValueElement('id', $location->id);
$generator->endValueElement('id');
$generator->startValueElement('priority', $location->priority);
$generator->endValueElement('priority');
$generator->startValueElement('hidden', $this->serializeBool($generator, $location->hidden));
$generator->endValueElement('hidden');
$generator->startValueElement('invisible', $this->serializeBool($generator, $location->invisible));
$generator->endValueElement('invisible');
$generator->startObjectElement('ParentLocation', 'Location');
if (trim($location->pathString, '/') !== '1') {
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadLocation', array('locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1)))));
$generator->endAttribute('href');
}
$generator->endObjectElement('ParentLocation');
$generator->startValueElement('pathString', $location->pathString);
$generator->endValueElement('pathString');
$generator->startValueElement('depth', $location->depth);
$generator->endValueElement('depth');
$generator->startValueElement('childCount', $this->locationService->getLocationChildCount($location));
$generator->endValueElement('childCount');
$generator->startValueElement('remoteId', $location->remoteId);
$generator->endValueElement('remoteId');
$generator->startObjectElement('Children', 'LocationList');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadLocationChildren', array('locationPath' => trim($location->pathString, '/'))));
$generator->endAttribute('href');
$generator->endObjectElement('Children');
$generator->startObjectElement('Content');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $location->contentId)));
$generator->endAttribute('href');
$generator->endObjectElement('Content');
$generator->startValueElement('sortField', $this->serializeSortField($location->sortField));
$generator->endValueElement('sortField');
$generator->startValueElement('sortOrder', $this->serializeSortOrder($location->sortOrder));
$generator->endValueElement('sortOrder');
$generator->startObjectElement('UrlAliases', 'UrlAliasRefList');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_listLocationURLAliases', array('locationPath' => trim($location->pathString, '/'))));
$generator->endAttribute('href');
$generator->endObjectElement('UrlAliases');
$generator->startObjectElement('ContentInfo', 'ContentInfo');
$generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $location->contentId)));
$generator->endAttribute('href');
$visitor->visitValueObject(new RestContentValue($location->contentInfo));
$generator->endObjectElement('ContentInfo');
$generator->endObjectElement('Location');
}
示例10: 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());
}
示例11: createWithoutDraftAction
/**
* Displays and processes a content creation form. Showing the form does not create a draft in the repository.
*
* @param int $contentTypeIdentifier ContentType id to create
* @param string $language Language code to create the content in (eng-GB, ger-DE, ...))
* @param int $parentLocationId Location the content should be a child of
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function createWithoutDraftAction($contentTypeIdentifier, $language, $parentLocationId, Request $request)
{
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
$data = (new ContentCreateMapper())->mapToFormData($contentType, ['mainLanguageCode' => $language, 'parentLocation' => $this->locationService->newLocationCreateStruct($parentLocationId)]);
$form = $this->createForm(ContentEditType::class, $data, ['languageCode' => $language]);
$form->handleRequest($request);
if ($form->isValid()) {
$this->contentActionDispatcher->dispatchFormAction($form, $data, $form->getClickedButton()->getName());
if ($response = $this->contentActionDispatcher->getResponse()) {
return $response;
}
}
return $this->render('EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig', ['form' => $form->createView(), 'languageCode' => $language, 'pagelayout' => $this->pagelayout]);
}
示例12: 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;
}
示例13: 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, '/'))));
}
示例14: getLocationCreateStruct
/**
* Creates and prepares location create structure.
*
* @param array $data
* @param int $defaultLocationId
* @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
*/
private function getLocationCreateStruct($data, $defaultLocationId)
{
$parentLocationId = $this->getContentDataParentLocationId($data, $defaultLocationId);
$locationStruct = $this->locationService->newLocationCreateStruct($parentLocationId);
$locationStruct->priority = isset($data['priority']) ? $data['priority'] : 0;
return $locationStruct;
}
示例15: 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);
}