예제 #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];
 }
 private function validate(QtiOrderInteraction $interaction)
 {
     if ($interaction->mustShuffle()) {
         LogService::log('Attribute `shuffle` is not supported');
     }
     foreach ($interaction->getSimpleChoices() as $simpleChoice) {
         /** @var SimpleChoice $simpleChoice */
         if ($simpleChoice->isFixed()) {
             LogService::log('Attribute `fixed` for ' . $simpleChoice->getIdentifier() . ' is not supported');
         }
     }
     return true;
 }
예제 #3
0
 public function testCreateShufflingFromOrder()
 {
     $choiceCollection = new SimpleChoiceCollection();
     $choiceCollection[] = new SimpleChoice('id1');
     $choiceCollection[] = new SimpleChoice('id2');
     $choiceCollection[] = new SimpleChoice('id3');
     $orderInteraction = new OrderInteraction('RESPONSE', $choiceCollection);
     $orderInteraction->setShuffle(true);
     $shuffling = StateUtils::createShufflingFromInteraction($orderInteraction);
     $this->assertEquals('RESPONSE', $shuffling->getResponseIdentifier());
     $shufflingGroups = $shuffling->getShufflingGroups();
     $this->assertEquals(1, count($shufflingGroups));
     $this->assertEquals(array('id1', 'id2', 'id3'), $shufflingGroups[0]->getIdentifiers()->getArrayCopy());
 }
 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 OrderInteraction('RESPONSE', $choices);
     $prompt = new Prompt();
     $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...'))));
     $component->setPrompt($prompt);
     $component->setMinChoices(1);
     $component->setMaxChoices(2);
     $marshaller = $this->getMarshallerFactory()->createMarshaller($component);
     $element = $marshaller->marshall($component);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<orderInteraction responseIdentifier="RESPONSE" maxChoices="2" minChoices="1"><prompt>Prompt...</prompt><simpleChoice identifier="choice_1">Choice #1</simpleChoice><simpleChoice identifier="choice_2">Choice #2</simpleChoice></orderInteraction>', $dom->saveXML($element));
 }
 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;
 }