/**
  * Load the constantfiles.
  *
  * @access protected
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param array $extraConstants
  * @return void
  */
 protected function loadConstants($extraConstants)
 {
     common_Logger::t('Loading extension ' . $this->extension->getId() . ' constants');
     // load the constants from the manifest
     if ($this->extension->getId() != "generis") {
         foreach ($this->extension->getConstants() as $key => $value) {
             if (!defined($key) && !is_array($value)) {
                 define($key, $value);
             }
         }
     }
     // we will load the constant file of the current extension and all it's dependancies
     // get the dependancies
     $extensions = array_keys($this->extension->getDependencies());
     // merge them with the additional constants (defined in the options)
     $extensions = array_merge($extensions, $extraConstants);
     // add the current extension (as well !)
     $extensions = array_merge(array($this->extension->getId()), $extensions);
     foreach ($extensions as $extension) {
         if ($extension == 'generis') {
             continue;
             //generis constants are already loaded
         }
         //load the config of the extension
         $this->loadConstantsFile($extension);
     }
 }
Example #2
0
 /**
  * Load the extension.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param array $extraConstants
  * @return mixed
  */
 public function load($extraConstants = array())
 {
     if (!empty($extraConstants)) {
         throw new common_exception_Error('Loading extra constants in ' . __CLASS__ . ' nolonger supported');
     }
     common_Logger::t('Loading extension ' . $this->getExtension()->getId() . ' constants');
     // load the constants from the manifest
     if ($this->extension->getId() != "generis") {
         foreach ($this->extension->getConstants() as $key => $value) {
             if (!defined($key) && !is_array($value)) {
                 define($key, $value);
             }
         }
     }
     $constantFile = $this->getExtension()->getDir() . 'includes' . DIRECTORY_SEPARATOR . 'constants.php';
     if (file_exists($constantFile)) {
         //include the constant file
         include_once $constantFile;
         //this variable comes from the constant file and contain the const definition
         if (isset($todefine)) {
             foreach ($todefine as $constName => $constValue) {
                 if (!defined($constName)) {
                     define($constName, $constValue);
                     //constants are defined there!
                 } else {
                     common_Logger::d('Constant ' . $constName . ' in ' . $this->getExtension()->getId() . ' has already been defined');
                 }
             }
             unset($todefine);
         }
     }
 }
 public function run()
 {
     common_Logger::t('Uninstall Tao Update TODO');
     $extmanger = common_ext_ExtensionsManager::singleton();
     $ext = $extmanger->getExtensionById('taoUpdate');
     $extuninstaller = new common_ext_ExtensionUninstaller($ext);
     $extuninstaller->uninstall();
 }
