private function validateInteraction(InlineChoiceInteraction $interaction) { if (!empty($interaction->mustShuffle())) { LogService::log('The attribute `shuffle` is not supported, thus is ignored'); } if (!empty($interaction->isRequired())) { LogService::log('The attribute `required` is not supported, thus is ignored'); } return $interaction; }
public function testMarshall20() { // check that suffled systematically out and no required attribute. $inlineChoices = new InlineChoiceCollection(); $choice = new InlineChoice('inlineChoice1'); $choice->setFixed(true); $choice->setContent(new TextOrVariableCollection(array(new TextRun('Option1')))); $inlineChoices[] = $choice; $inlineChoiceInteraction = new InlineChoiceInteraction('RESPONSE', $inlineChoices); $inlineChoiceInteraction->setShuffle(false); $inlineChoiceInteraction->setRequired(true); $element = $this->getMarshallerFactory('2.0.0')->createMarshaller($inlineChoiceInteraction)->marshall($inlineChoiceInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<inlineChoiceInteraction responseIdentifier="RESPONSE" shuffle="false"><inlineChoice identifier="inlineChoice1" fixed="true">Option1</inlineChoice></inlineChoiceInteraction>', $dom->saveXML($element)); }
public function testMarshall() { $inlineChoices = new InlineChoiceCollection(); $choice = new InlineChoice('inlineChoice1'); $choice->setFixed(true); $choice->setContent(new TextOrVariableCollection(array(new TextRun('Option1')))); $inlineChoices[] = $choice; $choice = new InlineChoice('inlineChoice2'); $choice->setContent(new TextOrVariableCollection(array(new TextRun('Option2')))); $inlineChoices[] = $choice; $choice = new InlineChoice('inlineChoice3'); $choice->setContent(new TextOrVariableCollection(array(new TextRun('Option3')))); $inlineChoices[] = $choice; $inlineChoiceInteraction = new InlineChoiceInteraction('RESPONSE', $inlineChoices); $inlineChoiceInteraction->setShuffle(true); $inlineChoiceInteraction->setRequired(true); $element = $this->getMarshallerFactory()->createMarshaller($inlineChoiceInteraction)->marshall($inlineChoiceInteraction); $dom = new DOMDocument('1.0', 'UTF-8'); $element = $dom->importNode($element, true); $this->assertEquals('<inlineChoiceInteraction responseIdentifier="RESPONSE" shuffle="true" required="true"><inlineChoice identifier="inlineChoice1" fixed="true">Option1</inlineChoice><inlineChoice identifier="inlineChoice2">Option2</inlineChoice><inlineChoice identifier="inlineChoice3">Option3</inlineChoice></inlineChoiceInteraction>', $dom->saveXML($element)); }
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]; }
public function testCreateShufflingFromInlineChoiceInteraction() { $choiceCollection = new InlineChoiceCollection(); $choiceCollection[] = new InlineChoice('id1'); $choiceCollection[] = new InlineChoice('id2'); $choiceCollection[] = new InlineChoice('id3'); $inlineChoiceInteraction = new InlineChoiceInteraction('RESPONSE', $choiceCollection); $inlineChoiceInteraction->setShuffle(true); $shuffling = StateUtils::createShufflingFromInteraction($inlineChoiceInteraction); $this->assertEquals('RESPONSE', $shuffling->getResponseIdentifier()); $shufflingGroups = $shuffling->getShufflingGroups(); $this->assertEquals(1, count($shufflingGroups)); $this->assertEquals(array('id1', 'id2', 'id3'), $shufflingGroups[0]->getIdentifiers()->getArrayCopy()); }