]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6524 @2.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 28 Nov 2023 12:18:49 +0000 (13:18 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 28 Nov 2023 12:18:49 +0000 (13:18 +0100)
app/Http/Controllers/Admin/Operations/FluidbookCollection/PreviewOperation.php
app/Jobs/FluidbookCollectionDownload.php
app/Models/FluidbookCollection.php

index 15247de26d5baabbede063e138151772c1c537c1..ad92dc9a985d2d900f64a94e62863bef623107fd 100644 (file)
@@ -73,7 +73,7 @@ trait PreviewOperation
 
         $isScorm = $version === 'scorm';
 
-        $dest = $collection->getFinalPath($theme, $isScorm);
+        $dest = $collection->getFinalPath() . $collection->type . '/online';
         if ($path === 'index.html') {
             $collection->incrementPreviewVisit();
             $compiler = new FluidbookCollectionDownload($collection, 'export', backpack_user());
@@ -104,7 +104,7 @@ trait PreviewOperation
             abort(404);
         }
         foreach ($collection->publications as $pub) {
-            $fluidbook = FluidbookPublication::withoutGlobalScopes()->find( $pub['fluidbook']);
+            $fluidbook = FluidbookPublication::withoutGlobalScopes()->find($pub['fluidbook']);
             if (null === $fluidbook) {
                 continue;
             }
index 6829c83d67f284fd89105fe30fdf85c5e3bb0a67..d9536b9211b0cbed6c6ac469f846a513c02a2281 100644 (file)
@@ -75,38 +75,31 @@ class FluidbookCollectionDownload extends DownloadBase
 
     protected function _compile()
     {
-        $compilepath = $this->entry->getFinalPath();
-        $this->compile($compilepath, true);
-        return $compilepath;
+        return $this->compile();
     }
 
     /**
      * @param $path
-     * @return void
+     * @return string
      * @throws \Exception
      */
-    public function compile($path, $empty = true)
+    public function compile($forceVersion = null)
     {
         $data = $this->entry->getPageData();
-        if ($empty) {
-            $path = Files::emptyDir($path);
-        }
 
         PHP::neverStop();
         if ($data->type === 'scorm_multilang') {
-            $this->compileMultilang($data, $path, true);
+            return $this->compileMultilang('scorm');
         } else if ($data->type === 'export_multilang') {
-            $this->compileMultilang($data, $path, false);
+            return $this->compileMultilang($forceVersion);
         } elseif ($data->type === 'export') {
-            $this->compileExport($data, $path);
+            return $this->compileExport();
         }
     }
 
     public function compilePreview()
     {
-        $compilepath = $this->entry->getFinalPath();
-        $this->compile($compilepath, false);
-        return $compilepath;
+        return $this->compile('online');
     }
 
     protected function getCollectionGlobalSettings()
@@ -125,12 +118,17 @@ class FluidbookCollectionDownload extends DownloadBase
     /**
      * @param $data PageData
      * @param $path string
-     * @return void
+     * @return string
      * @throws \Exception
      */
-    protected function compileMultilang($data, $path, $scorm = false)
+    protected function compileMultilang($version = null)
     {
+        $data = $this->entry->getPageData();
         $optionsFluidbooks = [];
+        if (null === $version) {
+            $version = $version ?? $data->version_multilang;
+        }
+        $basePath = Files::mkdir($this->entry->getFinalPath() . $data->type . '/' . $version);
 
         foreach ($data->publications as $publication) {
             $fbid = $publication['fluidbook'];
@@ -145,7 +143,7 @@ class FluidbookCollectionDownload extends DownloadBase
         $multipleDevices = count(array_unique($this->devices)) > 1;
 
         $options = $this->getCollectionGlobalSettings();
-        $options['scorm_enable'] = $scorm;
+        $options['scorm_enable'] = $version === 'scorm';
         // We don't want an hybrid fluidbook in a collection
         $options['mobilefirstFluidbookId'] = '';
 
@@ -198,7 +196,7 @@ class FluidbookCollectionDownload extends DownloadBase
                 $fbOptions += $optionsFluidbooks[$fbid];
             }
 
-            $jobs[] = $this->_jobDownloadFluidbook($fbid, $scorm ? 'scorm' : 'online', $path . $this->dirs[$fbid], $fbOptions);
+            $jobs[] = $this->_jobDownloadFluidbook($fbid, $version, $basePath . $this->dirs[$fbid], $fbOptions);
         }
         $this->_waitJobs($jobs);
 
@@ -208,10 +206,10 @@ class FluidbookCollectionDownload extends DownloadBase
             $default = $this->langs[0] ?? 'en';
         }
 
-        if ($scorm) {
-            $manifestFile = $path . 'imsmanifest.xml';
+        if ($version === 'scorm') {
+            $manifestFile = $basePath . 'imsmanifest.xml';
             foreach ($allVersions as $k => $dir) {
-                $manifest = $path . $dir . '/imsmanifest.xml';
+                $manifest = $basePath . $dir . '/imsmanifest.xml';
                 if ($k === 0) {
                     rename($manifest, $manifestFile);
                 } else if (file_exists($manifest)) {
@@ -224,17 +222,21 @@ class FluidbookCollectionDownload extends DownloadBase
             file_put_contents($manifestFile, $manifestContent);
         }
 
+        $ext = $version === 'sharepoint' ? 'aspx' : 'html';
+
         if ($multipleDevices) {
             if ($data->redirection_algorithm === 'language') {
-                $redirectScript = self::getMultiDevicesRedirectScript($versionsByLanguage, $default, $data->redirection_algorithm);
+                $redirectScript = self::getMultiDevicesRedirectScript($versionsByLanguage, $default, $data->redirection_algorithm, $ext);
             } else {
-                $redirectScript = self::getMultiDevicesRedirectScript($versionsByDevice, $default, $data->redirection_algorithm);
+                $redirectScript = self::getMultiDevicesRedirectScript($versionsByDevice, $default, $data->redirection_algorithm, $ext);
             }
         } else {
-            $redirectScript = self::getRedirectScript($versionsByLanguage, $default);
+            $redirectScript = self::getRedirectScript($versionsByLanguage, $default, $ext);
         }
 
-        file_put_contents($path . '/index.html', $redirectScript);
+
+        file_put_contents($basePath . '/index.' . $ext, $redirectScript);
+        return $basePath;
     }
 
 
@@ -277,7 +279,7 @@ class FluidbookCollectionDownload extends DownloadBase
 
     protected function _getMultilangOptions($fluidbooks)
     {
-        $defaultFlags = ['en' => 'gb', 'sv' => 'se', 'zh' => 'cn', 'el' => 'gr', 'ja' => 'jp', 'ko' => 'kr'];
+        $defaultFlags = ['en' => 'gb', 'sv' => 'se', 'zh' => 'cn', 'el' => 'gr', 'ja' => 'jp', 'ko' => 'kr', 'vi' => 'vn', 'cs' => 'cz'];
 
         $multilang = [];
         foreach ($fluidbooks as $fbid => $publication) {
@@ -404,11 +406,13 @@ class FluidbookCollectionDownload extends DownloadBase
     /**
      * @param $data PageData
      * @param $path string
-     * @return void
+     * @return string
      * @throws \Exception
      */
-    protected function compileExport($data, $basePath)
+    protected function compileExport($data)
     {
+        $data = $this->entry->getPageData();
+        $basePath = Files::mkdir($this->entry->getFinalPath() . $data->type . '/' . $data->version);
         $options = $this->getCollectionGlobalSettings();
 
         $jobs = [];
@@ -419,6 +423,7 @@ class FluidbookCollectionDownload extends DownloadBase
         }
 
         $this->_waitJobs($jobs);
+        return $basePath;
     }
 
     protected function getPublicationsPaths($data, $attr = 'dir')
@@ -441,17 +446,17 @@ class FluidbookCollectionDownload extends DownloadBase
     }
 
 
-    public static function getRedirectScript($versions, $default = 'en')
+    public static function getRedirectScript($versions, $default = 'en', $ext = 'html')
     {
-        return self::_getRedirectScript("var dir=guessPreferredLanguageVersion(" . json_encode($versions) . ",'" . $default . "');");
+        return self::_getRedirectScript("var dir=guessPreferredLanguageVersion(" . json_encode($versions) . ",'" . $default . "');", $ext);
     }
 
-    public static function getMultiDevicesRedirectScript($versions, $default = 'en', $priority = 'language')
+    public static function getMultiDevicesRedirectScript($versions, $default = 'en', $priority = 'language', $ext = 'html')
     {
-        return self::_getRedirectScript("var dir=guessPreferredVersion('" . $priority . "'," . json_encode($versions) . ",'" . $default . "');");
+        return self::_getRedirectScript("var dir=guessPreferredVersion('" . $priority . "'," . json_encode($versions) . ",'" . $default . "');", $ext);
     }
 
-    protected static function _getRedirectScript($code)
+    protected static function _getRedirectScript($code, $ext = 'html')
     {
         return "<html>
 <head></head>
@@ -529,7 +534,7 @@ function getLanguagesFromBrowser() {
 }
 
 $code
-window.location='./' + dir + '/index.html';
+window.location='./' + dir + '/index." . $ext . "';
 </script>
 </body>
 </html>";
index fa4a74be16883ed1dd2c02041f70278e9bef16a0..4eb36035af41a72ec4aea902306c9cecf2e146cc 100644 (file)
@@ -74,6 +74,8 @@ class FluidbookCollection extends ToolboxStatusModel
             ]
         );
         $this->addField('version', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export']]);
+        $excluded = array_diff(array_keys(FluidbookExportVersion::getVersions()), ['online', 'sharepoint']);
+        $this->addField('version_multilang', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export_multilang'], 'excluded_options' => $excluded, 'default' => 'online']);
         $this->addField('publications', BunchOfFieldsMultiple::class, __('Publications'), ['bunch' => CollectionPublication::class, 'edit_label' => '%fluidbook > %dir']);
         $this->addField('install', ExternalPath::class, 'Installer sur un serveur externe', ['default' => '', 'fake' => true, 'translatable' => false, 'store_in' => 'settings', 'servers_model' => FluidbookExternalInstallServer::class, ['when' => ['type' => ['export', 'export_multilang']]]]);
         $this->addField('override_settings', BunchOfFieldsMultiple::class, __('Redéfinir les paramètres lors de l\'export'), ['bunch' => Fluidbook_Setting::class]);
@@ -96,7 +98,7 @@ class FluidbookCollection extends ToolboxStatusModel
         return $res;
     }
 
-    public function getFinalPath()
+    public function getFinalPath($type = null, $version = null)
     {
         return Files::mkdir(protected_path('fluidbookcollection/final/' . $this->id));
     }