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];
 }
 public static function buildFlowStaticCollectionContent(QtiComponentCollection $content)
 {
     $collection = new FlowStaticCollection();
     foreach ($content as $component) {
         $collection->attach($component);
     }
     return $collection;
 }
 private function buildHottextInteraction($responseIdentifier)
 {
     $interaction = HottextInteractionBuilder::buildSimple($responseIdentifier, ['Hello, my name ', ['A' => 'are'], ' James. I ', ['B' => 'have'], ' five brothers. and all of them ', ['C' => 'is'], ' girls.']);
     $prompt = new Prompt();
     $promptCollection = new FlowStaticCollection();
     $promptCollection->attach(new TextRun('Select the error in the following passage of text'));
     $prompt->setContent($promptCollection);
     $interaction->setPrompt($prompt);
     return $interaction;
 }
 private function buildExtendedTextInteraction($identifier)
 {
     $prompt = new Prompt();
     $collection = new FlowStaticCollection();
     $collection->attach(new TextRun('Please describe yourself in few words'));
     $prompt->setContent($collection);
     $interaction = new ExtendedTextInteraction($identifier);
     $interaction->setPrompt($prompt);
     return $interaction;
 }
 private static function buildSimpleMatchSet(array $matchSets, $matchMax)
 {
     $matchChoiceAssociation = new SimpleAssociableChoiceCollection();
     foreach ($matchSets as $identifier => $value) {
         $choice = new SimpleAssociableChoice($identifier, $matchMax);
         $contentCollection = new FlowStaticCollection();
         $contentCollection->attach(new TextRun($value));
         $choice->setContent($contentCollection);
         $matchChoiceAssociation->attach($choice);
     }
     return new SimpleMatchSet($matchChoiceAssociation);
 }
 public static function buildSimple($responseIdentifier, array $identifierLabelMap)
 {
     $collection = new SimpleChoiceCollection();
     foreach ($identifierLabelMap as $identifier => $label) {
         $choice = new SimpleChoice($identifier);
         $content = new FlowStaticCollection();
         $content->attach(new TextRun($label));
         $choice->setContent($content);
         $collection->attach($choice);
     }
     return new ChoiceInteraction($responseIdentifier, $collection);
 }
Esempio n. 7
0
 public function convert(BaseQuestionType $questionType, $interactionIdentifier, $interactionLabel)
 {
     /** @var mcq $question */
     $question = $questionType;
     // Build <choiceInteraction>
     $valueIdentifierMap = [];
     $simpleChoiceCollection = new SimpleChoiceCollection();
     foreach ($question->get_options() as $index => $option) {
         /** @var mcq_options_item $option */
         $choiceContent = new FlowStaticCollection();
         foreach (QtiMarshallerUtil::unmarshallElement($option->get_label()) as $component) {
             $choiceContent->attach($component);
         }
         // Use option['value'] as choice `identifier` if it has the correct format,
         // Otherwise, generate a valid using index such `CHOICE_1`, `CHOICE_2`, etc
         $originalOptionValue = $option->get_value();
         $choiceIdentifier = Format::isIdentifier($originalOptionValue, false) ? $originalOptionValue : 'CHOICE_' . $index;
         // Store this reference in a map
         $valueIdentifierMap[$originalOptionValue] = $choiceIdentifier;
         $choice = new SimpleChoice($choiceIdentifier);
         $choice->setContent($choiceContent);
         $simpleChoiceCollection->attach($choice);
     }
     // Build final interaction and its corresponding <responseDeclaration>, and its <responseProcessingTemplate>
     $interaction = new ChoiceInteraction($interactionIdentifier, $simpleChoiceCollection);
     $interaction->setLabel($interactionLabel);
     $interaction->setMinChoices(1);
     $interaction->setMaxChoices($question->get_multiple_responses() ? $simpleChoiceCollection->count() : 1);
     // Build the prompt
     $interaction->setPrompt($this->convertStimulusForPrompt($question->get_stimulus()));
     // Set shuffle options
     $interaction->setShuffle($question->get_shuffle_options() ? true : false);
     // Set the layout
     if ($question->get_ui_style() instanceof mcq_ui_style && $question->get_ui_style()->get_type() === 'horizontal' && intval($question->get_ui_style()->get_columns()) === count($question->get_options())) {
         $interaction->setOrientation(Orientation::HORIZONTAL);
     } else {
         $interaction->setOrientation(Orientation::VERTICAL);
         LogService::log('ui_style` is ignored and `choiceInteraction` is assumed and set as `vertical`');
     }
     if (empty($question->get_validation())) {
         return [$interaction, null, null];
     }
     $builder = new McqValidationBuilder($question->get_multiple_responses(), $valueIdentifierMap);
     list($responseDeclaration, $responseProcessing) = $builder->buildValidation($interactionIdentifier, $question->get_validation());
     return [$interaction, $responseDeclaration, $responseProcessing];
 }
 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;
 }
 public function testPrompt()
 {
     $interaction = ChoiceInteractionBuilder::buildSimple('testIdentifier', ['choiceA' => 'Choice A']);
     $prompt = new Prompt();
     $promptContent = new FlowStaticCollection();
     $promptContent->attach(new TextRun('Test'));
     $htmlCollection = new InlineCollection();
     $htmlCollection->attach(new TextRun('123'));
     $p = new P();
     $p->setContent($htmlCollection);
     $promptContent->attach($p);
     $prompt->setContent($promptContent);
     $interaction->setPrompt($prompt);
     $interactionMapper = new ChoiceInteractionMapper($interaction);
     $questionType = $interactionMapper->getQuestionType();
     $this->assertTrue($questionType->get_stimulus() === 'Test<p>123</p>');
 }