Example #4
0
 /**
  * Short description of method feed
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  */
 public function feed()
 {
     common_Logger::t('Evaluating AsyncFile ' . $this->getName(), array('TAO'));
     if (isset($_POST[$this->name])) {
         $struct = json_decode($_POST[$this->name], true);
         if ($struct !== false) {
             $this->setValue($struct);
         } else {
             common_Logger::w('Could not unserialise AsyncFile field ' . $this->getName(), array('TAO'));
         }
     }
 }
 public function run()
 {
     $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('ltiProvider');
     if ($ext->isInstalled()) {
         common_Logger::t('Uninstall ltiProvider');
         $db = core_kernel_classes_DbWrapper::singleton();
         $sql = "DELETE from extensions where id ='ltiProvider';";
         $db->exec($sql);
         tao_helpers_File::delTree($ext->getConstant('BASE_PATH'));
         $newExt = common_ext_ExtensionsManager::singleton()->getExtensionById('taoLti');
         taoUpdate_models_classes_DataMigrationService::singleton()->installExtension($newExt);
     }
 }
 /**
  * Export the Test definition itself and its related media.
  *
  * @param array $itemIdentifiers An array of identifiers that were assigned to exported items into the IMS Manifest.
  */
 protected function exportTest(array $itemIdentifiers)
 {
     $testXmlDocument = $this->postProcessing($this->getTestDocument()->saveToString());
     $newTestDir = 'tests/' . tao_helpers_Uri::getUniqueId($this->getItem()->getUri()) . '/';
     $testRootDir = $this->getTestService()->getQtiTestDir($this->getItem());
     $file = $this->getTestService()->getQtiTestFile($this->getItem());
     // revert backslashes introduced by dirname on windows
     $relPath = trim(str_replace('\\', '/', dirname($testRootDir->getRelPath($file))), '/');
     $testHref = $newTestDir . (empty($relPath) ? '' : $relPath . '/') . 'test.xml';
     common_Logger::t('TEST DEFINITION AT: ' . $testHref);
     $this->getZip()->addFromString($testHref, $testXmlDocument);
     $this->referenceTest($testHref, $itemIdentifiers);
     $iterator = $testRootDir->getFlyIterator(Directory::ITERATOR_RECURSIVE | Directory::ITERATOR_FILE);
     foreach ($iterator as $f) {
         // Only add dependency files...
         if ($f->getBasename() !== TAOQTITEST_FILENAME) {
             // Add the file to the archive.
             $fileHref = $newTestDir . ltrim($testRootDir->getRelPath($f), '/');
             common_Logger::t('AUXILIARY FILE AT: ' . $fileHref);
             $this->getZip()->addFromString($fileHref, $f->read());
             $this->referenceAuxiliaryFile($fileHref);
         }
     }
 }
 /**
  * Short description of method importResource
  *
  * @access private
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  core_kernel_classes_Property $targetProperty
  * @param  core_kernel_classes_Resource $targetResource
  * @param  string $csvRow
  * @param  string $csvColumn
  * @return mixed
  */
 private function importResource(core_kernel_classes_Property $targetProperty, core_kernel_classes_Resource $targetResource, $csvRow, $csvColumn)
 {
     if ($csvColumn != 'csv_select' && $csvColumn != 'csv_null') {
         // We have to import the cell value as a resource for the target property.
         $value = $csvRow[$csvColumn];
         if ($value != null) {
             common_Logger::t("CSV - Importing a resource");
             $value = $this->applyCallbacks($csvRow[$csvColumn], $this->options, $targetProperty);
             $this->attachResource($targetProperty, $targetResource, $value);
         } else {
             // We have here an exception. The column mapped related to $targetProperty
             // is mapped but not value was found for the current cell. If an entry
             // in the static data map corresponds to the current property, the default
             // value should be used to set the property value.
         }
     } else {
         common_Logger::d("CSV - A default value will be affected.");
     }
 }
