protected function getOutcome($identifier) { foreach ($this->item->getOutcomes() as $outcome) { if ($outcome->getIdentifier() == $identifier) { return $outcome; } } throw new ParsingException('cannot found the outcome with identifier ' . $identifier); }
/** * Short description of method create * * @access public * @author Joel Bout, <*****@*****.**> * @param * Item item * @return oat\taoQtiItem\model\qti\response\ResponseProcessing */ public static function create(Item $item) { $returnValue = new TemplatesDriven(); if (count($item->getOutcomes()) == 0) { $item->setOutcomes(array(new OutcomeDeclaration(array('identifier' => 'SCORE', 'baseType' => 'float', 'cardinality' => 'single')))); } foreach ($item->getInteractions() as $interaction) { $returnValue->setTemplate($interaction->getResponse(), Template::MATCH_CORRECT); } return $returnValue; }
/** * Short description of method __construct * * @access public * @author Joel Bout, <*****@*****.**> * @param Item item * @param string outcomeIdentifier * @return mixed */ public function __construct(Item $item, $outcomeIdentifier = 'SCORE') { parent::__construct(); $this->outcomeIdentifier = $outcomeIdentifier; $outcomeExists = false; foreach ($item->getOutcomes() as $outcome) { if ($outcome->getIdentifier() == $outcomeIdentifier) { $outcomeExists = true; break; } } if (!$outcomeExists) { $outcomes = $item->getOutcomes(); $outcomes[] = new OutcomeDeclaration(array('identifier' => $outcomeIdentifier, 'baseType' => 'float', 'cardinality' => 'single')); $item->setOutcomes($outcomes); } }
/** * Short description of method create * * @access public * @author Joel Bout, <*****@*****.**> * @param int classID * @param Response response * @param Item item * @return oat\taoQtiItem\model\qti\response\interactionResponseProcessing\InteractionResponseProcessing */ public static function create($classID, ResponseDeclaration $response, Item $item) { switch ($classID) { case None::CLASS_ID: $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\None'; break; case MatchCorrectTemplate::CLASS_ID: $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MatchCorrectTemplate'; break; case MapResponseTemplate::CLASS_ID: $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MapResponseTemplate'; break; case MapResponsePointTemplate::CLASS_ID: $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MapResponsePointTemplate'; break; case Custom::CLASS_ID: $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\Custom'; break; default: throw new common_exception_Error('Unknown InteractionResponseProcessing Class ID "' . $classID . '"'); } $outcome = self::generateOutcomeDefinition(); $outcomes = $item->getOutcomes(); $outcomes[] = $outcome; $item->setOutcomes($outcomes); $returnValue = new $className($response, $outcome); return $returnValue; }
/** * Short description of method buildCompositeResponseProcessing * * @access public * @author Joel Bout, <*****@*****.**> * @param DOMElement data * @param Item item * @return oat\taoQtiItem\model\qti\response\ResponseProcessing */ protected function buildCompositeResponseProcessing(DOMElement $data, Item $item) { $returnValue = null; // STRONGLY simplified summation detection $patternCorrectTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue"]'; $patternMapTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not/*) = 1 ] [name(./responseIf/not/*[1]) = "isNull" ] [count(./responseIf/not/isNull/*) = 1 ] [name(./responseIf/not/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "mapResponse"]'; $patternMapPointTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not/*) = 1 ] [name(./responseIf/not/*[1]) = "isNull" ] [count(./responseIf/not/isNull/*) = 1 ] [name(./responseIf/not/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "mapResponsePoint"]'; $patternNoneTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "isNull" ] [count(./responseIf/isNull/*) = 1 ] [name(./responseIf/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue"]'; $possibleSummation = '/setOutcomeValue [count(./*) = 1 ] [name(./*[1]) = "sum" ]'; $irps = array(); $composition = null; $data = simplexml_import_dom($data); foreach ($data as $responseRule) { if (!is_null($composition)) { throw new UnexpectedResponseProcessing('Not composite, rules after composition'); } $subtree = new SimpleXMLElement($responseRule->asXML()); if (count($subtree->xpath($patternCorrectTAO)) > 0) { $responseIdentifier = (string) $subtree->responseIf->match->variable[0]['identifier']; $irps[$responseIdentifier] = array('class' => 'MatchCorrectTemplate', 'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']); } elseif (count($subtree->xpath($patternMapTAO)) > 0) { $responseIdentifier = (string) $subtree->responseIf->not->isNull->variable[0]['identifier']; $irps[$responseIdentifier] = array('class' => 'MapResponseTemplate', 'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']); } elseif (count($subtree->xpath($patternMapPointTAO)) > 0) { $responseIdentifier = (string) $subtree->responseIf->not->isNull->variable[0]['identifier']; $irps[$responseIdentifier] = array('class' => 'MapResponsePointTemplate', 'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']); } elseif (count($subtree->xpath($patternNoneTAO)) > 0) { $responseIdentifier = (string) $subtree->responseIf->isNull->variable[0]['identifier']; $irps[$responseIdentifier] = array('class' => 'None', 'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier'], 'default' => (string) $subtree->responseIf->setOutcomeValue[0]->baseValue[0]); } elseif (count($subtree->xpath($possibleSummation)) > 0) { $composition = 'Summation'; $outcomesUsed = array(); foreach ($subtree->xpath('/setOutcomeValue/sum/variable') as $var) { $outcomesUsed[] = (string) $var[0]['identifier']; } } else { throw new UnexpectedResponseProcessing('Not composite, unknown rule'); } } if (is_null($composition)) { throw new UnexpectedResponseProcessing('Not composit, Composition rule missing'); } $responses = array(); foreach ($item->getInteractions() as $interaction) { $responses[$interaction->getResponse()->getIdentifier()] = $interaction->getResponse(); } if (count(array_diff(array_keys($irps), array_keys($responses))) > 0) { throw new UnexpectedResponseProcessing('Not composit, no responses for rules: ' . implode(',', array_diff(array_keys($irps), array_keys($responses)))); } if (count(array_diff(array_keys($responses), array_keys($irps))) > 0) { common_Logger::w('Some responses have no processing'); throw new UnexpectedResponseProcessing('Not composit, no support for unmatched variables yet'); } //assuming sum is correct $compositonRP = new Summation($item); foreach ($responses as $id => $response) { $outcome = null; foreach ($item->getOutcomes() as $possibleOutcome) { if ($possibleOutcome->getIdentifier() == $irps[$id]['outcome']) { $outcome = $possibleOutcome; break; } } if (is_null($outcome)) { throw new ParsingException('Undeclared Outcome in ResponseProcessing'); } $classname = '\\oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\' . $irps[$id]['class']; $irp = new $classname($response, $outcome); if ($irp instanceof \oat\taoQtiItem\model\qti\response\interactionResponseProcessing\None && isset($irps[$id]['default'])) { $irp->setDefaultValue($irps[$id]['default']); } $compositonRP->add($irp); } $returnValue = $compositonRP; return $returnValue; }