/**
  * Remove unused response declaration from the items and rp template misuse
  *
  * @param oat\taoQtiItem\modal\Item $item
  * @param string $itemFile
  * @return boolean
  */
 protected function updateItem(Item $item, $itemFile)
 {
     $changed = false;
     $requireFix = false;
     $interactions = $item->getInteractions();
     foreach ($interactions as $interaction) {
         if ($interaction instanceof PortableCustomInteraction && $interaction->getTypeIdentifier() === 'textReaderInteraction') {
             $response = $interaction->getResponse();
             $currentDefaultVal = $response->getDefaultValue();
             if (!is_array($currentDefaultVal) || empty($currentDefaultVal) || count($currentDefaultVal) !== 1) {
                 $requireFix = true;
             } else {
                 $val = $currentDefaultVal[0];
                 $requireFix = !($val instanceof Value && $val->getValue() === 'true');
             }
             if ($requireFix) {
                 $defaultValue = new Value();
                 $defaultValue->setValue('true');
                 $response->setDefaultValue([$defaultValue]);
                 $changed = true;
             }
         }
     }
     return $changed;
 }
 /**
  * Short description of method buildResponseDeclaration
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  DOMElement $data
  * @return \oat\taoQtiItem\model\qti\ResponseDeclaration
  * @see http://www.imsglobal.org/question/qti_v2p0/imsqti_infov2p0.html#element10074
  */
 protected function buildResponseDeclaration(DOMElement $data)
 {
     $myResponse = new ResponseDeclaration($this->extractAttributes($data), $this->item);
     $data = simplexml_import_dom($data);
     //set the correct responses
     $correctResponseNodes = $data->xpath("*[name(.) = 'correctResponse']");
     $responses = array();
     foreach ($correctResponseNodes as $correctResponseNode) {
         foreach ($correctResponseNode->value as $value) {
             $correct = (string) $value;
             $response = new Value();
             foreach ($value->attributes() as $attrName => $attrValue) {
                 $response->setAttribute($attrName, strval($attrValue));
             }
             $response->setValue(htmlentities($correct));
             $responses[] = $response;
         }
         break;
     }
     $myResponse->setCorrectResponses($responses);
     //set the correct responses
     $defaultValueNodes = $data->xpath("*[name(.) = 'defaultValue']");
     $defaultValues = array();
     foreach ($defaultValueNodes as $defaultValueNode) {
         foreach ($defaultValueNode->value as $value) {
             $default = (string) $value;
             $defaultValue = new Value();
             foreach ($value->attributes() as $attrName => $attrValue) {
                 $defaultValue->setAttribute($attrName, strval($attrValue));
             }
             $defaultValue->setValue(htmlentities($default));
             $defaultValues[] = $defaultValue;
         }
         break;
     }
     $myResponse->setDefaultValue($defaultValues);
     //set the mapping if defined
     $mappingNodes = $data->xpath("*[name(.) = 'mapping']");
     foreach ($mappingNodes as $mappingNode) {
         if (isset($mappingNode['defaultValue'])) {
             $myResponse->setMappingDefaultValue(floatval((string) $mappingNode['defaultValue']));
         }
         $mappingOptions = array();
         foreach ($mappingNode->attributes() as $key => $value) {
             if ($key != 'defaultValue') {
                 $mappingOptions[$key] = (string) $value;
             }
         }
         $myResponse->setAttribute('mapping', $mappingOptions);
         $mapping = array();
         foreach ($mappingNode->mapEntry as $mapEntry) {
             $mapping[(string) $mapEntry['mapKey']] = (string) $mapEntry['mappedValue'];
         }
         $myResponse->setMapping($mapping);
         break;
     }
     //set the areaMapping if defined
     $mappingNodes = $data->xpath("*[name(.) = 'areaMapping']");
     foreach ($mappingNodes as $mappingNode) {
         if (isset($mappingNode['defaultValue'])) {
             $myResponse->setMappingDefaultValue(floatval((string) $mappingNode['defaultValue']));
         }
         $mappingOptions = array();
         foreach ($mappingNode->attributes() as $key => $value) {
             if ($key != 'defaultValue') {
                 $mappingOptions[$key] = (string) $value;
             }
         }
         $myResponse->setAttribute('areaMapping', $mappingOptions);
         $mapping = array();
         foreach ($mappingNode->areaMapEntry as $mapEntry) {
             $mappingAttributes = array();
             foreach ($mapEntry->attributes() as $key => $value) {
                 $mappingAttributes[(string) $key] = (string) $value;
             }
             $mapping[] = $mappingAttributes;
         }
         $myResponse->setMapping($mapping, 'area');
         break;
     }
     return $myResponse;
 }