Example #8
0
 public function analyseLogPerformance()
 {
     common_Logger::singleton()->enable();
     $start = microtime(true);
     for ($i = 0; $i < self::RUNS; $i++) {
         // nothing
     }
     $emptyTime = microtime(true) - $start;
     echo "Idle run: " . $emptyTime . "<br />";
     $start = microtime(true);
     for ($i = 0; $i < self::RUNS; $i++) {
         common_Logger::t('a trace test message');
     }
     $traceTime = microtime(true) - $start;
     echo "Trace run: " . $traceTime . "<br />";
     $start = microtime(true);
     for ($i = 0; $i < self::RUNS; $i++) {
         common_Logger::i('a info test message');
     }
     $infoTime = microtime(true) - $start;
     echo "Info run: " . $infoTime . "<br />";
     common_Logger::singleton()->restore();
     common_Logger::singleton()->disable();
     $start = microtime(true);
     for ($i = 0; $i < self::RUNS; $i++) {
         common_Logger::i('a disabled test message');
     }
     $disabledTime = microtime(true) - $start;
     echo "Disabled run: " . $disabledTime . "<br />";
     common_Logger::singleton()->restore();
     $start = microtime(true);
     sleep(1);
     $testwait = microtime(true) - $start;
     echo "Wait: " . $testwait . "<br />";
     echo "ok";
 }
 /**
  * AssessmentTestSession implementations must override this method in order to submit test results
  * from the current AssessmentTestSession to the appropriate data source.
  *
  * This method is triggered once at the end of the AssessmentTestSession.
  *
  * * @throws AssessmentTestSessionException With error code RESULT_SUBMISSION_ERROR if an error occurs while transmitting results.
  */
 protected function submitTestResults()
 {
     $testUri = $this->getTest()->getUri();
     $sessionId = $this->getSessionId();
     foreach ($this->getAllVariables() as $var) {
         common_Logger::t("Submitting test result '" . $var->getIdentifier() . "' related to test '" . $testUri . "'.");
         $this->getResultTransmitter()->transmitTestVariable($var, $sessionId, $testUri);
     }
 }
 /**
  * Compile the RubricBlocRefs' contents into a separate rubric block PHP template.
  * 
  * @param AssessmentTest $assessmentTest The AssessmentTest object you want to compile the rubrickBlocks.
  */
 protected function compileRubricBlocks(AssessmentTest $assessmentTest)
 {
     $rubricBlockRefs = $assessmentTest->getComponentsByClassName('rubricBlockRef');
     $testService = taoQtiTest_models_classes_QtiTestService::singleton();
     $sourceDir = $testService->getQtiTestDir($this->getResource());
     foreach ($rubricBlockRefs as $rubricRef) {
         $rubricRefHref = $rubricRef->getHref();
         $cssScoper = $this->getCssScoper();
         $renderingEngine = $this->getRenderingEngine();
         $markupPostRenderer = $this->getMarkupPostRenderer();
         $publicCompiledDocDir = $this->getPublicDirectory();
         $privateCompiledDocDir = $this->getPrivateDirectory();
         // -- loading...
         common_Logger::t("Loading rubricBlock '" . $rubricRefHref . "'...");
         $rubricDoc = new XmlDocument();
         $rubricDoc->loadFromString($this->getPrivateDirectory()->read($rubricRefHref));
         common_Logger::t("rubricBlock '" . $rubricRefHref . "' successfully loaded.");
         // -- rendering...
         common_Logger::t("Rendering rubricBlock '" . $rubricRefHref . "'...");
         $pathinfo = pathinfo($rubricRefHref);
         $renderingFile = $pathinfo['filename'] . '.php';
         $rubric = $rubricDoc->getDocumentComponent();
         $rubricStylesheets = $rubric->getStylesheets();
         $stylesheets = new StylesheetCollection();
         // In any case, include the base QTI Stylesheet.
         $stylesheets->merge($rubricStylesheets);
         $rubric->setStylesheets($stylesheets);
         // -- If the rubricBlock has no id, give it a auto-generated one in order
         // to be sure that CSS rescoping procedure works fine (it needs at least an id
         // to target its scoping).
         if ($rubric->hasId() === false) {
             // Prepend 'tao' to the generated id because the CSS
             // ident token must begin by -|[a-zA-Z]
             $rubric->setId('tao' . uniqid());
         }
         // -- Copy eventual remote resources of the rubricBlock.
         $this->copyRemoteResources($rubric);
         $domRendering = $renderingEngine->render($rubric);
         $mainStringRendering = $markupPostRenderer->render($domRendering);
         // Prepend stylesheets rendering to the main rendering.
         $styleRendering = $renderingEngine->getStylesheets();
         $mainStringRendering = $styleRendering->ownerDocument->saveXML($styleRendering) . $mainStringRendering;
         foreach ($stylesheets as $rubricStylesheet) {
             $relPath = trim($this->getExtraPath(), '/');
             $relPath = (empty($relPath) ? '' : $relPath . DIRECTORY_SEPARATOR) . $rubricStylesheet->getHref();
             $sourceFile = $sourceDir->getFile($relPath);
             if (!$publicCompiledDocDir->has($relPath)) {
                 try {
                     $data = $sourceFile->read();
                     $tmpDir = \tao_helpers_File::createTempDir();
                     $tmpFile = $tmpDir . 'tmp.css';
                     file_put_contents($tmpFile, $data);
                     $scopedCss = $cssScoper->render($tmpFile, $rubric->getId());
                     unlink($tmpFile);
                     rmdir($tmpDir);
                     $publicCompiledDocDir->write($relPath, $scopedCss);
                 } catch (\InvalidArgumentException $e) {
                     common_Logger::e('Unable to copy file into public directory: ' . $relPath);
                 }
             }
         }
         // -- Replace the artificial 'tao://qti-directory' base path with a runtime call to the delivery time base path.
         $mainStringRendering = str_replace(TAOQTITEST_PLACEHOLDER_BASE_URI, '<?php echo $' . TAOQTITEST_BASE_PATH_NAME . '; ?>', $mainStringRendering);
         if (!$privateCompiledDocDir->has($renderingFile)) {
             try {
                 $privateCompiledDocDir->write($renderingFile, $mainStringRendering);
                 common_Logger::t("rubricBlockRef '" . $rubricRefHref . "' successfully rendered.");
             } catch (\InvalidArgumentException $e) {
                 common_Logger::e('Unable to copy file into public directory: ' . $renderingFile);
             }
         }
         // -- Clean up old rubric block and reference the new rubric block template.
         $privateCompiledDocDir->delete($rubricRefHref);
         $rubricRef->setHref('./' . $pathinfo['filename'] . '.php');
     }
 }
 /**
  * Export the Test definition itself and its related media.
  * 
  * @param array $itemIdentifiers An array of identifiers that were assigned to exported items into the IMS Manifest.
  */
 protected function exportTest(array $itemIdentifiers)
 {
     // Serialize the test definition somewhere and add
     // it to the archive.
     $tmpPath = tempnam('/tmp', 'tao');
     $this->getTestDocument()->save($tmpPath);
     $testPath = $this->getTestService()->getTestContent($this->getItem())->getAbsolutePath();
     // Add the test definition in the archive.
     $testBasePath = 'tests/' . tao_helpers_Uri::getUniqueId($this->getItem()->getUri()) . '/';
     $extraPath = trim(str_replace(array($testPath, TAOQTITEST_FILENAME), '', $this->getTestService()->getDocPath($this->getItem())), DIRECTORY_SEPARATOR);
     $testHref = $testBasePath . (empty($extraPath) === false ? $extraPath . '/' : '') . 'test.xml';
     common_Logger::t('TEST DEFINITION AT: ' . $testHref);
     $this->addFile($tmpPath, $testHref);
     $this->referenceTest($testHref, $itemIdentifiers);
     $files = tao_helpers_File::scandir($testPath, array('recursive' => true, 'absolute' => true));
     foreach ($files as $f) {
         // Only add dependency files...
         if (is_dir($f) === false && strpos($f, TAOQTITEST_FILENAME) === false) {
             // Add the file to the archive.
             $fileHref = $testBasePath . ltrim(str_replace($testPath, '', $f), '/');
             common_Logger::t('AUXILIARY FILE AT: ' . $fileHref);
             $this->getZip()->addFile($f, $fileHref);
             $this->referenceAuxiliaryFile($fileHref);
         }
     }
 }
 /**
  * Update the durations involved in the AssessmentTestSession to mirror the durations at the current time.
  * This method can be useful for stateless systems that make use of QtiSm.
  */
 public function updateDuration()
 {
     // not needed anymore
     \common_Logger::t('Call to disabled updateDuration()');
 }
