]> _ Git - fluidbook-toolbox.git/commitdiff
wait #4891 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Nov 2021 10:40:16 +0000 (11:40 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Nov 2021 10:40:16 +0000 (11:40 +0100)
app/Models/FluidbookCollection.php

index c92b4acfe3348bcb489f3219c87336ede529deee..698b324e4a737449ba4386d6678f0ccb94b0b7e6 100644 (file)
@@ -10,6 +10,7 @@ use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
 use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
+use Cubist\Util\Files\Files;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\Auth;
 use function Symfony\Component\String\s;
@@ -58,6 +59,9 @@ class FluidbookCollection extends CubistMagicAbstractModel
     public function compile($path)
     {
         $data = $this->getPageData();
+
+        $path = Files::emptyDir($path);
+
         if ($data->type === 'scorm_multilang') {
             return $this->compileSCORMMultilang($data, $path);
         }
@@ -72,7 +76,6 @@ class FluidbookCollection extends CubistMagicAbstractModel
         $user = backpack_user();
         $ws->login($user->email, $user->api_token);
 
-        $first = true;
         $langs = [];
         foreach ($data->publications as $publication) {
             $fbid = $publication['fluidbook'];
@@ -80,11 +83,6 @@ class FluidbookCollection extends CubistMagicAbstractModel
             $langs[] = $metadata->lang;
             $dir = $path . '/' . $metadata->lang;
             $ws->installBook($fbid, $dir, 'scorm', 3);
-            if ($first) {
-                $first = false;
-                copy($dir . '/imsmanifest.xml', $path . '/imsmanifest.xml');
-            }
-            unlink($dir . '/imsmanifest.xml');
         }
 
         if (in_array('en', $langs)) {
@@ -93,6 +91,15 @@ class FluidbookCollection extends CubistMagicAbstractModel
             $default = $langs[0];
         }
 
+        foreach ($langs as $lang) {
+            $manifest = $path . '/' . $lang . '/imsmanifest.xml';
+            if ($lang === $default) {
+                rename($manifest, $path . '/imsmanifest.xml');
+            } else {
+                unlink($manifest);
+            }
+        }
+
         $redirectionScript = "<html>
 <head></head>
 <body>
@@ -135,11 +142,11 @@ function getLanguagesFromBrowser() {
 }
 
 var locale=guessPreferedLanguage(" . json_encode($langs) . ",'" . $default . "');
-window.location=\"./ + locale + /index.html\";
+window.location='./' + locale + '/index.html';
 </script>
 </body>
 </html>";
 
-        file_put_contents($path.'/index.html',$redirectionScript);
+        file_put_contents($path . '/index.html', $redirectionScript);
     }
 }