本文整理汇总了PHP中eZ\Publish\API\Repository\ContentService::loadRelations方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentService::loadRelations方法的具体用法?PHP ContentService::loadRelations怎么用?PHP ContentService::loadRelations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\API\Repository\ContentService
的用法示例。
在下文中一共展示了ContentService::loadRelations方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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');
}
示例3: onContentCacheClear
public function onContentCacheClear(ContentCacheClearEvent $event)
{
$contentInfo = $event->getContentInfo();
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
foreach ($this->contentService->loadRelations($versionInfo) as $relation) {
foreach ($this->locationService->loadLocations($relation->getDestinationContentInfo()) as $relatedLocation) {
$event->addLocationToClear($relatedLocation);
}
}
// Using sudo since loading reverse relations is conditioned to content/reverserelatedlist permission and we don't need this check here.
/** @var \eZ\Publish\API\Repository\Values\Content\Relation[] $reverseRelations */
$reverseRelations = $this->repository->sudo(function () use($contentInfo) {
return $this->contentService->loadReverseRelations($contentInfo);
});
foreach ($reverseRelations as $reverseRelation) {
foreach ($this->locationService->loadLocations($reverseRelation->getSourceContentInfo()) as $relatedLocation) {
$event->addLocationToClear($relatedLocation);
}
}
}
示例4: 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_getView', 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_loadViewResults', array('viewId' => $data->identifier)));
$generator->endAttribute('href');
// 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');
/** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */
$contentInfo = $searchHit->valueObject->contentInfo;
$restContent = new RestContentValue($contentInfo, $this->locationService->loadLocation($contentInfo->mainLocationId), $searchHit->valueObject, $this->contentTypeService->loadContentType($contentInfo->contentTypeId), $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo()));
$visitor->visitValueObject($restContent);
$generator->endObjectElement('value');
$generator->endObjectElement('searchHit');
}
$generator->endList('searchHit');
$generator->endHashElement('searchHits');
// END searchHits
$generator->endObjectElement('Result');
// END Result
$generator->endObjectElement('View');
}
示例5: loadRelations
/**
* Loads all outgoing relations for the given version
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
*
* @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
*
* @return \eZ\Publish\API\Repository\Values\Content\Relation[]
*/
public function loadRelations(VersionInfo $versionInfo)
{
return $this->service->loadRelations($versionInfo);
}