Exemplo n.º 1
0
 public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel)
 {
     /** @var clozetext $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
     $maxLength = !is_null($question->get_max_length()) ? intval($question->get_max_length()) : 15;
     // Set default to `15` if not set
     $index = 0;
     $template = preg_replace_callback('/{{response}}/', function ($match) use(&$index, $interactionIdentifier, $interactionLabel, $maxLength) {
         $interaction = new TextEntryInteraction($interactionIdentifier . '_' . $index);
         $interaction->setLabel($interactionLabel);
         $interaction->setExpectedLength($maxLength);
         $index++;
         $replacement = QtiMarshallerUtil::marshall($interaction);
         return $replacement;
     }, $question->get_template());
     // Wrap this interaction in a block since our `clozetext` `template` meant to be blocky and not inline
     $div = new Div();
     $div->setClass('lrn-template');
     $div->setContent(ContentCollectionBuilder::buildFlowCollectionContent(QtiMarshallerUtil::unmarshallElement($template)));
     // Build validation
     $isCaseSensitive = is_null($question->get_case_sensitive()) ? true : $question->get_case_sensitive();
     $validationBuilder = new ClozetextValidationBuilder($isCaseSensitive);
     list($responseDeclaration, $responseProcessing) = $validationBuilder->buildValidation($interactionIdentifier, $question->get_validation(), $isCaseSensitive);
     return [$div, $responseDeclaration, $responseProcessing];
 }
Exemplo n.º 2
0
 public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel)
 {
     /** @var shorttext $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();
     $interaction = new TextEntryInteraction($interactionIdentifier);
     $interaction->setLabel($interactionLabel);
     // Build placeholder
     $placeholderText = $question->get_placeholder();
     if (!empty($placeholderText)) {
         $interaction->setPlaceholderText($placeholderText);
     }
     // Use 15 as default
     $interaction->setExpectedLength($question->get_max_length() ? $question->get_max_length() : 15);
     // Build those validation
     $isCaseSensitive = $question->get_case_sensitive() === null ? true : $question->get_case_sensitive();
     $validationBuilder = new ShorttextValidationBuilder($isCaseSensitive);
     list($responseDeclaration, $responseProcessing) = $validationBuilder->buildValidation($interactionIdentifier, $question->get_validation(), $isCaseSensitive);
     // TODO: This is a freaking hack
     // Wrap this interaction in a block since our `shorttext` meant to be blocky and not inline
     $div = new Div();
     $content = new FlowCollection();
     $content->attach($interaction);
     $div->setContent($content);
     return [$div, $responseDeclaration, $responseProcessing];
 }
 public function testShouldConsiderMaxLengthMoreThan250()
 {
     $interactionOne = new TextEntryInteraction('testIdentifierOne');
     $interactionOne->setExpectedLength(50);
     $interactionTwo = new TextEntryInteraction('testIdentifierTwo');
     $interactionTwo->setExpectedLength(500);
     $itemBody = $this->buildItemBodyWithTwoInteraction($interactionOne, $interactionTwo);
     $mapper = new MergedTextEntryInteractionMapper('dummyReference', $itemBody);
     $question = $mapper->getQuestionType();
     $this->assertNotNull($question);
     $this->assertTrue($question->get_max_length() >= 250);
     $this->assertTrue($question->get_multiple_line());
 }
 public function testMarshallMaximal()
 {
     $textEntryInteraction = new TextEntryInteraction('RESPONSE');
     $textEntryInteraction->setBase(2);
     $textEntryInteraction->setStringIdentifier('mystring');
     $textEntryInteraction->setExpectedLength(35);
     $textEntryInteraction->setPatternMask('[0-9]+');
     $textEntryInteraction->setPlaceholderText('input here...');
     $element = $this->getMarshallerFactory()->createMarshaller($textEntryInteraction)->marshall($textEntryInteraction);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $element = $dom->importNode($element, true);
     $this->assertEquals('<textEntryInteraction responseIdentifier="RESPONSE" base="2" stringIdentifier="mystring" expectedLength="35" patternMask="[0-9]+" placeholderText="input here..."/>', $dom->saveXML($element));
 }