예제 #1
0
 public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel)
 {
     /** @var orderlist $question */
     $question = $questionType;
     $simpleChoiceCollection = new SimpleChoiceCollection();
     $indexIdentifiersMap = [];
     foreach ($question->get_list() as $key => $item) {
         $simpleChoice = new SimpleChoice('CHOICE_' . $key);
         $choiceContent = new FlowStaticCollection();
         foreach (QtiMarshallerUtil::unmarshallElement($item) as $component) {
             $choiceContent->attach($component);
         }
         $simpleChoice->setContent($choiceContent);
         $simpleChoiceCollection->attach($simpleChoice);
         $indexIdentifiersMap[$key] = $simpleChoice->getIdentifier();
     }
     $interaction = new OrderInteraction($interactionIdentifier, $simpleChoiceCollection);
     $interaction->setLabel($interactionLabel);
     $interaction->setPrompt($this->convertStimulusForPrompt($question->get_stimulus()));
     $interaction->setShuffle(false);
     $interaction->setOrientation(Orientation::VERTICAL);
     $builder = new OrderlistValidationBuilder($indexIdentifiersMap);
     list($responseDeclaration, $responseProcessing) = $builder->buildValidation($interactionIdentifier, $question->get_validation());
     return [$interaction, $responseDeclaration, $responseProcessing];
 }
 public static function buildSimple($responseIdentifier, array $identifierLabelMap)
 {
     $collection = new SimpleChoiceCollection();
     foreach ($identifierLabelMap as $identifier => $label) {
         $choice = new SimpleChoice($identifier);
         $content = new FlowStaticCollection();
         $content->attach(new TextRun($label));
         $choice->setContent($content);
         $collection->attach($choice);
     }
     return new ChoiceInteraction($responseIdentifier, $collection);
 }
 public function testMarshall()
 {
     $simpleChoice = new SimpleChoice('choice_1');
     $simpleChoice->setClass('qti-simpleChoice');
     $strong = new Strong();
     $strong->setContent(new InlineCollection(array(new TextRun('strong'))));
     $simpleChoice->setContent(new FlowStaticCollection(array(new TextRun('This is ... '), $strong, new TextRun('!'))));
     $marshaller = $this->getMarshallerFactory()->createMarshaller($simpleChoice);
     $element = $marshaller->marshall($simpleChoice);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<simpleChoice class="qti-simpleChoice" identifier="choice_1">This is ... <strong>strong</strong>!</simpleChoice>', $dom->saveXML($element));
 }
 public function testMarshall()
 {
     $choice1 = new SimpleChoice('choice_1');
     $choice1->setContent(new FlowStaticCollection(array(new TextRun('Choice #1'))));
     $choice2 = new SimpleChoice('choice_2');
     $choice2->setContent(new FlowStaticCollection(array(new TextRun('Choice #2'))));
     $choices = new SimpleChoiceCollection(array($choice1, $choice2));
     $component = new ChoiceInteraction('RESPONSE', $choices);
     $prompt = new Prompt();
     $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...'))));
     $component->setPrompt($prompt);
     $marshaller = $this->getMarshallerFactory()->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<choiceInteraction responseIdentifier="RESPONSE"><prompt>Prompt...</prompt><simpleChoice identifier="choice_1">Choice #1</simpleChoice><simpleChoice identifier="choice_2">Choice #2</simpleChoice></choiceInteraction>', $dom->saveXML($element));
 }
