public static function buildGapMatchInteraction($identifier, array $gapTextList, array $gapImgList, array $gapList)
 {
     $gapChoiceCollection = new GapChoiceCollection();
     foreach ($gapTextList as $identifier => $contentStr) {
         $gapText = new GapText($identifier, 1);
         $content = new TextOrVariableCollection();
         $content->attach(new TextRun($contentStr));
         $gapText->setContent($content);
         $gapChoiceCollection->attach($gapText);
     }
     foreach ($gapImgList as $identifier => $imagedURL) {
         $obj = new Object($imagedURL, 'image/png');
         $gapImg = new GapImg($identifier, 1, $obj);
         $gapChoiceCollection->attach($gapImg);
     }
     $content = new BlockStaticCollection();
     $p = new P();
     $inlineCollection = new InlineCollection();
     foreach ($gapList as $gapIdentifier) {
         $gap = new Gap($gapIdentifier);
         $inlineCollection->attach($gap);
     }
     $p->setContent($inlineCollection);
     $content->attach($p);
     return new GapMatchInteraction($identifier, $gapChoiceCollection, $content);
 }
 public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel)
 {
     //TODO: Need validation a question shall have at least 1 {{response}} and 1 item in `possible_responses`
     /** @var clozeassociation $question */
     $question = $questionType;
     // Replace {{ response }} with `gap` elements
     $index = 0;
     $template = preg_replace_callback('/{{response}}/', function ($match) use(&$index) {
         $gapIdentifier = self::GAP_IDENTIFIER_PREFIX . $index;
         $replacement = '<gap identifier="' . $gapIdentifier . '"/>';
         $index++;
         return $replacement;
     }, $question->get_template());
     $content = ContentCollectionBuilder::buildBlockStaticCollectionContent(QtiMarshallerUtil::unmarshallElement($template));
     // Map `possible_responses` to gaps
     // TODO: Detect `img`
     $gapChoices = new GapChoiceCollection();
     $possibleResponses = $question->get_possible_responses();
     $matchMax = $question->get_duplicate_responses() ? count($possibleResponses) : 1;
     foreach ($possibleResponses as $index => $possibleResponse) {
         $gapChoice = new GapText(self::GAPCHOICE_IDENTIFIER_PREFIX . $index, $matchMax);
         $gapChoiceContent = new TextOrVariableCollection();
         $gapChoiceContent->attach(new TextRun($possibleResponse));
         $gapChoice->setContent($gapChoiceContent);
         $gapChoices->attach($gapChoice);
     }
     $interaction = new GapMatchInteraction($interactionIdentifier, $gapChoices, $content);
     $interaction->setLabel($interactionLabel);
     $interaction->setPrompt($this->convertStimulusForPrompt($question->get_stimulus()));
     $validationBuilder = new ClozeassociationValidationBuilder($possibleResponses);
     list($responseDeclaration, $responseProcessing) = $validationBuilder->buildValidation($interaction->getResponseIdentifier(), $question->get_validation());
     return [$interaction, $responseDeclaration, $responseProcessing];
 }
 public static function buildSimple($responseIdentifier, array $identifierTextRunContentMap)
 {
     $collection = new InlineChoiceCollection();
     foreach ($identifierTextRunContentMap as $identifier => $textRunContent) {
         $inlineChoice = new InlineChoice($identifier);
         $textOrVariableCollection = new TextOrVariableCollection();
         $textOrVariableCollection->attach(new TextRun($textRunContent));
         $inlineChoice->setContent($textOrVariableCollection);
         $collection->attach($inlineChoice);
     }
     return new InlineChoiceInteraction($responseIdentifier, $collection);
 }
 public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel)
 {
     /** @var clozedropdown $question */
     $question = $questionType;
     // Extra text that can't be mapped since we are in textEntryInteraction which does not have prompt
     $this->extraContent = $question->get_stimulus();
     // Replace {{ response }} with `textEntryInteraction` elements
     $valueIdentifierMapPerInlineChoices = [];
     $index = 0;
     $possibleResponses = $question->get_possible_responses();
     $template = preg_replace_callback('/{{response}}/', function ($match) use(&$index, &$valueIdentifierMapPerInlineChoices, $possibleResponses, $interactionIdentifier, $interactionLabel) {
         $inlineChoiceCollection = new InlineChoiceCollection();
         if (!isset($possibleResponses[$index])) {
             throw new MappingException('Invalid `possible_responses`, missing entries');
         }
         foreach ($possibleResponses[$index] as $choiceIndex => $choiceValue) {
             $inlineChoiceIdentifier = 'INLINECHOICE_' . $choiceIndex;
             $valueIdentifierMapPerInlineChoices[$index][$choiceValue] = $inlineChoiceIdentifier;
             // Update this map so can be used later upon building responseDeclaration objects
             $inlineChoice = new InlineChoice($inlineChoiceIdentifier);
             $inlineChoiceContent = new TextOrVariableCollection();
             $inlineChoiceContent->attach(new TextRun($choiceValue));
             $inlineChoice->setContent($inlineChoiceContent);
             $inlineChoiceCollection->attach($inlineChoice);
         }
         $interaction = new InlineChoiceInteraction($interactionIdentifier . '_' . $index, $inlineChoiceCollection);
         $interaction->setLabel($interactionLabel);
         $index++;
         $replacement = QtiMarshallerUtil::marshall($interaction);
         return $replacement;
     }, $question->get_template());
     // Wrap this interaction in a block since our `clozedropdown` `template` meant to be blocky and not inline
     $div = new Div();
     $div->setClass('lrn-template');
     $div->setContent(ContentCollectionBuilder::buildFlowCollectionContent(QtiMarshallerUtil::unmarshallElement($template)));
     // Build validation
     $validationBuilder = new ClozedropdownValidationBuilder($valueIdentifierMapPerInlineChoices);
     list($responseDeclaration, $responseProcessing) = $validationBuilder->buildValidation($interactionIdentifier, $question->get_validation());
     return [$div, $responseDeclaration, $responseProcessing];
 }