/** * 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); }
/** * 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'); }
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); } } }
/** * 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'); }
/** * 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); }