コード例 #1
0
 private function isMultipleResponse(QtiMatchInteraction $interaction)
 {
     // We determine whether the question shall be mapped to `multiple_responses` as true
     // if any the source choices (stems or options) can be mapped to be more than 1
     foreach ($interaction->getSourceChoices()->getSimpleAssociableChoices() as $choice) {
         /** @var SimpleAssociableChoice $choice */
         if ($choice->getMatchMax() !== 1) {
             return true;
         }
     }
     foreach ($interaction->getTargetChoices()->getSimpleAssociableChoices() as $choice) {
         /** @var SimpleAssociableChoice $choice */
         if ($choice->getMatchMax() !== 1) {
             return true;
         }
     }
     return false;
 }
コード例 #2
0
ファイル: StateUtilsTest.php プロジェクト: nagyist/qti-sdk
 public function testCreateShufflingFromMatchInteraction()
 {
     $choiceCollection1 = new SimpleAssociableChoiceCollection();
     $choiceCollection1[] = new SimpleAssociableChoice('id1', 1);
     $choiceCollection1[] = new SimpleAssociableChoice('id2', 1);
     $choiceCollection2 = new SimpleAssociableChoiceCollection();
     $choiceCollection2[] = new SimpleAssociableChoice('id3', 1);
     $choiceCollection2[] = new SimpleAssociableChoice('id4', 1);
     $matchSets = new SimpleMatchSetCollection();
     $matchSets[] = new SimpleMatchSet($choiceCollection1);
     $matchSets[] = new SimpleMatchSet($choiceCollection2);
     $matchInteraction = new MatchInteraction('RESPONSE', $matchSets);
     $matchInteraction->setShuffle(true);
     $shuffling = StateUtils::createShufflingFromInteraction($matchInteraction);
     $this->assertEquals('RESPONSE', $shuffling->getResponseIdentifier());
     $shufflingGroups = $shuffling->getShufflingGroups();
     $this->assertEquals(2, count($shufflingGroups));
     $this->assertEquals(array('id1', 'id2'), $shufflingGroups[0]->getIdentifiers()->getArrayCopy());
     $this->assertEquals(array('id3', 'id4'), $shufflingGroups[1]->getIdentifiers()->getArrayCopy());
 }
コード例 #3
0
 public function convert(BaseQuestionType $question, $interactionIdentifier, $interactionLabel)
 {
     /** @var choicematrix $question */
     // Is multiple response ?
     $isMultipleResponses = !empty($question->get_multiple_responses()) ? $question->get_multiple_responses() : false;
     $optionCount = count($question->get_options());
     $stemCount = count($question->get_stems());
     // Append the two sets of choices, the first set defines the source choices and the second set the targets
     $simpleMatchCollection = new SimpleMatchSetCollection();
     list($stemCollection, $stemIndexIdentifierMap) = $this->buildStemCollection($question, $isMultipleResponses, $optionCount);
     list($optionCollection, $optionIndexIdentifierMap) = $this->buildOptionCollection($question, $stemCount);
     $simpleMatchCollection->attach(new SimpleMatchSet($stemCollection));
     $simpleMatchCollection->attach(new SimpleMatchSet($optionCollection));
     // Build the interaction
     $interaction = new MatchInteraction($interactionIdentifier, $simpleMatchCollection);
     $interaction->setPrompt($this->convertStimulusForPrompt($question->get_stimulus()));
     $interaction->setLabel($interactionLabel);
     $interaction->setShuffle(false);
     // No support for shuffling
     // If multiple response set then student is allowed to put 1 association (tick 1 box) or (optionCount * stemCount) association (tick all the boxes)
     $interaction->setMaxAssociations($isMultipleResponses ? $optionCount * $stemCount : $stemCount);
     $interaction->setMinAssociations($isMultipleResponses ? 1 : $stemCount);
     $builder = new ChoicematrixValidationBuilder($stemIndexIdentifierMap, $optionIndexIdentifierMap);
     list($responseDeclaration, $responseProcessing) = $builder->buildValidation($interactionIdentifier, $question->get_validation());
     return [$interaction, $responseDeclaration, $responseProcessing];
 }
 public function testMarshall()
 {
     $choice1A = new SimpleAssociableChoice('choice1A', 1);
     $choice1A->setContent(new FlowStaticCollection(array(new TextRun('choice1A'))));
     $choice1B = new SimpleAssociableChoice('choice1B', 1);
     $choice1B->setContent(new FlowStaticCollection(array(new TextRun('choice1B'))));
     $choice2A = new SimpleAssociableChoice('choice2A', 1);
     $choice2A->setContent(new FlowStaticCollection(array(new TextRun('choice2A'))));
     $choice2B = new SimpleAssociableChoice('choice2B', 1);
     $choice2B->setContent(new FlowStaticCollection(array(new TextRun('choice2B'))));
     $set1 = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($choice1A, $choice1B)));
     $set2 = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($choice2A, $choice2B)));
     $matchInteraction = new MatchInteraction('RESPONSE', new SimpleMatchSetCollection(array($set1, $set2)));
     $prompt = new Prompt();
     $prompt->setContent(new FlowStaticCollection(array(new TextRun('Prompt...'))));
     $matchInteraction->setPrompt($prompt);
     $matchInteraction->setShuffle(true);
     $marshaller = $this->getMarshallerFactory()->createMarshaller($matchInteraction);
     $element = $marshaller->marshall($matchInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<matchInteraction responseIdentifier="RESPONSE" shuffle="true"><prompt>Prompt...</prompt><simpleMatchSet><simpleAssociableChoice identifier="choice1A" matchMax="1">choice1A</simpleAssociableChoice><simpleAssociableChoice identifier="choice1B" matchMax="1">choice1B</simpleAssociableChoice></simpleMatchSet><simpleMatchSet><simpleAssociableChoice identifier="choice2A" matchMax="1">choice2A</simpleAssociableChoice><simpleAssociableChoice identifier="choice2B" matchMax="1">choice2B</simpleAssociableChoice></simpleMatchSet></matchInteraction>', $dom->saveXML($element));
 }
コード例 #5
0
 /**
  * @depends testMarshall20
  */
 public function testMarshallNoMinAssociations()
 {
     // Aims at testing that minAssociations is never in the output
     // in a QTI 2.0 context.
     $choice1A = new SimpleAssociableChoice('choice1A', 1);
     $choice1A->setContent(new FlowStaticCollection(array(new TextRun('choice1A'))));
     $choice2A = new SimpleAssociableChoice('choice2A', 1);
     $choice2A->setContent(new FlowStaticCollection(array(new TextRun('choice2A'))));
     $set1 = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($choice1A)));
     $set2 = new SimpleMatchSet(new SimpleAssociableChoiceCollection(array($choice2A)));
     $matchInteraction = new MatchInteraction('RESPONSE', new SimpleMatchSetCollection(array($set1, $set2)));
     $matchInteraction->setMinAssociations(1);
     $marshaller = $this->getMarshallerFactory('2.0.0')->createMarshaller($matchInteraction);
     $element = $marshaller->marshall($matchInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<matchInteraction responseIdentifier="RESPONSE" shuffle="false" maxAssociations="1"><simpleMatchSet><simpleAssociableChoice identifier="choice1A" matchMax="1">choice1A</simpleAssociableChoice></simpleMatchSet><simpleMatchSet><simpleAssociableChoice identifier="choice2A" matchMax="1">choice2A</simpleAssociableChoice></simpleMatchSet></matchInteraction>', $dom->saveXML($element));
 }