getValue(); switch ($var->getCardinality()) { case 'record': case 'single': if (strlen($value) === 0) { $formatted = ['base' => null]; } else { try { $formatted = ['base' => [$var->getBaseType() => self::formatStringValue($var->getBaseType(), $value)]]; } catch (\common_exception_NotImplemented $e) { // simply ignore unsupported data/type $formatted = ['base' => null]; } } break; case 'ordered': case 'multiple': $list = []; if(!empty($value) && preg_match('/^\s*[\[|<](.*)[\]>]\s*$/', $value, $content) ) { $matches = explode(';', $content[1]); foreach ($matches as $valueString) { if (empty(trim($valueString))) { continue; } try { $list[] = self::formatStringValue($var->getBaseType(), trim($valueString, " '")); } catch (\common_exception_NotImplemented $e) { // simply ignore unsupported data/type } } } $formatted = ['list' => [$var->getBaseType() => $list]]; break; default: throw new \common_Exception('unknown response cardinality'); } return $formatted; } /** * Format the output of oat\taoOutcomeUi\model\ResultsService::getStructuredVariables() into a client usable array * * @param array $testResultVariables - the array output from oat\taoOutcomeUi\model\ResultsService::getStructuredVariables(); * @param array $itemFilter = [] - the array of item uri to be included in the formatted output, all item if empty. * @return array * @throws \common_Exception */ public static function formatStructuredVariablesToItemState($testResultVariables, $itemFilter = []) { $formatted = []; foreach ($testResultVariables as $itemResult) { if (!isset($itemResult['uri'])) { continue; } $itemUri = $itemResult['uri']; if (!empty($itemFilter) && !in_array($itemUri, $itemFilter)) { continue; } $itemResults = []; foreach ($itemResult['taoResultServer_models_classes_ResponseVariable'] as $var) { /** * @var $responseVariable \taoResultServer_models_classes_ResponseVariable */ $responseVariable = $var['var']; if ($responseVariable->getBaseType() === 'file') { $itemResults[$responseVariable->getIdentifier()] = [ 'response' => ['base' => ['file' => ['uri' => $var['uri']]]] ]; } else { $itemResults[$responseVariable->getIdentifier()] = [ 'response' => self::formatVariableToPci($responseVariable) ]; } } $formatted[$itemUri][$itemResult['attempt']] = $itemResults; } return $formatted; } }