function loadTestDefinition(array &$average = null) { $start = microtime(); $phpDoc = new PhpDocument(); $phpDoc->load(dirname(__FILE__) . '/../../test/samples/custom/php/linear_4_items.php'); if (is_null($average) === false) { spentTime($start, microtime(), $average); } return $phpDoc->getDocumentComponent(); }
$basePath = '/../../src/qtism/runtime/processing/templates/2_1/'; $templates = array('match_correct', 'map_response', 'map_response_point'); $xmlTimings = array('match_correct' => array(), 'map_response' => array(), 'map_response_point' => array()); $phpTimings = array('match_correct' => array(), 'map_response' => array(), 'map_response_point' => array()); $iterations = 100; foreach ($templates as $t) { for ($i = 0; $i < $iterations; $i++) { // --- XML $start = microtime(); $xmlDoc = new XmlDocument('2.1'); $xmlDoc->load(dirname(__FILE__) . $basePath . $t . '.xml'); $end = microtime(); $xmlTimings[$t][] = spentTime($start, $end); // --- PHP $start = microtime(); $phpDoc = new PhpDocument(); $phpDoc->load(dirname(__FILE__) . $basePath . $t . '.php'); $end = microtime(); $phpTimings[$t][] = spentTime($start, $end); } } foreach ($templates as $t) { // compute arithmetic mean. $meanXml = 0; foreach ($xmlTimings[$t] as $v) { $meanXml += $v; } $meanXml = $meanXml / $iterations; // compute arithmetic mean. $meanPhp = 0; foreach ($phpTimings[$t] as $v) {
/** * Retrieve the Test Definition the test session is built from as an AssessmentTest object. * * @param string $qtiTestCompilation (e.g. <i>'http://sample/first.rdf#i14363448108243883-|http://sample/first.rdf#i14363448109065884+'</i>) * * @return AssessmentTest The AssessmentTest object the current test session is built from. */ public static function getTestDefinition($qtiTestCompilation) { $directoryIds = explode('|', $qtiTestCompilation); $dirPath = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryIds[0])->getPath(); $testFilePath = $dirPath . TAOQTITEST_COMPILED_FILENAME; common_Logger::d("Loading QTI-PHP file at '{$testFilePath}'."); $doc = new PhpDocument(); $doc->load($testFilePath); return $doc->getDocumentComponent(); }
/** * Compile the given $test into PHP source code for maximum performance. The file will be stored * into PRIVATE_DIRECTORY/compact-test.php. * * @param AssessmentTest $test */ protected function compileTest(AssessmentTest $test) { // Compiling a test may require extra processing time. helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::MEDIUM); $phpCompiledDoc = new PhpDocument('2.1', $test); $data = $phpCompiledDoc->saveToString(); $this->getPrivateDirectory()->write(TAOQTITEST_COMPILED_FILENAME, $data); common_Logger::d("QTI-PHP Test Compilation file saved to stream."); }
public function testLoadInteractionMixSaschsen() { $xmlDoc = new XmlDocument('2.1'); $xmlDoc->load(self::samplesDir() . 'ims/tests/interaction_mix_sachsen/interaction_mix_sachsen.xml'); $phpDoc = new PhpDocument(); $phpDoc->setDocumentComponent($xmlDoc->getDocumentComponent()); $file = tempnam('/tmp', 'qsm'); $phpDoc->save($file); $phpDoc = new PhpDocument(); $phpDoc->load($file); $this->assertEquals('InteractionMixSachsen_1901710679', $phpDoc->getDocumentComponent()->getIdentifier()); unlink($file); $this->assertFalse(file_exists($file)); }
<?php require_once dirname(__FILE__) . '/../../../../vendor/autoload.php'; use qtism\data\storage\php\PhpDocument; use qtism\data\storage\xml\XmlCompactDocument; $test = $argv[1]; $xmlFile = dirname(__FILE__) . "/../runtime/{$test}.xml"; $xmlDoc = new XmlCompactDocument(); $xmlDoc->load($xmlFile); $phpDoc = new PhpDocument(); $phpDoc->setDocumentComponent($xmlDoc->getDocumentComponent()); $phpDoc->save("{$test}.php");
/** * Execute the ResponseProcessing according to the current context. * * The following sub-types of ProcessingException may be thrown: * * * RuleProcessingException: If a ResponseRule in the ResponseProcessing produces an error OR if the ExitResponse rule is invoked. In this last case, a specific exception code will be produced to deal with the situation accordingly. * * ExpressionProcessingException: If an Expression within a ResponseRule produces an error. * * ResponseProcessingException: If there is a problem with the response processing template processing bound to the ResponseProcessing. * * @throws \qtism\runtime\common\ProcessingException */ public function process() { // @todo Figure out how to provide a way to the ResponseProcessingEngine to know the folder where to seek for templateLocation, which is a relative URI. $responseProcessing = $this->getComponent(); $template = $responseProcessing->getTemplate(); $templateLocation = $responseProcessing->getTemplateLocation(); if (count($responseProcessing->getResponseRules()) > 0) { // Always prefer the embedded rules. $rules = $responseProcessing->getResponseRules(); } else { $finalTemplateFile = ''; if (empty($template) === false) { // try to locate the template file thanks to the given mapping. $mapping = $this->getTemplateMapping(); if (isset($mapping[$template])) { $finalTemplateFile = $mapping[$template]; } } if (empty($finalTemplateFile) === true && empty($templateLocation) === false) { // The template could not be resolved using the mapping. // Try to use template location. if (@is_readable($templateLocation) === true) { $finalTemplateFile = $templateLocation; } } if (empty($finalTemplateFile) === true) { $msg = "The template file could not be found: template='{$template}', templateLocation='{$templateLocation}'."; throw new ResponseProcessingException($msg, $this, ResponseProcessingException::TEMPLATE_NOT_FOUND); } // Open the file and retrieve the rules. $this->trace("loading response processing template '{$finalTemplateFile}'"); $php = new PhpDocument(); $php->load($finalTemplateFile); $rules = $php->getDocumentComponent()->getResponseRules(); $this->trace(count($rules) . " responseRule(s) extracted from the response processing template"); } try { foreach ($rules as $rule) { $engine = new RuleEngine($rule, $this->getContext()); $engine->process(); $this->trace($rule->getQtiClassName() . ' executed'); } } catch (RuleProcessingException $e) { if ($e->getCode() !== RuleProcessingException::EXIT_RESPONSE) { throw $e; } else { $this->trace('Termination of response processing.'); } } }
/** * Retrieve the Test Definition the test session is built from as an AssessmentTest object. * * @param string $qtiTestCompilation (e.g. <i>'http://sample/first.rdf#i14363448108243883-|http://sample/first.rdf#i14363448109065884+'</i>) * * @return AssessmentTest The AssessmentTest object the current test session is built from. */ public static function getTestDefinition($qtiTestCompilation) { $directoryIds = explode('|', $qtiTestCompilation); $data = \tao_models_classes_service_FileStorage::singleton()->getDirectoryById($directoryIds[0])->read(TAOQTITEST_COMPILED_FILENAME); common_Logger::d("Loading QTI-PHP file from stream"); $doc = new PhpDocument(); $doc->loadFromString($data); return $doc->getDocumentComponent(); }
<?php require_once dirname(__FILE__) . '/../../../../qtism/qtism.php'; use qtism\data\storage\php\PhpDocument; use qtism\data\storage\xml\XmlCompactDocument; $xmlFile = dirname(__FILE__) . '/../runtime/nonlinear_40_items.xml'; $xmlDoc = new XmlCompactDocument(); $xmlDoc->load($xmlFile); $phpDoc = new PhpDocument(); $phpDoc->setDocumentComponent($xmlDoc->getDocumentComponent()); $phpDoc->save('nonlinear_40_items.php');
/** * Retrieve the Test Definition the test session is built * from as an AssessmentTest object. This method * also retrieves the compilation directory. * * @return AssessmentTest The AssessmentTest object the current test session is built from. */ protected function retrieveTestDefinition() { $directories = array('private' => null, 'public' => null); $directoryIds = explode('|', $this->getRequestParameter('QtiTestCompilation')); $directories['private'] = $this->getDirectory($directoryIds[0]); $directories['public'] = $this->getDirectory($directoryIds[1]); $this->setCompilationDirectory($directories); $dirPath = $directories['private']->getPath(); $testFilePath = $dirPath . TAOQTITEST_COMPILED_FILENAME; common_Logger::d("Loading QTI-PHP file at '{$testFilePath}'."); $doc = new PhpDocument(); $doc->load($testFilePath); $this->setTestDefinition($doc->getDocumentComponent()); }
/** * Compile the given $test into PHP source code for maximum performance. The file will be stored * into PRIVATE_DIRECTORY/compact-test.php. * * @param AssessmentTest $test */ protected function compileTest(AssessmentTest $test) { // Compiling a test may require extra processing time. helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::SHORT); $compiledDocDir = $this->getPrivateDirectory()->getPath(); $compiledDocPath = $compiledDocDir . TAOQTITEST_COMPILED_FILENAME; $phpCompiledDoc = new PhpDocument('2.1'); $phpCompiledDoc->setDocumentComponent($test); $phpCompiledDoc->save($compiledDocPath); common_Logger::d("QTI-PHP Test Compilation file registered at '" . $compiledDocPath . "'."); }