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]; }
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]; }