Example #13
0
 /**
  * Write a content into $this file, if not exists
  * $mixed content has to be string, resource, or PSR Stream
  * In case of Stream, $mixed has to be seekable and readable
  *
  * @param string|Resource|StreamInterface $mixed
  * @param null $mimeType
  * @return bool
  * @throws \common_Exception
  * @throws FileExistsException
  */
 public function write($mixed, $mimeType = null)
 {
     \common_Logger::t('Writting in ' . $this->getPrefix());
     $config = is_null($mimeType) ? [] : ['ContentType' => $mimeType];
     if (is_string($mixed)) {
         return $this->getFileSystem()->write($this->getPrefix(), $mixed, $config);
     } elseif (is_resource($mixed)) {
         return $this->getFileSystem()->writeStream($this->getPrefix(), $mixed, $config);
     } elseif ($mixed instanceof StreamInterface) {
         if (!$mixed->isReadable()) {
             throw new \common_Exception('Stream is not readable. Write to filesystem aborted.');
         }
         if (!$mixed->isSeekable()) {
             throw new \common_Exception('Stream is not seekable. Write to filesystem aborted.');
         }
         $mixed->rewind();
         $resource = StreamWrapper::getResource($mixed);
         if (!is_resource($resource)) {
             throw new \common_Exception('Unable to create resource from the given stream. Write to filesystem aborted.');
         }
         return $this->getFileSystem()->writeStream($this->getPrefix(), $resource, $config);
     } else {
         throw new \InvalidArgumentException('Value to be written has to be: string, resource or StreamInterface, ' . '"' . gettype($mixed) . '" given.');
     }
 }
 /**
  * 
  * @see common_persistence_Purgable::purge()
  */
 public function purge()
 {
     common_Logger::t('NoStorageKvPersistence is purged');
     return true;
 }
 /**
  * Copy the test resources (e.g. images) that will be availabe at delivery time
  * in the public compilation directory.
  * 
  */
 protected function copyPublicResources()
 {
     $compiledDocDir = $this->getPrivateDirectory()->getPath();
     $publicCompiledDocDir = $this->getPublicDirectory()->getPath();
     foreach (tao_helpers_File::scandir($compiledDocDir, array('recursive' => true, 'only' => tao_helpers_File::$FILE, 'absolute' => true)) as $file) {
         $mime = tao_helpers_File::getMimeType($file, true);
         $pathinfo = pathinfo($file);
         // Exclude CSS files because already copied when dealing with rubric blocks.
         if (in_array($mime, self::getPublicMimeTypes()) === true && $pathinfo['extension'] !== 'php') {
             $file = str_replace($compiledDocDir, '', $file);
             common_Logger::t("Copying public resource '{$file}'...");
             taoQtiTest_helpers_Utils::storeQtiResource($publicCompiledDocDir, $file, $compiledDocDir);
         }
     }
 }