protected function buildResponseDeclaration($responseIdentifier, $validation)
 {
     $responseDeclaration = new ResponseDeclaration($responseIdentifier);
     $responseDeclaration->setCardinality(Cardinality::MULTIPLE);
     $responseDeclaration->setBaseType(BaseType::DIRECTED_PAIR);
     /** @var clozeassociation_validation $validation */
     $validationValues = $validation->get_valid_response()->get_value();
     $validationScore = $validation->get_valid_response()->get_score();
     // Build correct response
     // Try to handle `null` values in `valid_response` `value`s
     $values = new ValueCollection();
     foreach ($validationValues as $index => $validResponse) {
         if (!isset($this->possibleResponsesMap[$validResponse])) {
             throw new MappingException('Invalid or missing missing valid response `' . $validResponse . '``');
         }
         if (!empty($validResponse)) {
             $first = ClozeassociationMapper::GAP_IDENTIFIER_PREFIX . $index;
             $second = ClozeassociationMapper::GAPCHOICE_IDENTIFIER_PREFIX . $this->possibleResponsesMap[$validResponse];
             $values->attach(new Value(new QtiDirectedPair($first, $second)));
         }
     }
     if ($values->count() > 0) {
         $correctResponse = new CorrectResponse($values);
         $responseDeclaration->setCorrectResponse($correctResponse);
     }
     return $responseDeclaration;
 }
 /**
  * Unmarshall a DOMElement object corresponding to a QTI responseDeclaration element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent A ResponseDeclaration object.
  * @throws UnmarshallingException 
  */
 protected function unmarshall(DOMElement $element)
 {
     try {
         $baseComponent = parent::unmarshall($element);
         $object = new ResponseDeclaration($baseComponent->getIdentifier());
         $object->setBaseType($baseComponent->getBaseType());
         $object->setCardinality($baseComponent->getCardinality());
         $object->setDefaultValue($baseComponent->getDefaultValue());
         $correctResponseElts = self::getChildElementsByTagName($element, 'correctResponse');
         if (count($correctResponseElts) === 1) {
             $correctResponseElt = $correctResponseElts[0];
             $marshaller = $this->getMarshallerFactory()->createMarshaller($correctResponseElt, array($baseComponent->getBaseType()));
             $object->setCorrectResponse($marshaller->unmarshall($correctResponseElt));
         }
         $mappingElts = self::getChildElementsByTagName($element, 'mapping');
         if (count($mappingElts) === 1) {
             $mappingElt = $mappingElts[0];
             $marshaller = $this->getMarshallerFactory()->createMarshaller($mappingElt, array($baseComponent->getBaseType()));
             $object->setMapping($marshaller->unmarshall($mappingElt));
         }
         $areaMappingElts = self::getChildElementsByTagName($element, 'areaMapping');
         if (count($areaMappingElts) === 1) {
             $areaMappingElt = $areaMappingElts[0];
             $marshaller = $this->getMarshallerFactory()->createMarshaller($areaMappingElt);
             $object->setAreaMapping($marshaller->unmarshall($areaMappingElt));
         }
         return $object;
     } catch (InvalidArgumentException $e) {
         $msg = "An unexpected error occured while unmarshalling the responseDeclaration.";
         throw new UnmarshallingException($msg, $element, $e);
     }
 }
 protected function buildResponseDeclaration($responseIdentifier, $validation)
 {
     /** @var clozetext_validation $validation */
     // Since we split {{response}} to multiple interactions, so we would have multiple <responseDeclaration> as needed as well
     $responseDeclarationCollection = new ResponseDeclarationCollection();
     // Process `valid_response`
     foreach ($validation->get_valid_response()->get_value() as $index => $value) {
         // We make assumption about interaction identifier shall always be the appended with index, ie. `_0`
         $responseDeclaration = new ResponseDeclaration($responseIdentifier . '_' . $index);
         $responseDeclaration->setCardinality(Cardinality::SINGLE);
         $responseDeclaration->setBaseType(BaseType::STRING);
         $valueCollection = new ValueCollection();
         $valueCollection->attach(new Value($value));
         $validResponseScore = floatval($validation->get_valid_response()->get_score());
         $mapEntriesCollection = new MapEntryCollection();
         $mapEntriesCollection->attach(new MapEntry($value, $validResponseScore, $this->isCaseSensitive));
         if (count($validation->get_alt_responses()) > 0) {
             /** @var clozetext_validation_alt_responses_item $alt */
             foreach ($validation->get_alt_responses() as $alt) {
                 // Assuming
                 if (!is_null($alt->get_value()) && isset($alt->get_value()[$index])) {
                     $alternativeValue = $alt->get_value()[$index];
                     $alternativeScore = floatval($alt->get_score());
                     $valueCollection->attach(new Value($alternativeValue));
                     $mapEntriesCollection->attach(new MapEntry($alternativeValue, $alternativeScore, $this->isCaseSensitive));
                 }
             }
         }
         $responseDeclaration->setCorrectResponse(new CorrectResponse($valueCollection));
         $responseDeclaration->setMapping(new Mapping($mapEntriesCollection));
         $responseDeclarationCollection->attach($responseDeclaration);
     }
     return $responseDeclarationCollection;
 }
 protected function buildResponseDeclaration($responseIdentifier, $validation)
 {
     /** @var mcq_validation $validation */
     $responseDeclaration = new ResponseDeclaration($responseIdentifier);
     $responseDeclaration->setCardinality($this->isMultipleResponse ? Cardinality::MULTIPLE : Cardinality::SINGLE);
     $responseDeclaration->setBaseType(BaseType::IDENTIFIER);
     $correctResponseBuilder = new QtiCorrectResponseBuilder();
     $responseDeclaration->setCorrectResponse($correctResponseBuilder->buildWithBaseTypeIdentifier($validation, $this->valueIdentifierMap));
     return $responseDeclaration;
 }
 protected function buildResponseDeclaration($responseIdentifier, $validation)
 {
     /** @var orderlist_validation $validation */
     $responseDeclaration = new ResponseDeclaration($responseIdentifier);
     $responseDeclaration->setCardinality(Cardinality::ORDERED);
     $responseDeclaration->setBaseType(BaseType::IDENTIFIER);
     $correctResponseBuilder = new QtiCorrectResponseBuilder();
     $responseDeclaration->setCorrectResponse($correctResponseBuilder->buildWithBaseTypeIdentifier($validation, $this->indexIdentifiersMap));
     return $responseDeclaration;
 }
 protected function buildResponseDeclaration($responseIdentifier, $validation)
 {
     $responseDeclaration = new ResponseDeclaration($responseIdentifier);
     $responseDeclaration->setCardinality(Cardinality::MULTIPLE);
     $responseDeclaration->setBaseType(BaseType::DIRECTED_PAIR);
     $score = floatval($validation->get_valid_response()->get_score());
     $value = $validation->get_valid_response()->get_value();
     // The validation in `choicematrix` has to be an array
     if (!is_array($value)) {
         throw new MappingException('Broken validation object. Response declaration mapping failed');
     }
     $responseDeclaration->setCorrectResponse(new CorrectResponse($this->buildValueCollection($value)));
     return $responseDeclaration;
 }
 protected function buildResponseDeclaration($responseIdentifier, $validation)
 {
     $responseDeclaration = new ResponseDeclaration($responseIdentifier);
     $responseDeclaration->setCardinality(Cardinality::SINGLE);
     $responseDeclaration->setBaseType(BaseType::STRING);
     $correctResponseBuilder = new QtiCorrectResponseBuilder();
     $responseDeclaration->setCorrectResponse($correctResponseBuilder->build($validation));
     $mappingResponseBuilder = new QtiMappingBuilder();
     $mapping = $mappingResponseBuilder->build($validation);
     $responseDeclaration->setMapping($mapping);
     foreach ($mapping->getMapEntries() as $mapEntry) {
         /** @var MapEntry $mapEntry */
         $mapEntry->setCaseSensitive($this->isCaseSensitive);
     }
     return $responseDeclaration;
 }
 protected function buildResponseDeclaration($responseIdentifier, $validation)
 {
     /** @var clozedropdown_validation $validation */
     // Since we split {{response}} to multiple interactions, so we would have multiple <responseDeclaration> as needed as well
     $responseDeclarationCollection = new ResponseDeclarationCollection();
     foreach ($validation->get_valid_response()->get_value() as $index => $value) {
         $valueIdentifierMap = $this->valueIdentifierMapPerInlineChoices[$index];
         $valueCollection = new ValueCollection();
         $valueCollection->attach(new Value($valueIdentifierMap[$value]));
         // We make assumption about interaction identifier shall always be the appended with index, ie. `_0`
         $responseDeclaration = new ResponseDeclaration($responseIdentifier . '_' . $index);
         $responseDeclaration->setBaseType(BaseType::IDENTIFIER);
         $responseDeclaration->setCardinality(Cardinality::SINGLE);
         $responseDeclaration->setCorrectResponse(new CorrectResponse($valueCollection));
         $responseDeclarationCollection->attach($responseDeclaration);
     }
     return $responseDeclarationCollection;
 }