예제 #5
0
 public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel)
 {
     /** @var mcq $question */
     $question = $questionType;
     // Build <choiceInteraction>
     $valueIdentifierMap = [];
     $simpleChoiceCollection = new SimpleChoiceCollection();
     foreach ($question->get_options() as $index => $option) {
         /** @var mcq_options_item $option */
         $choiceContent = new FlowStaticCollection();
         foreach (QtiMarshallerUtil::unmarshallElement($option->get_label()) as $component) {
             $choiceContent->attach($component);
         }
         // Use option['value'] as choice `identifier` if it has the correct format,
         // Otherwise, generate a valid using index such `CHOICE_1`, `CHOICE_2`, etc
         $originalOptionValue = $option->get_value();
         $choiceIdentifier = Format::isIdentifier($originalOptionValue, false) ? $originalOptionValue : 'CHOICE_' . $index;
         // Store this reference in a map
         $valueIdentifierMap[$originalOptionValue] = $choiceIdentifier;
         $choice = new SimpleChoice($choiceIdentifier);
         $choice->setContent($choiceContent);
         $simpleChoiceCollection->attach($choice);
     }
     // Build final interaction and its corresponding <responseDeclaration>, and its <responseProcessingTemplate>
     $interaction = new ChoiceInteraction($interactionIdentifier, $simpleChoiceCollection);
     $interaction->setLabel($interactionLabel);
     $interaction->setMinChoices(1);
     $interaction->setMaxChoices($question->get_multiple_responses() ? $simpleChoiceCollection->count() : 1);
     // Build the prompt
     $interaction->setPrompt($this->convertStimulusForPrompt($question->get_stimulus()));
     // Set shuffle options
     $interaction->setShuffle($question->get_shuffle_options() ? true : false);
     // Set the layout
     if ($question->get_ui_style() instanceof mcq_ui_style && $question->get_ui_style()->get_type() === 'horizontal' && intval($question->get_ui_style()->get_columns()) === count($question->get_options())) {
         $interaction->setOrientation(Orientation::HORIZONTAL);
     } else {
         $interaction->setOrientation(Orientation::VERTICAL);
         LogService::log('ui_style` is ignored and `choiceInteraction` is assumed and set as `vertical`');
     }
     if (empty($question->get_validation())) {
         return [$interaction, null, null];
     }
     $builder = new McqValidationBuilder($question->get_multiple_responses(), $valueIdentifierMap);
     list($responseDeclaration, $responseProcessing) = $builder->buildValidation($interactionIdentifier, $question->get_validation());
     return [$interaction, $responseDeclaration, $responseProcessing];
 }
예제 #6
0
 public function testCreateShufflingFromInteractionChoice()
 {
     $choice1 = new SimpleChoice('id1');
     $choice2 = new SimpleChoice('id2');
     $choice3 = new SimpleChoice('id3');
     $choice1->setFixed(true);
     $choice3->setFixed(true);
     $choiceCollection = new SimpleChoiceCollection(array($choice1, $choice2, $choice3));
     $choiceInteraction = new ChoiceInteraction('RESPONSE', $choiceCollection);
     $choiceInteraction->setShuffle(true);
     $shuffling = StateUtils::createShufflingFromInteraction($choiceInteraction);
     $this->assertEquals('RESPONSE', $shuffling->getResponseIdentifier());
     $shufflingGroups = $shuffling->getShufflingGroups();
     $this->assertEquals(1, count($shufflingGroups));
     $this->assertEquals(array('id1', 'id2', 'id3'), $shufflingGroups[0]->getIdentifiers()->getArrayCopy());
     $this->assertEquals(array('id1', 'id3'), $shufflingGroups[0]->getFixedIdentifiers()->getArrayCopy());
 }
