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 function testMarshall()
 {
     $gapText = new GapText('gapText1', 1);
     $gapText->setContent(new TextOrVariableCollection(array(new TextRun('My var is '), new PrintedVariable('var1'))));
     $marshaller = $this->getMarshallerFactory()->createMarshaller($gapText);
     $element = $marshaller->marshall($gapText);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<gapText identifier="gapText1" matchMax="1">My var is <printedVariable identifier="var1" base="10" powerForm="false" delimiter=";" mappingIndicator="="/></gapText>', $dom->saveXML($element));
 }
 public function testMarshall()
 {
     $gapText = new GapText('gapText1', 1);
     $gapText->setContent(new TextOrVariableCollection(array(new TextRun('This is gapText1'))));
     $object = new Object("./myimg.png", "image/png");
     $gapImg = new GapImg('gapImg1', 1, $object);
     $gap1 = new Gap('G1');
     $gap2 = new Gap('G2');
     $p = new P();
     $p->setContent(new InlineCollection(array(new TextRun('A text... '), $gap1, new TextRun(' and an image... '), $gap2)));
     $gapMatch = new GapMatchInteraction('RESPONSE', new GapChoiceCollection(array($gapText, $gapImg)), new BlockStaticCollection(array($p)));
     $marshaller = $this->getMarshallerFactory()->createMarshaller($gapMatch);
     $element = $marshaller->marshall($gapMatch);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<gapMatchInteraction responseIdentifier="RESPONSE"><gapText identifier="gapText1" matchMax="1">This is gapText1</gapText><gapImg identifier="gapImg1" matchMax="1"><object data="./myimg.png" type="image/png"/></gapImg><p>A text... <gap identifier="G1"/> and an image... <gap identifier="G2"/></p></gapMatchInteraction>', $dom->saveXML($element));
 }
Ejemplo n.º 5
0
 public function testMarshall20()
 {
     $gapText = new GapText('gapText1', 3);
     // Make sure that in QTI 2.0, printed variables are not taken into account at output time...
     $gapText->setContent(new TextOrVariableCollection(array(new TextRun('Some text...'), new PrintedVariable('id1'))));
     // Make sure there is no output for matchMin, templateIdentifier, showHide.
     $gapText->setMatchMin(1);
     $gapText->setTemplateIdentifier('XTEMPLATE');
     $gapText->setShowHide(ShowHide::HIDE);
     // But output for matchGroup attribute which is valid in QTI 2.0.
     $gapText->setMatchGroup(new IdentifierCollection(array('identifier1', 'id2')));
     $marshaller = $this->getMarshallerFactory('2.0.0')->createMarshaller($gapText);
     $element = $marshaller->marshall($gapText);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<gapText identifier="gapText1" matchMax="3" matchGroup="identifier1 id2">Some text...</gapText>', $dom->saveXML($element));
 }