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)
 {
     $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;
 }
 private function buildValueCollection(array $learnosityValues)
 {
     // The validation in `choicematrix` relies on its key to describe the index of stem/option pair
     $valueCollection = new ValueCollection();
     foreach ($this->buildQtiDirectedPairs($learnosityValues) as $pair) {
         $valueCollection->attach(new Value($pair));
     }
     return $valueCollection;
 }
 public static function buildWithCorrectResponse($identifier, array $values)
 {
     $responseDeclaration = new ResponseDeclaration($identifier);
     $valueCollection = new ValueCollection();
     foreach ($values as $value) {
         $valueCollection->attach(new Value($value));
     }
     $responseDeclaration->setCorrectResponse(new CorrectResponse($valueCollection));
     return $responseDeclaration;
 }
 private function buildValueCollection($validation)
 {
     // Handle `valid_response`
     $values = $this->buildValues($validation->get_valid_response()->get_value());
     // Handle `alt_responses`
     if (count($validation->get_alt_responses()) >= 1) {
         foreach ($validation->get_alt_responses() as $alt) {
             $values = array_merge($values, $this->buildValues($alt->get_value()));
         }
     }
     $valueCollection = new ValueCollection();
     foreach ($values as $value) {
         /** @var Value $value */
         $valueCollection->attach($value);
     }
     return $valueCollection;
 }
 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;
 }
 private function buildOutcomeDeclarations()
 {
     // Set <outcomeDeclaration> with assumption default value is always 0
     $outcomeDeclaration = new OutcomeDeclaration('SCORE', BaseType::INTEGER);
     $valueCollection = new ValueCollection();
     $valueCollection->attach(new Value(0));
     $outcomeDeclaration->setDefaultValue(new DefaultValue($valueCollection));
     $outcomeDeclarationCollection = new OutcomeDeclarationCollection();
     $outcomeDeclarationCollection->attach($outcomeDeclaration);
     return $outcomeDeclarationCollection;
 }