/**
  * Short description of method buildTemplateResponseProcessing
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  DOMElement data
  * @return oat\taoQtiItem\model\qti\response\ResponseProcessing
  */
 protected function buildTemplateResponseProcessing(DOMElement $data)
 {
     $returnValue = null;
     if ($data->hasAttribute('template') && $data->childNodes->length === 0) {
         $templateUri = (string) $data->getAttribute('template');
         $returnValue = new Template($templateUri);
     } elseif ($data->childNodes->length === 1) {
         //check response declaration identifier, which must be RESPONSE in standard rp
         $responses = $this->item->getResponses();
         if (count($responses) == 1) {
             $response = reset($responses);
             if ($response->getIdentifier() !== 'RESPONSE') {
                 throw new UnexpectedResponseProcessing('the response declaration identifier must be RESPONSE');
             }
         } else {
             //invalid number of response declaration
             throw new UnexpectedResponseProcessing('the item must have exactly one response declaration');
         }
         $patternCorrectIMS = 'responseCondition [count(./*) = 2 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] [name(./*[2]) = "responseElse" ] [count(./responseElse/*) = 1 ] [name(./responseElse/*[1]) = "setOutcomeValue" ] [name(./responseElse/setOutcomeValue/*[1]) = "baseValue"]';
         $patternMappingIMS = 'responseCondition [count(./*) = 2] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "isNull"] [name(./responseIf/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "variable"] [name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "mapResponse"]';
         $patternMappingPointIMS = 'responseCondition [count(./*) = 2] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "isNull"] [name(./responseIf/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "variable"] [name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "mapResponsePoint"]';
         if (count($this->queryXPath($patternCorrectIMS)) == 1) {
             $returnValue = new Template(Template::MATCH_CORRECT);
         } elseif (count($this->queryXPath($patternMappingIMS)) == 1) {
             $returnValue = new Template(Template::MAP_RESPONSE);
         } elseif (count($this->queryXPath($patternMappingPointIMS)) == 1) {
             $returnValue = new Template(Template::MAP_RESPONSE_POINT);
         } else {
             throw new UnexpectedResponseProcessing('not Template, wrong rule');
         }
         $returnValue->setRelatedItem($this->item);
     } else {
         throw new UnexpectedResponseProcessing('not Template');
     }
     return $returnValue;
 }
Пример #2
0
 /**
  * Short description of method takeOverFrom
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  ResponseProcessing responseProcessing
  * @param  Item item
  * @return oat\taoQtiItem\model\qti\response\Composite
  */
 public static function takeOverFrom(ResponseProcessing $responseProcessing, Item $item)
 {
     $returnValue = null;
     if ($responseProcessing instanceof static) {
         // already good
         $returnValue = $responseProcessing;
     } elseif ($responseProcessing instanceof Template) {
         // IMS Template
         $rp = new Summation($item, 'SCORE');
         foreach ($item->getInteractions() as $interaction) {
             $response = $interaction->getResponse();
             try {
                 $irp = Template::createByTemplate($responseProcessing->getUri(), $response, $item);
             } catch (Exception $e) {
                 throw new TakeoverFailedException();
             }
             $rp->add($irp, $item);
         }
         $returnValue = $rp;
     } elseif ($responseProcessing instanceof TemplatesDriven) {
         // TemplateDriven
         $rp = new Summation($item, 'SCORE');
         foreach ($item->getInteractions() as $interaction) {
             $response = $interaction->getResponse();
             try {
                 $irp = Template::createByTemplate($responseProcessing->getTemplate($response), $response, $item);
             } catch (Exception $e) {
                 throw new TakeoverFailedException();
             }
             $rp->add($irp, $item);
         }
         $returnValue = $rp;
     } else {
         common_Logger::d('Composite ResponseProcessing can not takeover from ' . get_class($responseProcessing) . ' yet');
         throw new TakeoverFailedException();
     }
     common_Logger::i('Converted to Composite', array('TAOITEMS', 'QTI'));
     return $returnValue;
 }
 /**
  * Short description of method buildTemplateResponseProcessing
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  DOMElement data
  * @return oat\taoQtiItem\model\qti\response\ResponseProcessing
  */
 protected function buildTemplateResponseProcessing(DOMElement $data)
 {
     $returnValue = null;
     if ($data->hasAttribute('template') && $data->childNodes->length === 0) {
         $templateUri = (string) $data->getAttribute('template');
         $returnValue = new Template($templateUri);
     } elseif ($data->childNodes->length === 1) {
         $patternCorrectIMS = 'responseCondition [count(./*) = 2 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] [name(./*[2]) = "responseElse" ] [count(./responseElse/*) = 1 ] [name(./responseElse/*[1]) = "setOutcomeValue" ] [name(./responseElse/setOutcomeValue/*[1]) = "baseValue"]';
         $patternMappingIMS = 'responseCondition [count(./*) = 2] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "isNull"] [name(./responseIf/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "variable"] [name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "mapResponse"]';
         $patternMappingPointIMS = 'responseCondition [count(./*) = 2] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "isNull"] [name(./responseIf/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "variable"] [name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "mapResponsePoint"]';
         if (count($this->queryXPath($patternCorrectIMS)) == 1) {
             $returnValue = new Template(Template::MATCH_CORRECT);
         } elseif (count($this->queryXPath($patternMappingIMS)) == 1) {
             $returnValue = new Template(Template::MAP_RESPONSE);
         } elseif (count($this->queryXPath($patternMappingPointIMS)) == 1) {
             $returnValue = new Template(Template::MAP_RESPONSE_POINT);
         } else {
             throw new UnexpectedResponseProcessing('not Template, wrong rule');
         }
         $returnValue->setRelatedItem($this->item);
     } else {
         throw new UnexpectedResponseProcessing('not Template');
     }
     return $returnValue;
 }