Beispiel #1
0
 /**
  * Get the current mode
  * @example (tao_helpers_Mode::get() == tao_helpers_Mode::DEVELOPMENT)
  * @return int matching the constants
  */
 public static function get()
 {
     if (empty(self::$currentMode)) {
         self::$currentMode = self::getCurrentMode();
     }
     return self::$currentMode;
 }
 /**
  * Desploy all the required files into the provided directories
  * 
  * @param core_kernel_classes_Resource $item
  * @param string $language
  * @param string $publicDirectory
  * @param string $privateFolder
  * @return common_report_Report
  */
 protected function deployQtiItem(core_kernel_classes_Resource $item, $language, $publicDirectory, $privateFolder)
 {
     //        start debugging here
     common_Logger::d('destination original ' . $publicDirectory . ' ' . $privateFolder);
     $itemService = taoItems_models_classes_ItemsService::singleton();
     $qtiService = Service::singleton();
     //copy all item folder (but the qti.xml)
     $itemFolder = $itemService->getItemFolder($item, $language);
     taoItems_helpers_Deployment::copyResources($itemFolder, $publicDirectory, array('qti.xml'));
     //copy item.xml file to private directory
     tao_helpers_File::copy($itemFolder . 'qti.xml', $privateFolder . 'qti.xml', false);
     //copy client side resources (javascript loader)
     $qtiItemDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir();
     $taoDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getDir();
     $assetPath = $qtiItemDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR;
     $assetLibPath = $taoDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
     if (\tao_helpers_Mode::is('production')) {
         tao_helpers_File::copy($assetPath . 'qtiLoader.min.js', $publicDirectory . 'qtiLoader.min.js', false);
     } else {
         tao_helpers_File::copy($assetPath . 'qtiLoader.js', $publicDirectory . 'qtiLoader.js', false);
         tao_helpers_File::copy($assetLibPath . 'require.js', $publicDirectory . 'require.js', false);
     }
     //load item in php object :
     //warning:  use the same instance of php qti item because the serial is regenerated each time:
     $qtiItem = $qtiService->getDataItemByRdfItem($item, $language);
     //store variable qti elements data into the private directory
     $variableElements = $qtiService->getVariableElements($qtiItem);
     $serializedVariableElements = json_encode($variableElements);
     file_put_contents($privateFolder . 'variableElements.json', $serializedVariableElements);
     // render item
     $xhtml = $qtiService->renderQTIItem($qtiItem, $language);
     // retrieve external resources
     $report = taoItems_helpers_Deployment::retrieveExternalResources($xhtml, $publicDirectory);
     //@todo (optional) : exclude 'require.js' from copying
     if ($report->getType() == common_report_Report::TYPE_SUCCESS) {
         $xhtml = $report->getData();
     } else {
         return $report;
     }
     //note : no need to manually copy qti or other third party lib files, all dependencies are managed by requirejs
     // write index.html
     file_put_contents($publicDirectory . 'index.html', $xhtml);
     //copy the event.xml if not present
     $eventsXmlFile = $publicDirectory . 'events.xml';
     if (!file_exists($eventsXmlFile)) {
         $qtiItemDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir();
         $eventsReference = $qtiItemDir . 'model' . DIRECTORY_SEPARATOR . 'qti' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'events_ref.xml';
         $eventXml = file_get_contents($eventsReference);
         if (is_string($eventXml) && !empty($eventXml)) {
             $eventXml = str_replace('{ITEM_URI}', $item->getUri(), $eventXml);
             @file_put_contents($eventsXmlFile, $eventXml);
         }
     }
     // --- Include QTI specific compilation stuff here.
     // At this moment, we should have compiled raw Items. We now have
     // to put the qti.xml file for each language in the compilation folder.
     return new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Successfully compiled "%s"', $language));
 }
 /**
  * Desploy all the required files into the provided directories
  *
  * @param core_kernel_classes_Resource $item
  * @param string $language
  * @param tao_models_classes_service_StorageDirectory $publicDirectory
  * @param tao_models_classes_service_StorageDirectory $privateDirectory
  * @return common_report_Report
  */
 protected function deployQtiItem(core_kernel_classes_Resource $item, $language, tao_models_classes_service_StorageDirectory $publicDirectory, tao_models_classes_service_StorageDirectory $privateDirectory)
 {
     $itemService = taoItems_models_classes_ItemsService::singleton();
     $qtiService = Service::singleton();
     //copy item.xml file to private directory
     $itemDir = $itemService->getItemDirectory($item, $language);
     $sourceItem = $itemDir->getFile('qti.xml');
     $privateDirectory->writeStream($language . '/qti.xml', $sourceItem->readStream());
     //copy client side resources (javascript loader)
     $qtiItemDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir();
     $taoDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getDir();
     $assetPath = $qtiItemDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR;
     $assetLibPath = $taoDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
     if (\tao_helpers_Mode::is('production')) {
         $fh = fopen($assetPath . 'qtiLoader.min.js', 'r');
         $publicDirectory->writeStream($language . '/qtiLoader.min.js', $fh);
         fclose($fh);
     } else {
         $fh = fopen($assetPath . 'qtiLoader.js', 'r');
         $publicDirectory->writeStream($language . '/qtiLoader.js', $fh);
         fclose($fh);
         $fh = fopen($assetLibPath . 'require.js', 'r');
         $publicDirectory->writeStream($language . '/require.js', $fh);
         fclose($fh);
     }
     //  retrieve the media assets
     try {
         $qtiItem = $this->retrieveAssets($item, $language, $publicDirectory);
         //store variable qti elements data into the private directory
         $variableElements = $qtiService->getVariableElements($qtiItem);
         $stream = \GuzzleHttp\Psr7\stream_for(json_encode($variableElements));
         $privateDirectory->writePsrStream($language . '/variableElements.json', $stream);
         $stream->close();
         // render item based on the modified QtiItem
         $xhtml = $qtiService->renderQTIItem($qtiItem, $language);
         //note : no need to manually copy qti or other third party lib files, all dependencies are managed by requirejs
         // write index.html
         $stream = \GuzzleHttp\Psr7\stream_for($xhtml);
         $publicDirectory->writePsrStream($language . '/index.html', $stream, 'text/html');
         $stream->close();
         return new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Successfully compiled "%s"', $language));
     } catch (\tao_models_classes_FileNotFoundException $e) {
         return new common_report_Report(common_report_Report::TYPE_ERROR, __('Unable to retrieve asset "%s"', $e->getFilePath()));
     } catch (XIncludeException $e) {
         return new common_report_Report(common_report_Report::TYPE_ERROR, $e->getUserMessage());
     } catch (\Exception $e) {
         return new common_report_Report(common_report_Report::TYPE_ERROR, $e->getMessage());
     }
 }
