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 static function buildItemBody(QtiComponentCollection $componentCollection) { $itemBody = new ItemBody('testItemBody'); $blockCollection = new BlockCollection(); $p = new P(); $pCollection = new InlineCollection(); $pCollection->attach(new TextRun('The Matrix movie is starring ')); // Build the <itemBody> $blockCollection->attach($p); foreach ($componentCollection as $c) { if ($c instanceof InlineInteraction) { $pCollection->attach($c); } else { $blockCollection->attach($c); } } $p->setContent($pCollection); $itemBody->setContent($blockCollection); return $itemBody; }
public static function buildSimple($identifier, $contentMap) { $interactionContent = new BlockStaticCollection(); $p = new P(); $pCollection = new InlineCollection(); foreach ($contentMap as $content) { if (is_array($content)) { $hottext = new Hottext(key($content)); $hottextContent = new InlineStaticCollection(); $hottextContent->attach(new TextRun($content[key($content)])); $hottext->setContent($hottextContent); $pCollection->attach($hottext); } else { if (is_string($content)) { $pCollection->attach(new TextRun($content)); } } } $p->setContent($pCollection); $interactionContent->attach($p); return new HottextInteraction($identifier, $interactionContent); }
private function buildTemplate(HottextInteraction $interaction) { $templateCollection = new QtiComponentCollection(); foreach ($interaction->getComponents() as $component) { // Ignore `prompt` since its going to be mapped to `stimulus` if (!$component instanceof Prompt) { $templateCollection->attach($component); } } $content = QtiMarshallerUtil::marshallCollection($templateCollection); foreach ($interaction->getComponentsByClassName('hottext') as $hottext) { /** @var Hottext $hottext */ $hottextString = QtiMarshallerUtil::marshall($hottext); $tokenSpan = new span(); $tokenSpan->setClass('lrn_token'); $inlineCollection = new InlineCollection(); foreach ($hottext->getComponents() as $c) { $inlineCollection->attach($c); } $tokenSpan->setContent($inlineCollection); $content = str_replace($hottextString, QtiMarshallerUtil::marshall($tokenSpan), $content); } return $content; }
protected function buildAssessmentItem(array $interactions, $responseProcessingTemplate = '') { $assessmentItem = new AssessmentItem('testItemID', 'testItemTitle', false); $responseProcessing = new ResponseProcessing(); $responseProcessing->setTemplate($responseProcessingTemplate); $assessmentItem->setResponseProcessing($responseProcessing); $itemBody = new ItemBody(); $p = new P(); $pCollection = new InlineCollection(); $pCollection->attach(new TextRun('The Matrix movie is starring ')); $pCollection->attach(new TextRun('.')); foreach ($interactions as $interaction) { $pCollection->attach($interaction); } $p->setContent($pCollection); $collection = new BlockCollection(); $collection->attach($p); $itemBody->setContent($collection); $assessmentItem->setItemBody($itemBody); return $assessmentItem; }
private function buildItemBodyWithSingleInteraction(TextEntryInteraction $interactionOne = null) { $interactionOne = empty($interactionOne) ? new TextEntryInteraction('testIdentifierOne') : $interactionOne; $itemBody = new ItemBody(); $itemBodyCollection = new BlockCollection(); // Build `<p>The Matrix .... <inlineChoiceInteraction...></inlineChoiceInteraction>.</p>` $p = new P(); $pCollection = new InlineCollection(); $pCollection->attach(new TextRun('The Matrix movie is starring ')); $pCollection->attach($interactionOne); $pCollection->attach(new TextRun('.')); $p->setContent($pCollection); // Build the <itemBody> $itemBodyCollection->attach($p); $itemBody->setContent($itemBodyCollection); return $itemBody; }
private function buildItemBodyWithTwoInteractions() { $interactionOne = InlineChoiceInteractionBuilder::buildSimple('testIdentifierOne', ['sydney' => 'Sydney', 'melbourne' => 'Melbourne', 'canberra' => 'Canberra']); $interactionTwo = InlineChoiceInteractionBuilder::buildSimple('testIdentifierTwo', ['hugh' => 'Hugh Jackman', 'keanu' => 'Keanu Reeves', 'gloria' => 'Gloria Foster']); $itemBody = new ItemBody(); $itemBodyCollection = new BlockCollection(); // Build `<p>The Matrix .... <inlineChoiceInteraction...></inlineChoiceInteraction>.</p>` $p = new P(); $pCollection = new InlineCollection(); $pCollection->attach(new TextRun('The Matrix movie is filmed at ')); $pCollection->attach($interactionOne); $pCollection->attach(new TextRun(', and starring ')); $pCollection->attach($interactionTwo); $p->setContent($pCollection); // Build the <itemBody> $itemBodyCollection->attach($p); $itemBody->setContent($itemBodyCollection); return $itemBody; }
public function testPrompt() { $interaction = ChoiceInteractionBuilder::buildSimple('testIdentifier', ['choiceA' => 'Choice A']); $prompt = new Prompt(); $promptContent = new FlowStaticCollection(); $promptContent->attach(new TextRun('Test')); $htmlCollection = new InlineCollection(); $htmlCollection->attach(new TextRun('123')); $p = new P(); $p->setContent($htmlCollection); $promptContent->attach($p); $prompt->setContent($promptContent); $interaction->setPrompt($prompt); $interactionMapper = new ChoiceInteractionMapper($interaction); $questionType = $interactionMapper->getQuestionType(); $this->assertTrue($questionType->get_stimulus() === 'Test<p>123</p>'); }