/** * 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; }
/** * Build a QTI_Item from a DOMElement, the root tag of which is root assessmentItem * * @param DOMElement $data * @return oat\taoQtiItem\model\qti\Item * @throws oat\taoQtiItem\model\qti\exception\ParsingException */ protected function buildItem(DOMElement $data) { //check on the root tag. $itemId = (string) $data->getAttribute('identifier'); common_Logger::i('Started parsing of QTI item' . (isset($itemId) ? ' ' . $itemId : ''), array('TAOITEMS')); //create the item instance $this->item = new Item($this->extractAttributes($data)); foreach ($this->queryXPath('namespace::*') as $node) { $name = preg_replace('/xmlns(:)?/', '', $node->nodeName); $this->item->addNamespace($name, $node->nodeValue); } $nsQti = $this->item->getNamespace('http://www.imsglobal.org/xsd/imsqti_v2p1'); $this->qtiPrefix = $nsQti ? $nsQti . ':' : ''; $styleSheetNodes = $this->queryXPath("*[name(.) = 'stylesheet']", $data); foreach ($styleSheetNodes as $styleSheetNode) { $styleSheet = $this->buildStylesheet($styleSheetNode); $this->item->addStylesheet($styleSheet); } //extract the responses $responseNodes = $this->queryXPath("*[name(.) = 'responseDeclaration']", $data); foreach ($responseNodes as $responseNode) { $response = $this->buildResponseDeclaration($responseNode); if (!is_null($response)) { $this->item->addResponse($response); } } //extract outcome variables $outcomes = array(); $outComeNodes = $this->queryXPath("*[name(.) = 'outcomeDeclaration']", $data); foreach ($outComeNodes as $outComeNode) { $outcome = $this->buildOutcomeDeclaration($outComeNode); if (!is_null($outcome)) { $outcomes[] = $outcome; } } if (count($outcomes) > 0) { $this->item->setOutcomes($outcomes); } //extract modal feedbacks $feedbackNodes = $this->queryXPath("*[name(.) = 'modalFeedback']", $data); foreach ($feedbackNodes as $feedbackNode) { $modalFeedback = $this->buildFeedback($feedbackNode); if (!is_null($modalFeedback)) { $this->item->addModalFeedback($modalFeedback); } } //extract the item structure to separate the structural/style content to the item content $itemBodies = $this->queryXPath("*[name(.) = 'itemBody']", $data); // array with 1 or zero bodies if ($itemBodies === false) { $errors = libxml_get_errors(); if (count($errors) > 0) { $error = array_shift($errors); $errormsg = $error->message; } else { $errormsg = "without errormessage"; } throw new ParsingException('XML error(' . $errormsg . ') on itemBody read' . (isset($itemId) ? ' for item ' . $itemId : '')); } elseif ($itemBodies->length) { $this->parseContainerItemBody($itemBodies->item(0), $this->item->getBody()); } //warning: extract the response processing at the latest to make oat\taoQtiItem\model\qti\response\TemplatesDriven::takeOverFrom() work $rpNodes = $this->queryXPath("*[name(.) = 'responseProcessing']", $data); if ($rpNodes->length === 0) { common_Logger::i('No responseProcessing found for QTI Item, setting empty custom', array('QTI', 'TAOITEMS')); $customrp = new Custom(array(), '<responseProcessing/>'); $this->item->setResponseProcessing($customrp); } else { $rpNode = $rpNodes->item(0); //the node should be alone $rProcessing = $this->buildResponseProcessing($rpNode, $this->item); if (!is_null($rProcessing)) { $this->item->setResponseProcessing($rProcessing); } } return $this->item; }