/** * Short description of method getInteractionResponseProcessing * * @access public * @author Joel Bout, <*****@*****.**> * @param Response response * @return oat\taoQtiItem\model\qti\response\interactionResponseProcessing\InteractionResponseProcessing */ public function getInteractionResponseProcessing(ResponseDeclaration $response) { foreach ($this->components as $irp) { if ($irp->getResponse() == $response) { $returnValue = $irp; break; } } if (is_null($returnValue)) { throw new common_Exception('No interactionResponseProcessing defined for ' . $response->getIdentifier()); } return $returnValue; }
/** * Short description of method getTemplate * * @access public * @author Joel Bout, <*****@*****.**> * @param Response response * @return string */ public function getTemplate(ResponseDeclaration $response) { return (string) $response->getHowMatch(); }
public function addResponse(ResponseDeclaration $response) { $this->responses[$response->getSerial()] = $response; $response->setRelatedItem($this); }
public function testSimpleFeedbackCorrect() { $outcomeFeedback = new OutcomeDeclaration(array('identifier' => 'FEEDBACK')); $response2 = new ResponseDeclaration(array('identifier' => 'RESPONSE2')); $response2->setHowMatch(Template::MATCH_CORRECT); $modalFeedback3 = new ModalFeedback(array('identifier' => 'feedbackThree')); $feebackRuleB = new SimpleFeedbackRule($outcomeFeedback, $modalFeedback3); $feebackRuleB->setCondition($response2, 'correct'); $output3 = $feebackRuleB->toQTI(); $doc = new \DOMDocument(); $doc->loadXML($output3); $data = simplexml_import_dom($doc); $patternFeedbackCorrect = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[1]) = "variable" ] [name(./responseIf/*[1]/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ]'; $match = $data->xpath($patternFeedbackCorrect); $responseIdentifier = (string) $data->responseIf->match->variable['identifier']; $feedbackOutcomeIdentifier = (string) $data->responseIf->setOutcomeValue['identifier']; $feedbackIdentifier = (string) $data->responseIf->setOutcomeValue->baseValue; $this->assertEquals($responseIdentifier, 'RESPONSE2'); $this->assertEquals($feedbackOutcomeIdentifier, 'FEEDBACK'); $this->assertEquals($feedbackIdentifier, 'feedbackThree'); }
/** * 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; $responses[] = htmlentities($correct); } break; } $myResponse->setCorrectResponses($responses); //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; }