validate(); $itemIdentifier = $this->hasRequestParameter('itemDefinition') ? $this->getRequestParameter('itemDefinition') : null; if (!is_array($itemIdentifier)) { $itemIdentifier = [$itemIdentifier]; } try { if (!$this->getRunnerService()->getTestConfig()->getConfigValue('itemCaching.enabled')) { common_Logger::w('Attempt to disclose the next items without the configuration'); throw new common_exception_Unauthorized(); } $response = []; foreach ($itemIdentifier as $itemId) { //load item data $response['items'][] = $this->getItemData($itemId); } if (isset($response['items'])) { $response['success'] = true; } } catch (\Exception $e) { $response = $this->getErrorResponse($e); } return $response; } /** * Create the item definition response for a given item * @param string $itemIdentifier the item id * @return array the item data * @throws \common_Exception */ protected function getItemData($itemIdentifier) { $serviceContext = $this->getServiceContext(); $itemRef = $this->getRunnerService()->getItemHref($serviceContext, $itemIdentifier); $itemData = $this->getRunnerService()->getItemData($serviceContext, $itemRef); $baseUrl = $this->getRunnerService()->getItemPublicUrl($serviceContext, $itemRef); $portableElements = $this->getRunnerService()->getItemPortableElements($serviceContext, $itemRef); $itemState = $this->getRunnerService()->getItemState($serviceContext, $itemIdentifier); if ($itemState === null || !count($itemState)) { $itemState = new stdClass(); } return [ 'baseUrl' => $baseUrl, 'itemData' => $itemData, 'itemState' => $itemState, 'itemIdentifier' => $itemIdentifier, 'portableElements' => $portableElements ]; } /** * `itemDefinition` field is required. * * @return array */ protected function getRequiredFields() { return array_merge(parent::getRequiredFields(), ['itemDefinition']); } }