echo json_encode(get_data('contentVariableElements'));
?>
,
                    userVars : <?php 
echo json_encode(get_data('js_variables'));
?>
,
                    customScripts : <?php 
echo json_encode(get_data('javascripts'));
?>
                };
            }());
        </script>

        <?php 
if (tao_helpers_Mode::is('production')) {
    ?>
            <script type="text/javascript" src="<?php 
    echo get_data('taoQtiItem_lib_path');
    ?>
qtiLoader.min.js"></script>
        <?php 
} else {
    ?>
            <script type="text/javascript" src="<?php 
    echo get_data('tao_lib_path');
    ?>
require.js" data-main="<?php 
    echo get_data('taoQtiItem_lib_path');
    ?>
qtiLoader"></script>
 /**
  * Build script element for AMD loader
  *
  * @return string
  */
 public static function getAmdLoader()
 {
     if (\common_session_SessionManager::isAnonymous()) {
         $amdLoader = array('src' => Template::js('lib/require.js', 'tao'), 'data-main' => TAOBASE_WWW . 'js/login', 'data-config' => get_data('client_config_url'));
     } else {
         if (\tao_helpers_Mode::is('production')) {
             $amdLoader = array('src' => Template::js('main.min.js', 'tao'), 'data-config' => get_data('client_config_url'));
         } else {
             $amdLoader = array('src' => Template::js('lib/require.js', 'tao'), 'data-config' => get_data('client_config_url'), 'data-main' => TAOBASE_WWW . 'js/main');
         }
     }
     $amdScript = '<script id="amd-loader" ';
     foreach ($amdLoader as $attr => $value) {
         $amdScript .= $attr . '="' . $value . '" ';
     }
     return trim($amdScript) . '></script>';
 }
 /**
  * Desploy all the required files into the provided directories
  *
  * @param core_kernel_classes_Resource $item
  * @param string $language
  * @param string $publicDirectory
  * @param string $privateFolder
  * @return common_report_Report
  */
 protected function deployQtiItem(core_kernel_classes_Resource $item, $language, $publicDirectory, $privateFolder)
 {
     //        start debugging here
     common_Logger::d('destination original ' . $publicDirectory . ' ' . $privateFolder);
     $itemService = taoItems_models_classes_ItemsService::singleton();
     $qtiService = Service::singleton();
     //copy item.xml file to private directory
     $itemFolder = $itemService->getItemFolder($item, $language);
     tao_helpers_File::copy($itemFolder . 'qti.xml', $privateFolder . 'qti.xml', false);
     //copy client side resources (javascript loader)
     $qtiItemDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir();
     $taoDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getDir();
     $assetPath = $qtiItemDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR;
     $assetLibPath = $taoDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR;
     if (\tao_helpers_Mode::is('production')) {
         tao_helpers_File::copy($assetPath . 'qtiLoader.min.js', $publicDirectory . 'qtiLoader.min.js', false);
     } else {
         tao_helpers_File::copy($assetPath . 'qtiLoader.js', $publicDirectory . 'qtiLoader.js', false);
         tao_helpers_File::copy($assetLibPath . 'require.js', $publicDirectory . 'require.js', false);
     }
     // retrieve the media assets
     try {
         $qtiItem = $this->retrieveAssets($item, $language, $publicDirectory);
         //store variable qti elements data into the private directory
         $variableElements = $qtiService->getVariableElements($qtiItem);
         $serializedVariableElements = json_encode($variableElements);
         file_put_contents($privateFolder . 'variableElements.json', $serializedVariableElements);
         // render item based on the modified QtiItem
         $xhtml = $qtiService->renderQTIItem($qtiItem, $language);
         //note : no need to manually copy qti or other third party lib files, all dependencies are managed by requirejs
         // write index.html
         file_put_contents($publicDirectory . 'index.html', $xhtml);
         return new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Successfully compiled "%s"', $language));
     } catch (\tao_models_classes_FileNotFoundException $e) {
         return new common_report_Report(common_report_Report::TYPE_ERROR, __('Unable to retrieve asset "%s"', $e->getFilePath()));
     }
 }
Beispiel #7
0
 /**
  * Create the AMD loader for the current context.
  * It will load login's modules for anonymous session.
  * Loads the bundle mode in production and the dynamic mode in debug.
  *
  * @param string $bundle the bundle URL
  * @param string $controller the controller module id
  * @param array  $params additional parameters
  * @return string the script tag
  */
 public static function getAmdLoader($bundle = null, $controller = null, $params = null)
 {
     $bundleMode = \tao_helpers_Mode::is('production');
     $configUrl = get_data('client_config_url');
     $requireJsUrl = Template::js('lib/require.js', 'tao');
     $bootstrapUrl = Template::js('loader/bootstrap', 'tao');
     $loader = new AmdLoader($configUrl, $requireJsUrl, $bootstrapUrl);
     if (\common_session_SessionManager::isAnonymous()) {
         $controller = 'controller/login';
         $bundle = Template::js('loader/login.min.js', 'tao');
     }
     if ($bundleMode) {
         return $loader->getBundleLoader($bundle, $controller, $params);
     }
     return $loader->getDynamicLoader($controller, $params);
 }