/** * removes a role from the given user. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the role is not assigned to the user * * @param \eZ\Publish\API\Repository\Values\User\Role $role * @param \eZ\Publish\API\Repository\Values\User\User $user */ public function unassignRoleFromUser(APIRole $role, User $user) { $values = $this->requestParser->parse('user', $user->id); $userId = $values['user']; $values = $this->requestParser->parse('role', $role->id); $roleId = $values['role']; $response = $this->client->request('DELETE', $this->requestParser->generate('userRoleAssignment', array('user' => $userId, 'role' => $roleId)), new Message(array('Accept' => $this->outputVisitor->getMediaType('RoleAssignmentList')))); if (!empty($response->body)) { $this->inputDispatcher->parse($response); } }
/** * Gets the object-state of object identified by $contentId. * * The $state is the id of the state within one group. * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup * * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectState */ public function getContentState(ContentInfo $contentInfo, ObjectStateGroup $objectStateGroup) { $values = $this->requestParser->parse('object', $contentInfo->id); $groupValues = $this->requestParser->parse('objectstategroup', $objectStateGroup->id); $response = $this->client->request('GET', $this->requestParser->generate('objectObjectStates', array('object' => $values['object'])), new Message(array('Accept' => $this->outputVisitor->getMediaType('ContentObjectStates')))); $objectStates = $this->inputDispatcher->parse($response); foreach ($objectStates as $state) { $stateValues = $this->requestParser->parse('objectstate', $state->id); if ($stateValues['objectstategroup'] == $groupValues['objectstategroup']) { return $state; } } }
/** * Loads content in a version of the given content object. * * If no version number is given, the method returns the current version * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given id does not exist * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version * * @param int $contentId * @param array $languages A language filter for fields. If not given all languages are returned * @param int $versionNo the version number. If not given the current version is returned * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true * * @return \eZ\Publish\API\Repository\Values\Content\Content * @todo Handle $versionNo = null * @todo Handle language filters */ public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) { // $contentId should already be a URL! $contentIdValues = $this->requestParser->parse('object', $contentId); $url = ''; if ($versionNo === null) { $url = $this->fetchCurrentVersionUrl($this->requestParser->generate('objectCurrentVersion', array('object' => $contentIdValues['object']))); } else { $url = $this->requestParser->generate('objectVersion', array('object' => $contentIdValues['object'], 'version' => $versionNo)); } $response = $this->client->request('GET', $url, new Message(array('Accept' => $this->outputVisitor->getMediaType('Version')))); return $this->inputDispatcher->parse($response); }
/** * Unassign a content type from a group. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to link a content type * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the content type is not assigned this the given group. * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If $contentTypeGroup is the last group assigned to the content type * * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $contentTypeGroup */ public function unassignContentTypeGroup(ContentType $contentType, ContentTypeGroup $contentTypeGroup) { if ($contentType instanceof ContentTypeDraft) { $urlValues = $this->requestParser->parse("typeDraft", $contentType->id); } else { $urlValues = $this->requestParser->parse("type", $contentType->id); } $groupUrlValues = $this->requestParser->parse("typegroup", $contentTypeGroup->id); $urlValues["group"] = $groupUrlValues["typegroup"]; $response = $this->client->request('DELETE', $this->requestParser->generate('groupOfType', $urlValues), new Message(array('Accept' => $this->outputVisitor->getMediaType('ContentTypeGroupRefList')))); if ($this->isErrorResponse($response)) { try { $this->inputDispatcher->parse($response); } catch (ForbiddenException $e) { throw new InvalidArgumentException($e->getMessage(), $e->getCode()); } catch (NotFoundException $e) { throw new BadStateException($e->getMessage(), $e->getCode()); } } }
/** * Parses the given $id for $type into its raw form. * * Takes a repository specific $id of $type and returns the raw database ID * for the object. * * @param string $type * @param mixed $id * * @return mixed */ public function parseId($type, $id) { $values = $this->requestParser->parse($type, $id); return $values[$type]; }
/** * Loads children which are readable by the current user of a location object sorted by sortField and sortOrder * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * * @param int $offset the start offset for paging * @param int $limit the number of locations returned. If $limit = -1 all children starting at $offset are returned * * @return \eZ\Publish\API\Repository\Values\Content\LocationList */ public function loadLocationChildren(Location $location, $offset = 0, $limit = -1) { $values = $this->requestParser->parse('location', $location->id); $response = $this->client->request('GET', $this->requestParser->generate('locationChildren', array('location' => $values['location'])), new Message(array('Accept' => $this->outputVisitor->getMediaType('LocationList')))); return $this->inputDispatcher->parse($response); }