private function buildValidation(HottextInteraction $interaction)
 {
     $hottextComponents = array_flip(array_map(function ($component) {
         return $component->getIdentifier();
     }, $interaction->getComponentsByClassName('hottext')->getArrayCopy(true)));
     $validationBuilder = new HottextInteractionValidationBuilder($hottextComponents, $interaction->getMaxChoices(), $this->responseDeclaration);
     return $validationBuilder->buildValidation($this->responseProcessingTemplate);
 }
 /**
  * @depends testMarshall21
  */
 public function testMarshallNoOutputMinStrings20()
 {
     // Make sure no output for minStrings in a QTI 2.0 context.
     $hottext = new Hottext('hottext1');
     $hottext->setContent(new InlineStaticCollection(array(new TextRun('hot'))));
     $div = new Div();
     $div->setContent(new FlowCollection(array(new TextRun('This is a '), new Hottext('hot1'), new TextRun(' text...'))));
     $content = new BlockStaticCollection(array($div));
     $hottextInteraction = new HottextInteraction('RESPONSE', $content);
     $hottextInteraction->setMinChoices(1);
     $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($hottextInteraction)->marshall($hottextInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<hottextInteraction responseIdentifier="RESPONSE"><div>This is a <hottext identifier="hot1"/> text...</div></hottextInteraction>', $dom->saveXML($element));
 }
 public function testMarshall()
 {
     $hottext = new Hottext('hottext1');
     $hottext->setContent(new InlineStaticCollection(array(new TextRun('hot'))));
     $div = new Div();
     $div->setContent(new FlowCollection(array(new TextRun('This is a '), new Hottext('hot1'), new TextRun(' text...'))));
     $content = new BlockStaticCollection(array($div));
     $hottextInteraction = new HottextInteraction('RESPONSE', $content);
     $prompt = new Prompt();
     $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...'))));
     $hottextInteraction->setPrompt($prompt);
     $element = $this->getMarshallerFactory()->createMarshaller($hottextInteraction)->marshall($hottextInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<hottextInteraction responseIdentifier="RESPONSE"><prompt>Prompt...</prompt><div>This is a <hottext identifier="hot1"/> text...</div></hottextInteraction>', $dom->saveXML($element));
 }
 public function convert(BaseQuestionType $question, $interactionIdentifier, $interactionLabel)
 {
     /** @var tokenhighlight $question */
     // Grab those `template` and convert those highlights to <hottext>
     $html = new SimpleHtmlDom();
     $html->load($question->get_template());
     $tokens = $html->find('span.lrn_token');
     $indexIdentifierMap = [];
     foreach ($tokens as $key => &$span) {
         $span->outertext = '<hottext identifier="TOKEN_' . intval($key) . '">' . $span->innertext . '</hottext>';
         $indexIdentifierMap[$key] = 'TOKEN_' . intval($key);
     }
     $htmlContent = $html->save();
     $contentComponents = QtiMarshallerUtil::unmarshallElement($htmlContent);
     $contentCollection = ContentCollectionBuilder::buildBlockStaticCollectionContent($contentComponents);
     // Build the interaction
     $interaction = new HottextInteraction($interactionIdentifier, $contentCollection);
     $interaction->setLabel($interactionLabel);
     $interaction->setPrompt($this->convertStimulusForPrompt($question->get_stimulus()));
     // Learnosity does not enforce number of choices, thus using default such the min choice would be 1
     // and max would be the `max_selection` if set, otherwise use token count
     $interaction->setMinChoices(1);
     $interaction->setMaxChoices(is_int($question->get_max_selection()) ? $question->get_max_selection() : count($tokens));
     // Build validation
     $builder = new TokenhighlightValidationBuilder($indexIdentifierMap);
     list($responseDeclaration, $responseProcessing) = $builder->buildValidation($interaction->getResponseIdentifier(), $question->get_validation());
     return [$interaction, $responseDeclaration, $responseProcessing];
 }