/** * * @access * @author "Patrick Plichart <*****@*****.**>" */ public function testStoreItemVariable() { //storeItemVariable(core_kernel_classes_Resource $deliveryResult, $test, $item, taoResultServer_models_classes_Variable $itemVariable, $callId) $deliveryResult = $this->service->storeDeliveryResult(); $this->service->storeTestTaker($deliveryResult, "unittest_testtaker"); $this->service->storeDelivery($deliveryResult, "unittest_delivery"); $itemVariable = new taoResultServer_models_classes_ResponseVariable(); $itemVariable->setCandidateResponse("unittest_candidateResponse"); $itemVariable->setCardinality("single"); $itemVariable->setIdentifier("unittest_identifier"); $itemVariable->setBaseType("file"); $storedVariable = $this->service->storeItemVariable($deliveryResult, "myTest", "myItem", $itemVariable, "callid_31"); }
/** * Transmit a QtiSm Runtime Variable to the target Result Server as an Item Result. * * @param mixed $variables QtiSm Runtime Variable(s). * @param string $transmissionId A unique identifier that identifies uniquely the visited item. * @param string $itemUri An optional URI that identifies uniquely the item the $variable comes from. * @param string $testUri An optional URL that identifies uniquely the test the $variable comes from. * @throws taoQtiCommon_helpers_ResultTransmissionException If an error occurs while transmitting the Variable to the target Result Server. */ public function transmitItemVariable($variables, $transmissionId, $itemUri = '', $testUri = '') { $itemVariableSet = array(); if (is_array($variables) === false) { $variables = array($variables); } foreach ($variables as $variable) { $identifier = $variable->getIdentifier(); if ($variable instanceof OutcomeVariable) { $value = $variable->getValue(); $resultVariable = new taoResultServer_models_classes_OutcomeVariable(); $resultVariable->setIdentifier($identifier); $resultVariable->setBaseType(BaseType::getNameByConstant($variable->getBaseType())); $resultVariable->setCardinality(Cardinality::getNameByConstant($variable->getCardinality())); $resultVariable->setValue(self::transformValue($value)); $itemVariableSet[] = $resultVariable; } else { if ($variable instanceof ResponseVariable) { // ResponseVariable. $value = $variable->getValue(); $resultVariable = new taoResultServer_models_classes_ResponseVariable(); $resultVariable->setIdentifier($identifier); $resultVariable->setBaseType(BaseType::getNameByConstant($variable->getBaseType())); $resultVariable->setCardinality(Cardinality::getNameByConstant($variable->getCardinality())); $resultVariable->setCandidateResponse(self::transformValue($value)); // The fact that the response is correct must not be sent for built-in // response variables 'duration' and 'numAttempts'. if (!in_array($identifier, array('duration', 'numAttempts', 'comment'))) { $resultVariable->setCorrectResponse($variable->isCorrect()); } $itemVariableSet[] = $resultVariable; } } } try { common_Logger::d("Sending Variables to result server."); $this->getResultServer()->storeItemVariableSet($testUri, $itemUri, $itemVariableSet, $transmissionId); } catch (Exception $e) { $msg = "An error occured while transmitting an Outcome Variable to the target result server."; $code = taoQtiCommon_helpers_ResultTransmissionException::OUTCOME; throw new taoQtiCommon_helpers_ResultTransmissionException($msg, $code); } }
<?php require_once dirname(__FILE__) . '/../includes/raw_start.php'; //done ahead of your code $rs = new taoResultServer_models_classes_ResultServerStateFull(); $rs->initResultServer("http://www.tao.lu/Ontologies/taoAltResultStorage.rdf#KeyValueResultStorage"); //optional control on Ids $id = $rs->spawnResult("myCoolId"); $rs->storeRelatedTestTaker("Jerome the big guy"); $rs->storeRelatedDelivery("Jerome's super delivery"); //you are doing this $itemVariable = new taoResultServer_models_classes_ResponseVariable(); $itemVariable->setCandidateResponse("[Jerome Awesome]"); $itemVariable->setCardinality("single"); $itemVariable->setIdentifier("unittest_identifier"); $itemVariable->setBaseType("pair"); $callIdItem = "An identifier of the execution of an item occurence for a test taker"; $rs->storeItemVariable("sometest identifier", "someidentifier", $itemVariable, $callIdItem); //and youn want to do this $variables = $rs->getVariables($callIdItem); $variable = $rs->getVariable($callIdItem, "unittest_identifier"); print_r($variable); $testtaker = $rs->getTestTaker($id); print_r($testtaker); $delivery = $rs->getDelivery($id); print_r($delivery); //consider results may have been broadcasted to different storages, //thus if one of them does not contain the readable interface, //you don't have an exception globally but partial data.
/** * * @author Lionel Lecaque, lionel@taotesting.com */ public function testGetItemVariableDataFromDeliveryResult() { $prophet = new Prophet(); $impProphecy = $prophet->prophesize('oat\\taoOutcomeRds\\model\\RdsResultStorage'); $impProphecy->getRelatedItemCallIds('#fakeUri')->willReturn(array('#itemsResults1' => '#itemResultVariable', '#itemsResults2' => '#itemResultVariable2', '#itemsResults3' => '#itemResultVariable3')); $item = new \stdClass(); $item->item = '#item'; $item->uri = '#uri'; $var = new \taoResultServer_models_classes_TraceVariable(); $var->setEpoch(microtime()); $var->setIdentifier('varIdentifier'); $item->variable = $var; $item2 = new \stdClass(); $item2->item = '#item2'; $item2->uri = '#uri2'; $var2 = new \taoResultServer_models_classes_ResponseVariable(); $var2->setEpoch(microtime()); $var2->setIdentifier('varIdentifier2'); // response correct $var2->setCorrectResponse(1); $item2->variable = $var2; $item3 = new \stdClass(); $item3->item = '#item3'; $item3->uri = '#uri3'; $var3 = new \taoResultServer_models_classes_ResponseVariable(); $var3->setEpoch(microtime()); $var3->setIdentifier('varIdentifier3'); // response incorrect $var3->setCorrectResponse(0); $item3->variable = $var3; $impProphecy->getVariables('#itemResultVariable')->willReturn(array(array($item))); $impProphecy->getVariables('#itemResultVariable2')->willReturn(array(array($item2))); $impProphecy->getVariables('#itemResultVariable3')->willReturn(array(array($item3))); $imp = $impProphecy->reveal(); $this->service->setImplementation($imp); $deliveryResultProphecy = $prophet->prophesize('core_kernel_classes_Resource'); $deliveryResultProphecy->getUri()->willReturn('#fakeUri'); $deliveryResult = $deliveryResultProphecy->reveal(); $itemVar = $this->service->getItemVariableDataFromDeliveryResult($deliveryResult, 'lastSubmitted'); $this->assertArrayHasKey('#item', $itemVar); $this->assertArrayHasKey('itemModel', $itemVar['#item']); $this->assertEquals('unknown', $itemVar['#item']['itemModel']); $this->assertArrayHasKey('sortedVars', $itemVar['#item']); $this->assertArrayHasKey('taoResultServer_models_classes_TraceVariable', $itemVar['#item']['sortedVars']); $this->assertArrayHasKey('varIdentifier', $itemVar['#item']['sortedVars']['taoResultServer_models_classes_TraceVariable']); $this->assertArrayHasKey('uri', $itemVar['#item']['sortedVars']['taoResultServer_models_classes_TraceVariable']['varIdentifier'][0]); $this->assertEquals('#uri', $itemVar['#item']['sortedVars']['taoResultServer_models_classes_TraceVariable']['varIdentifier'][0]['uri']); $this->assertArrayHasKey('isCorrect', $itemVar['#item']['sortedVars']['taoResultServer_models_classes_TraceVariable']['varIdentifier'][0]); $this->assertEquals('unscored', $itemVar['#item']['sortedVars']['taoResultServer_models_classes_TraceVariable']['varIdentifier'][0]['isCorrect']); $this->assertArrayHasKey('var', $itemVar['#item']['sortedVars']['taoResultServer_models_classes_TraceVariable']['varIdentifier'][0]); $this->assertInstanceOf('taoResultServer_models_classes_TraceVariable', $itemVar['#item']['sortedVars']['taoResultServer_models_classes_TraceVariable']['varIdentifier'][0]['var']); $this->assertEquals($var, $itemVar['#item']['sortedVars']['taoResultServer_models_classes_TraceVariable']['varIdentifier'][0]['var']); $this->assertArrayHasKey('label', $itemVar['#item']); // item2 $this->assertArrayHasKey('#item2', $itemVar); $this->assertArrayHasKey('itemModel', $itemVar['#item2']); $this->assertEquals('unknown', $itemVar['#item2']['itemModel']); $this->assertArrayHasKey('sortedVars', $itemVar['#item2']); $this->assertArrayHasKey('taoResultServer_models_classes_ResponseVariable', $itemVar['#item2']['sortedVars']); $this->assertArrayHasKey('varIdentifier2', $itemVar['#item2']['sortedVars']['taoResultServer_models_classes_ResponseVariable']); $this->assertArrayHasKey('uri', $itemVar['#item2']['sortedVars']['taoResultServer_models_classes_ResponseVariable']['varIdentifier2'][0]); $this->assertEquals('#uri2', $itemVar['#item2']['sortedVars']['taoResultServer_models_classes_ResponseVariable']['varIdentifier2'][0]['uri']); $this->assertArrayHasKey('isCorrect', $itemVar['#item2']['sortedVars']['taoResultServer_models_classes_ResponseVariable']['varIdentifier2'][0]); $this->assertEquals('correct', $itemVar['#item2']['sortedVars']['taoResultServer_models_classes_ResponseVariable']['varIdentifier2'][0]['isCorrect']); // item3 $this->assertArrayHasKey('#item3', $itemVar); $this->assertArrayHasKey('itemModel', $itemVar['#item3']); $this->assertEquals('unknown', $itemVar['#item3']['itemModel']); $this->assertArrayHasKey('sortedVars', $itemVar['#item3']); $this->assertArrayHasKey('taoResultServer_models_classes_ResponseVariable', $itemVar['#item3']['sortedVars']); $this->assertArrayHasKey('varIdentifier3', $itemVar['#item3']['sortedVars']['taoResultServer_models_classes_ResponseVariable']); $this->assertArrayHasKey('uri', $itemVar['#item3']['sortedVars']['taoResultServer_models_classes_ResponseVariable']['varIdentifier3'][0]); $this->assertEquals('#uri3', $itemVar['#item3']['sortedVars']['taoResultServer_models_classes_ResponseVariable']['varIdentifier3'][0]['uri']); $this->assertArrayHasKey('isCorrect', $itemVar['#item3']['sortedVars']['taoResultServer_models_classes_ResponseVariable']['varIdentifier3'][0]); $this->assertEquals('incorrect', $itemVar['#item3']['sortedVars']['taoResultServer_models_classes_ResponseVariable']['varIdentifier3'][0]['isCorrect']); }
$itemVariable->setValue("MyValue" . $i . $j); $itemVariable->setIdentifier("identifier" . $i . $j); $itemVariable->setCardinality("single"); $itemVariable->setBaseType("float"); } else { $itemVariable = new taoResultServer_models_classes_ResponseVariable(); $itemVariable->setCandidateResponse("[Jerome Awesome]"); $itemVariable->setCorrectResponse("[nop,plop]"); $itemVariable->setIdentifier("identifier" . $i . $j); $itemVariable->setCardinality("single"); $itemVariable->setBaseType("pair"); } $callIdItem = "An identifier of the execution of an item occurence for a test taker#" . $j; $item = "anotherId#" . $j; $rs->storeItemVariable($deliverIdentifier, $test, $item, $itemVariable, $callIdItem); // $rs->storeItemVariable($deliveryResult, $test, $item, $itemVariable, $callIdItem); } $callIdTest = "Great Test Id#134589"; $testVariable = new taoResultServer_models_classes_ResponseVariable(); $testVariable->setIdentifier("identifier" . $i); $testVariable->setCardinality("single"); $testVariable->setBaseType("pair"); $rs->storeTestVariable($deliverIdentifier, $test, $testVariable, $callIdTest); // $rs->storeTestVariable($deliveryResult, $test, $testVariable, $callIdTest); } $time_end = microtime(true); $time = $time_end - $time_start; echo "\n{$time}\n"; $timeTot += $time; } echo "{$timeTot}\n";
/** * @author "Patrick Plichart, <*****@*****.**>" */ public function storeItemVariableSet() { $variables = array(); $item = $this->hasRequestParameter("itemId") ? $this->getRequestParameter("itemId") : "undefined"; $callIdItem = $this->hasRequestParameter("serviceCallId") ? $this->getRequestParameter("serviceCallId") : "undefined"; $test = $this->hasRequestParameter("testId") ? $this->getRequestParameter("testId") : "undefined"; if ($this->hasRequestParameter("outcomeVariables")) { $outcomeVariables = $this->getRequestParameter("outcomeVariables"); foreach ($outcomeVariables as $variableName => $outcomeValue) { $outComeVariable = new taoResultServer_models_classes_OutcomeVariable(); //$outComeVariable->setBaseType("int"); $outComeVariable->setCardinality("single"); $outComeVariable->setIdentifier($variableName); $outComeVariable->setValue($outcomeValue); $variables[] = $outComeVariable; } } if ($this->hasRequestParameter("responseVariables")) { $responseVariables = $this->getRequestParameter("responseVariables"); foreach ($responseVariables as $variableName => $responseValue) { $responseVariable = new taoResultServer_models_classes_ResponseVariable(); //$responseVariable->setBaseType("int"); //$responseVariable->setCardinality("single"); $responseVariable->setIdentifier($variableName); $responseVariable->setCandidateResponse($responseValue); //$responseVariable->setCorrectResponse(true); $variables[] = $responseVariable; } } if ($this->hasRequestParameter("traceVariables")) { $traceVariables = $this->getRequestParameter("outcomeVariables"); foreach ($traceVariables as $variableName => $traceValue) { $traceVariable = new taoResultServer_models_classes_TraceVariable(); //$outComeVariable->setBaseType("int"); $traceVariable->setIdentifier($variableName); $traceVariable->setTrace($traceValue); $variables[] = $traceVariable; } } try { $data = $this->service->storeItemVariableSet($test, $item, $variables, $callIdItem); } catch (exception $e) { $this->returnFailure($e); } return $this->returnSuccess($data); }