コード例 #1
0
 public function convert(BaseQuestionType $question, $interactionIdentifier, $interactionLabel)
 {
     /** @var tokenhighlight $question */
     // Grab those `template` and convert those highlights to <hottext>
     $html = new SimpleHtmlDom();
     $html->load($question->get_template());
     $tokens = $html->find('span.lrn_token');
     $indexIdentifierMap = [];
     foreach ($tokens as $key => &$span) {
         $span->outertext = '<hottext identifier="TOKEN_' . intval($key) . '">' . $span->innertext . '</hottext>';
         $indexIdentifierMap[$key] = 'TOKEN_' . intval($key);
     }
     $htmlContent = $html->save();
     $contentComponents = QtiMarshallerUtil::unmarshallElement($htmlContent);
     $contentCollection = ContentCollectionBuilder::buildBlockStaticCollectionContent($contentComponents);
     // Build the interaction
     $interaction = new HottextInteraction($interactionIdentifier, $contentCollection);
     $interaction->setLabel($interactionLabel);
     $interaction->setPrompt($this->convertStimulusForPrompt($question->get_stimulus()));
     // Learnosity does not enforce number of choices, thus using default such the min choice would be 1
     // and max would be the `max_selection` if set, otherwise use token count
     $interaction->setMinChoices(1);
     $interaction->setMaxChoices(is_int($question->get_max_selection()) ? $question->get_max_selection() : count($tokens));
     // Build validation
     $builder = new TokenhighlightValidationBuilder($indexIdentifierMap);
     list($responseDeclaration, $responseProcessing) = $builder->buildValidation($interaction->getResponseIdentifier(), $question->get_validation());
     return [$interaction, $responseDeclaration, $responseProcessing];
 }
コード例 #2
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];
 }