public function getQuestionType() { $interactionComponents = $this->itemBody->getComponentsByClassName('inlineChoiceInteraction', true); $interactionXmls = []; $possibleResponsesMap = []; foreach ($interactionComponents as $component) { /** @var Interaction $component */ $interactionXmls[] = QtiMarshallerUtil::marshall($component); /** @var InlineChoice $inlineChoice */ foreach ($component->getComponents() as $inlineChoice) { $possibleResponsesMap[$component->getResponseIdentifier()][$inlineChoice->getIdentifier()] = QtiMarshallerUtil::marshallCollection($inlineChoice->getContent()); } } $template = $this->buildTemplate($this->itemBody, $interactionXmls); $clozedropdown = new clozedropdown('clozedropdown', $template, array_values(array_map('array_values', $possibleResponsesMap))); $validationBuilder = new InlineChoiceInteractionValidationBuilder($this->responseDeclarations, $possibleResponsesMap); // Build `validation` $validation = $validationBuilder->buildValidation($this->responseProcessingTemplate); if (!empty($validation)) { $clozedropdown->set_validation($validation); } return $clozedropdown; }
private function buildValidation() { $validationBuilder = new InlineChoiceInteractionValidationBuilder([$this->interaction->getResponseIdentifier() => $this->responseDeclaration], [$this->interaction->getResponseIdentifier() => $this->choicesMapping]); return $validationBuilder->buildValidation($this->responseProcessingTemplate); }