public function processAssessmentItem(AssessmentItem $assessmentItem)
 {
     // Randomize <assessmentItem>'s identifier, since it can later will be mapped to item reference
     // and also would be prepended as question reference
     if ($this->mode === self::RANDOMIZE_ITEM_REFERENCE) {
         $assessmentItem->setIdentifier(UuidUtil::generate());
         return $assessmentItem;
     } else {
         return $assessmentItem;
     }
 }
Example #2
0
 public function testModalFeedbackRules()
 {
     $assessmentItem = new AssessmentItem('Q01', 'Question 1', false);
     $modalFeedback1 = new ModalFeedback('LOOKUP', 'SHOWME');
     $modalFeedback2 = new ModalFeedback('LOOKUP2', 'HIDEME');
     $modalFeedback2->setShowHide(ShowHide::HIDE);
     $assessmentItem->setModalFeedbacks(new ModalFeedbackCollection(array($modalFeedback1, $modalFeedback2)));
     $modalFeedbackRules = $assessmentItem->getModalFeedbackRules();
     $this->assertEquals(2, count($modalFeedbackRules));
     $this->assertEquals('LOOKUP', $modalFeedbackRules[0]->getOutcomeIdentifier());
     $this->assertEquals('SHOWME', $modalFeedbackRules[0]->getIdentifier());
     $this->assertEquals(ShowHide::SHOW, $modalFeedbackRules[0]->getShowHide());
     $this->assertEquals('LOOKUP2', $modalFeedbackRules[1]->getOutcomeIdentifier());
     $this->assertEquals('HIDEME', $modalFeedbackRules[1]->getIdentifier());
     $this->assertEquals(ShowHide::HIDE, $modalFeedbackRules[1]->getShowHide());
 }
 public function processAssessmentItem(AssessmentItem $assessmentItem)
 {
     // TODO: Yea, we ignore rubric but what happen if the rubric is deep inside nested
     $newCollection = new BlockCollection();
     $itemBodyNew = new ItemBody();
     /** @var QtiComponent $component */
     foreach ($assessmentItem->getItemBody()->getContent() as $key => $component) {
         if (!$component instanceof RubricBlock) {
             $newCollection->attach($component);
         } else {
             LogService::log('Does not support <rubricBlock>. Ignoring <rubricBlock>');
         }
     }
     $itemBodyNew->setContent($newCollection);
     $assessmentItem->setItemBody($itemBodyNew);
     return $assessmentItem;
 }
 public function processAssessmentItem(AssessmentItem $assessmentItem)
 {
     foreach ($assessmentItem->getIterator() as $component) {
         if ($component instanceof Object) {
             /** @var Object $component */
             if ($this->isInternalUrl($component->getData())) {
                 $component->setData($this->baseAssetUrl . $component->getData());
             }
         } elseif ($component instanceof Img) {
             /** @var Img $component */
             if ($this->isInternalUrl($component->getSrc())) {
                 $component->setSrc($this->baseAssetUrl . basename($component->getSrc()));
             }
         }
     }
     return $assessmentItem;
 }
 public function processAssessmentItem(AssessmentItem $assessmentItem)
 {
     $itemBody = $assessmentItem->getItemBody();
     foreach ($itemBody->getIterator() as $component) {
         if ($component instanceof Math) {
             $element = $component->getXml()->documentElement;
             // Remove prefix if exists for conversion
             // ie. <m:math> to just <math>
             $element->removeAttributeNS($element->namespaceURI, $element->prefix);
             $component->setXmlString($element->ownerDocument->saveXML());
             // Remove MathML namespace declaration
             $component->setTargetNamespace('');
             $this->hasMathML = true;
         }
     }
     $assessmentItem->setItemBody($itemBody);
     return $assessmentItem;
 }
