/** * Parse input structure. * * @param array $data * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher * * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct */ public function parse(array $data, ParsingDispatcher $parsingDispatcher) { if (!array_key_exists('identifier', $data)) { throw new Exceptions\Parser("Missing 'identifier' attribute for ObjectStateCreate."); } $objectStateCreateStruct = $this->objectStateService->newObjectStateCreateStruct($data['identifier']); if (!array_key_exists('priority', $data)) { throw new Exceptions\Parser("Missing 'priority' attribute for ObjectStateCreate."); } $objectStateCreateStruct->priority = (int) $data['priority']; if (!array_key_exists('defaultLanguageCode', $data)) { throw new Exceptions\Parser("Missing 'defaultLanguageCode' attribute for ObjectStateCreate."); } $objectStateCreateStruct->defaultLanguageCode = $data['defaultLanguageCode']; if (!array_key_exists('names', $data) || !is_array($data['names'])) { throw new Exceptions\Parser("Missing or invalid 'names' element for ObjectStateCreate."); } if (!array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) { throw new Exceptions\Parser("Missing or invalid 'names' element for ObjectStateCreate."); } $objectStateCreateStruct->names = $this->parserTools->parseTranslatableList($data['names']); // @todo XSD says that descriptions field is mandatory. Does that make sense? if (array_key_exists('descriptions', $data) && is_array($data['descriptions'])) { $objectStateCreateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']); } return $objectStateCreateStruct; }
protected function getSelectionChoices() { $choices = []; foreach ($this->objectStateService->loadObjectStateGroups() as $group) { foreach ($this->objectStateService->loadObjectStates($group) as $state) { $choices[$state->id] = $state->getName($state->defaultLanguageCode); } } return $choices; }
/** * Updates object states of content * An object state in the input overrides the state of the object state group. * * @param $contentId * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException * * @return \eZ\Publish\Core\REST\Common\Values\ContentObjectStates */ public function setObjectStatesForContent($contentId, Request $request) { $newObjectStates = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent())); $countByGroups = array(); foreach ($newObjectStates as $newObjectState) { $groupId = (int) $newObjectState->groupId; if (array_key_exists($groupId, $countByGroups)) { ++$countByGroups[$groupId]; } else { $countByGroups[$groupId] = 1; } } foreach ($countByGroups as $groupId => $count) { if ($count > 1) { throw new ForbiddenException("Multiple object states provided for group with ID {$groupId}"); } } $contentInfo = $this->contentService->loadContentInfo($contentId); $contentObjectStates = array(); foreach ($newObjectStates as $newObjectState) { $objectStateGroup = $this->objectStateService->loadObjectStateGroup($newObjectState->groupId); $this->objectStateService->setContentState($contentInfo, $objectStateGroup, $newObjectState->objectState); $contentObjectStates[(int) $objectStateGroup->id] = $newObjectState; } return new ContentObjectStates($contentObjectStates); }
/** * Parse input structure. * * @param array $data * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher * * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct */ public function parse(array $data, ParsingDispatcher $parsingDispatcher) { if (!array_key_exists('identifier', $data)) { throw new Exceptions\Parser("Missing 'identifier' attribute for ObjectStateGroupCreate."); } $objectStateGroupCreateStruct = $this->objectStateService->newObjectStateGroupCreateStruct($data['identifier']); if (!array_key_exists('defaultLanguageCode', $data)) { throw new Exceptions\Parser("Missing 'defaultLanguageCode' attribute for ObjectStateGroupCreate."); } $objectStateGroupCreateStruct->defaultLanguageCode = $data['defaultLanguageCode']; if (!array_key_exists('names', $data) || !is_array($data['names'])) { throw new Exceptions\Parser("Missing or invalid 'names' element for ObjectStateGroupCreate."); } if (!array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) { throw new Exceptions\Parser("Missing or invalid 'names' element for ObjectStateGroupCreate."); } $objectStateGroupCreateStruct->names = $this->parserTools->parseTranslatableList($data['names']); if (array_key_exists('descriptions', $data) && is_array($data['descriptions'])) { $objectStateGroupCreateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']); } return $objectStateGroupCreateStruct; }
/** * Instantiates a new Object State Update Struct. * * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct */ public function newObjectStateUpdateStruct() { return $this->service->newObjectStateUpdateStruct(); }