예제 #7
0
 public function testShuffleWithFixed()
 {
     // It is difficult to test a random algorithm.
     // In this way, we just check it runs. Deeper
     // analysis can be done in /test/scripts/.
     // DOM creation...
     $dom = new DOMDocument('1.0', 'UTF-8');
     $node = $dom->createElement('fakenode');
     $dom->appendChild($node);
     $choice = $dom->createElement('div');
     $choice->setAttribute('fixed', 'false');
     $choice->setAttribute('id', 'choice1');
     $choice->setAttribute('class', 'qti-simpleChoice');
     $node->appendChild($choice);
     $choice = $dom->createElement('div');
     $choice->setAttribute('fixed', 'true');
     $choice->setAttribute('id', 'choice2');
     $choice->setAttribute('class', 'qti-simpleChoice qti-hide');
     $node->appendChild($choice);
     $choice = $dom->createElement('div');
     $choice->setAttribute('fixed', 'false');
     $choice->setAttribute('id', 'choice3');
     $choice->setAttribute('class', 'qti-simpleChoice');
     $node->appendChild($choice);
     // In memory model creation ...
     $shufflables = new ShufflableCollection();
     $choice = new SimpleChoice('choice1');
     $choice->setFixed(false);
     $choice->setId('choice1');
     $shufflables[] = $choice;
     $choice = new SimpleChoice('choice2');
     $choice->setFixed(true);
     $choice->setId('choice2');
     $shufflables[] = $choice;
     $choice = new SimpleChoice('choice3');
     $choice->setFixed(false);
     $choice->setId('choice3');
     $shufflables[] = $choice;
     Utils::shuffle($node, $shufflables);
     // Let's check if 'choice2' is still in place...
     $this->assertEquals('choice2', $node->getElementsByTagName('div')->item(1)->getAttribute('id'));
     $node0Id = $node->getElementsByTagName('div')->item(0)->getAttribute('id');
     $node1Id = $node->getElementsByTagName('div')->item(2)->getAttribute('id');
     $this->assertTrue($node0Id === 'choice1' && $node1Id === 'choice3' || $node0Id === 'choice3' && $node1Id === 'choice1');
 }
 public static function buildOrderInteraction($identifier, $choices, $promptText = null)
 {
     $simpleChoiceCollection = new SimpleChoiceCollection();
     foreach ($choices as $identifier => $value) {
         $simpleChoice = new SimpleChoice($identifier);
         $contentCollection = new FlowStaticCollection();
         $contentCollection->attach(new TextRun($value));
         $simpleChoice->setContent($contentCollection);
         $simpleChoiceCollection->attach($simpleChoice);
     }
     $orderInteraction = new OrderInteraction($identifier, $simpleChoiceCollection);
     if ($promptText) {
         $prompt = new Prompt();
         $contentCollection = new FlowStaticCollection();
         $contentCollection->attach(new TextRun($promptText));
         $prompt->setContent($contentCollection);
         $orderInteraction->setPrompt($prompt);
     }
     return $orderInteraction;
 }
 /**
  * @depends testMarshallSimple20
  */
 public function testMarshallNoTemplateIdentifierNoShowHide20()
 {
     // Aims at testing that templateIdentifier and showHide attributes
     // are not taken into accoun in a QTI 2.0 context.
     $simpleChoice = new SimpleChoice('choice_1');
     $simpleChoice->setFixed(true);
     $simpleChoice->setTemplateIdentifier('XTEMPLATE');
     $simpleChoice->setShowHide(ShowHide::HIDE);
     $simpleChoice->setContent(new FlowStaticCollection(array(new TextRun('Choice #1'))));
     $marshaller = $this->getMarshallerFactory('2.0.0')->createMarshaller($simpleChoice);
     $element = $marshaller->marshall($simpleChoice);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<simpleChoice identifier="choice_1" fixed="true">Choice #1</simpleChoice>', $dom->saveXML($element));
 }
 public function testMarshallOrientationNoOutput20()
 {
     // Aims at testing that orientation is not output in a QTI 2.0 context.
     $choice1 = new SimpleChoice('choice_1');
     $choice1->setContent(new FlowStaticCollection(array(new TextRun('Choice #1'))));
     $choices = new SimpleChoiceCollection(array($choice1));
     $component = new ChoiceInteraction('RESPONSE', $choices);
     // Set non-default value for orientation...
     $component->setOrientation(Orientation::HORIZONTAL);
     $marshaller = $this->getMarshallerFactory('2.0.0')->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<choiceInteraction responseIdentifier="RESPONSE" shuffle="false" maxChoices="0"><simpleChoice identifier="choice_1">Choice #1</simpleChoice></choiceInteraction>', $dom->saveXML($element));
 }