/** * 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); }
/** * Loads a object state group. * * @param mixed $objectStateGroupId * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the group was not found * * @return \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup */ public function loadObjectStateGroup($objectStateGroupId) { return $this->service->loadObjectStateGroup($objectStateGroupId); }