Example #6
0
 private function validateAssessmentItem(AssessmentItem $assessmentItem)
 {
     if ($assessmentItem->getOutcomeDeclarations()->count()) {
         LogService::log('Ignoring <outcomeDeclaration> on <assessmentItem>. Generally we mapped <defaultValue> to 0');
     }
     if ($assessmentItem->getTemplateDeclarations()->count()) {
         throw new MappingException('Does not support <templateDeclaration> on <assessmentItem>. Ignoring <templateDeclaration>');
     }
     if (!empty($assessmentItem->getTemplateProcessing())) {
         throw new MappingException('Does not support <templateProcessing> on <assessmentItem>. Ignoring <templateProcessing>');
     }
     if ($assessmentItem->getModalFeedbacks()->count()) {
         LogService::log('Ignoring <modalFeedback> on <assessmentItem>');
     }
     if ($assessmentItem->getStylesheets()->count()) {
         LogService::log('Ignoring <stylesheet> on <assessmentItem>');
     }
     return $assessmentItem;
 }
 public function build($itemIdentifier, $itemLabel, array $questions, $content = '')
 {
     // Initialise our <assessmentItem>
     $assessmentItem = new AssessmentItem($itemIdentifier, $itemIdentifier, false);
     $assessmentItem->setLabel($itemLabel);
     $assessmentItem->setOutcomeDeclarations($this->buildOutcomeDeclarations());
     $assessmentItem->setToolName('Learnosity');
     // Store interactions on this array to later be placed on <itemBody>
     $interactions = [];
     $responseDeclarationCollection = new ResponseDeclarationCollection();
     $responseProcessingTemplates = [];
     foreach ($questions as $question) {
         /** @var Question $question */
         // Map the `questions` and its validation objects to be placed at <itemBody>
         // The extraContent usually comes from `stimulus` of item that mapped to inline interaction and has no `prompt`
         list($interaction, $responseDeclaration, $responseProcessing, $extraContent) = $this->map($question);
         if (!empty($responseDeclaration)) {
             // TODO: Need to tidy this up
             // Well sometimes we can have multiple response declarations, ie. clozetext
             if ($responseDeclaration instanceof ResponseDeclarationCollection) {
                 $responseDeclarationCollection->merge($responseDeclaration);
             } else {
                 $responseDeclarationCollection->attach($responseDeclaration);
             }
         }
         if (!empty($responseProcessing)) {
             /** @var ResponseProcessing $responseProcessing */
             $responseProcessingTemplates[] = $responseProcessing->getTemplate();
         }
         $interactions[$question->get_reference()]['interaction'] = $interaction;
         if (!empty($extraContent)) {
             $interactions[$question->get_reference()]['extraContent'] = $extraContent;
         }
     }
     // Build <itemBody>
     $assessmentItem->setItemBody($this->itemBodyBuilder->buildItemBody($interactions, $content));
     // Map <responseDeclaration>
     if (!empty($responseDeclarationCollection)) {
         $assessmentItem->setResponseDeclarations($responseDeclarationCollection);
     }
     // Map <responseProcessing> - combine response processing from questions
     // TODO: Tidy up this stuff
     if (!empty($responseProcessingTemplates)) {
         $templates = array_unique($responseProcessingTemplates);
         $isOnlyMatchCorrect = count($templates) === 1 && $templates[0] === Constants::RESPONSE_PROCESSING_TEMPLATE_MATCH_CORRECT;
         $responseProcessing = new ResponseProcessing();
         $responseProcessing->setTemplate($isOnlyMatchCorrect ? Constants::RESPONSE_PROCESSING_TEMPLATE_MATCH_CORRECT : Constants::RESPONSE_PROCESSING_TEMPLATE_MAP_RESPONSE);
         $assessmentItem->setResponseProcessing($responseProcessing);
     }
     return $assessmentItem;
 }
 public function testMarshallMaximal()
 {
     $identifier = 'Q01';
     $title = 'Test Item';
     $timeDependent = true;
     $adaptive = true;
     $lang = 'en-YO';
     // Yoda English ;)
     $responseDeclarations = new ResponseDeclarationCollection();
     $responseDeclarations[] = new ResponseDeclaration('resp1', BaseType::INTEGER, Cardinality::SINGLE);
     $responseDeclarations[] = new ResponseDeclaration('resp2', BaseType::FLOAT, Cardinality::SINGLE);
     $outcomeDeclarations = new OutcomeDeclarationCollection();
     $outcomeDeclarations[] = new OutcomeDeclaration('out1', BaseType::BOOLEAN, Cardinality::MULTIPLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('out2', BaseType::IDENTIFIER, Cardinality::SINGLE);
     $item = new AssessmentItem($identifier, $title, $timeDependent, $lang);
     $item->setAdaptive($adaptive);
     $item->setResponseDeclarations($responseDeclarations);
     $item->setOutcomeDeclarations($outcomeDeclarations);
     $marshaller = $this->getMarshallerFactory()->createMarshaller($item);
     $element = $marshaller->marshall($item);
     $this->assertInstanceOf('\\DOMElement', $element);
     $this->assertEquals('assessmentItem', $element->nodeName);
     // adaptive, timeDependent, identifier, lang, title
     $this->assertEquals($element->attributes->length, 5);
     $this->assertEquals($identifier, $element->getAttribute('identifier'));
     $this->assertEquals($title, $element->getAttribute('title'));
     $this->assertEquals('true', $element->getAttribute('timeDependent'));
     $this->assertEquals('true', $element->getAttribute('adaptive'));
     $this->assertEquals($lang, $element->getAttribute('lang'));
     $responseDeclarationElts = $element->getElementsByTagName('responseDeclaration');
     $this->assertEquals(2, $responseDeclarationElts->length);
     $this->assertEquals('resp1', $responseDeclarationElts->item(0)->getAttribute('identifier'));
     $this->assertEquals('resp2', $responseDeclarationElts->item(1)->getAttribute('identifier'));
     $outcomeDeclarationElts = $element->getElementsByTagName('outcomeDeclaration');
     $this->assertEquals(2, $outcomeDeclarationElts->length);
     $this->assertEquals('out1', $outcomeDeclarationElts->item(0)->getAttribute('identifier'));
     $this->assertEquals('out2', $outcomeDeclarationElts->item(1)->getAttribute('identifier'));
 }
 /**
  * @dataProvider fillVariableProvider
  * 
  * @param IAssessmentItem $itemRef The reference item.
  * @param string $variableIdentifier The identifier of the variable.
  * @param array $data Client-side data.
  * @param Variable $expectedVariable
  */
 public function testFillVariable(array $data, Variable $expectedVariable)
 {
     // Non-time dependent basic item in 'Yoda English'.
     $itemRef = new AssessmentItem('Q01', 'Question 01', false, 'en-YO');
     $outcomeDeclarations = new OutcomeDeclarationCollection();
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME1', BaseType::FLOAT, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME2', BaseType::INTEGER, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME3', BaseType::BOOLEAN, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME4', BaseType::STRING, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME5', BaseType::POINT, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME6', BaseType::PAIR, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME7', BaseType::DIRECTED_PAIR, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME8', BaseType::DURATION, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME9', BaseType::URI, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME10', BaseType::IDENTIFIER, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME11', BaseType::INT_OR_IDENTIFIER, Cardinality::SINGLE);
     $outcomeDeclarations[] = new OutcomeDeclaration('OUTCOME12', BaseType::INTEGER, Cardinality::SINGLE);
     $responseDeclarations = new ResponseDeclarationCollection();
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE1', BaseType::IDENTIFIER, Cardinality::SINGLE);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE2', BaseType::IDENTIFIER, Cardinality::MULTIPLE);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE3', BaseType::DIRECTED_PAIR, Cardinality::ORDERED);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE4', -1, Cardinality::RECORD);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE5', -1, Cardinality::RECORD);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE6', -1, Cardinality::RECORD);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE7', -1, Cardinality::RECORD);
     $responseDeclarations[] = new ResponseDeclaration('RESPONSE8', BaseType::BOOLEAN, Cardinality::MULTIPLE);
     $itemRef->setOutcomeDeclarations($outcomeDeclarations);
     $itemRef->setResponseDeclarations($responseDeclarations);
     $filler = new taoQtiCommon_helpers_PciVariableFiller($itemRef);
     $variable = $filler->fill($expectedVariable->getIdentifier(), $data);
     $this->assertEquals($expectedVariable->getIdentifier(), $variable->getIdentifier());
     $this->assertEquals($expectedVariable->getBaseType(), $variable->getBaseType());
     $this->assertEquals($expectedVariable->getCardinality(), $variable->getCardinality());
     $this->assertEquals(get_class($expectedVariable), get_class($variable));
     if ($expectedVariable->getValue() === null) {
         $this->assertSame($expectedVariable->getValue(), $variable->getValue());
     } else {
         $this->assertTrue($expectedVariable->getValue()->equals($variable->getValue()));
     }
 }
 protected function buildAssessmentItem(array $interactions, $responseProcessingTemplate = '')
 {
     $assessmentItem = new AssessmentItem('testItemID', 'testItemTitle', false);
     $responseProcessing = new ResponseProcessing();
     $responseProcessing->setTemplate($responseProcessingTemplate);
     $assessmentItem->setResponseProcessing($responseProcessing);
     $itemBody = new ItemBody();
     $p = new P();
     $pCollection = new InlineCollection();
     $pCollection->attach(new TextRun('The Matrix movie is starring '));
     $pCollection->attach(new TextRun('.'));
     foreach ($interactions as $interaction) {
         $pCollection->attach($interaction);
     }
     $p->setContent($pCollection);
     $collection = new BlockCollection();
     $collection->attach($p);
     $itemBody->setContent($collection);
     $assessmentItem->setItemBody($itemBody);
     return $assessmentItem;
 }