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;
 }
 /**
  * @param string $identifier
  * @param array $mapping Mapping of `mapKey` to [`mappedValue`, `caseSensitive`]
  * ie. {
  *      "York" => [1, false]
  *      "york" => [1, false]
  *      "Manhattan" => [1, true]
  * }
  *
  * @return \qtism\data\state\ResponseDeclaration
  */
 public static function buildWithMapping($identifier, array $mapping, $mapEntryKeyType = null)
 {
     $responseDeclaration = new ResponseDeclaration($identifier);
     $mapEntryCollection = new MapEntryCollection();
     foreach ($mapping as $mapKey => $values) {
         $mappedValue = $values[0];
         $caseSensitive = isset($values[1]) ? $values[1] : false;
         if ($mapEntryKeyType) {
             $keyParts = explode(' ', $mapKey);
             $mapKey = new QtiDirectedPair($keyParts[0], $keyParts[1]);
         }
         $mapEntryCollection->attach(new MapEntry($mapKey, floatval($mappedValue), $caseSensitive));
     }
     $responseDeclaration->setMapping(new Mapping($mapEntryCollection));
     return $responseDeclaration;
 }
 private function buildMapEntryCollection($validation)
 {
     // Handle `valid_response`
     $mapEntries = $this->buildMapEntries($validation->get_valid_response());
     // Handle `alt_responses`
     if (count($validation->get_alt_responses()) > 0) {
         foreach ($validation->get_alt_responses() as $alt) {
             $mapEntries = array_merge($mapEntries, $this->buildMapEntries($alt));
         }
     }
     $mapEntryCollection = new MapEntryCollection();
     foreach ($mapEntries as $mapEntry) {
         $mapEntryCollection->attach($mapEntry);
     }
     return $mapEntryCollection;
 }