]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5840 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 30 Mar 2023 14:45:12 +0000 (16:45 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 30 Mar 2023 14:45:12 +0000 (16:45 +0200)
app/Console/Commands/FluidbookCollection.php
app/Jobs/DownloadBase.php
app/Jobs/FluidbookCollectionDownload.php
app/Models/FluidbookCollection.php
resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php

index 4ae7550ffd38b9a494484e158dcd6c73126fa274..ce8aa4d0aa5a16b193afd83eb3c63b6aa705b06b 100644 (file)
@@ -19,8 +19,8 @@ class FluidbookCollection extends CubistCommand
     public function handle()
     {
         PHP::neverStop(true);
-        $fluidbook = \App\Models\FluidbookCollection::find($this->argument('id'));
-        $job = new FluidbookCollectionDownload($fluidbook, $this->argument('action'), User::withoutGlobalScope('ownerclause')->findOrFail(5));
+        $collection = \App\Models\FluidbookCollection::find($this->argument('id'));
+        $job = new FluidbookCollectionDownload($collection, $this->argument('action'), User::withoutGlobalScope('ownerclause')->findOrFail(5));
         $job->handle();
     }
 }
index 28015d768c8c907150f7ab66a81c3246bdf0dc88..365f12b68de4c188d3a47553afa8226905bf310e 100644 (file)
@@ -52,19 +52,9 @@ class DownloadBase extends Base
         $this->action = $action;
     }
 
-    public function sendNotification($subject, $text, $actions = [])
+    public function sendNotification($subject, $text, $actions = [], $showTextIfNotEmail = false)
     {
-        $this->getUser()->notify(new DownloadReady($subject, $text, $actions));
-//
-//
-//        if ($this->getUser()->slack) {
-//            if ($this->sendSlack($subject, $text, $actions)) {
-//                return;
-//            }
-//        }
-//
-//        // Fallback email if
-//        $this->sendEmail($subject, $text, $actions);
+        $this->getUser()->notify(new DownloadReady($subject, $text, $actions, $showTextIfNotEmail));
     }
 
     public function sendSlack($subject, $text, $actions = [])
index 7713aada99312a79c7367376e1826846040c7819..0ad90dde9fffdd54b7231f7562fbed4a2b3d916a 100644 (file)
@@ -6,6 +6,7 @@ use App\Fluidbook\Packager\Packager;
 use App\Models\FluidbookPublication;
 use App\Models\User;
 use App\Services\WorkshopV2;
+use Cubist\Backpack\Magic\PageData;
 use Cubist\Util\CommandLine\Rsync;
 use Cubist\Util\Files\Files;
 use Cubist\Util\PHP;
@@ -45,6 +46,8 @@ class FluidbookCollectionDownload extends DownloadBase
     }
 
     /**
+     * @param $path
+     * @return null
      * @throws \Exception
      */
     public function compile($path)
@@ -67,7 +70,7 @@ class FluidbookCollectionDownload extends DownloadBase
     {
         $options = [];
         foreach ($this->entry->getPageData()->override_settings as $setting) {
-            if (!$setting['key']) {
+            if (!$setting || !isset($setting['key']) || !$setting['key']) {
                 continue;
             }
             $options[$setting['key']] = $setting['value'];
@@ -77,14 +80,98 @@ class FluidbookCollectionDownload extends DownloadBase
     }
 
     /**
+     * @param $data PageData
+     * @param $path string
+     * @return void
      * @throws \Exception
      */
+
     protected function compileSCORMMultilang($data, $path)
     {
-        return $this->compileSCORM($data, $path, true);
+        $ws = $this->_getws2();
+        $langs = [];
+        $countries = [];
+
+        $defaultFlags = ['en' => 'gb', 'sv' => 'se'];
+
+        foreach ($data->publications as $publication) {
+            $fbid = $publication['fluidbook'];
+            $metadata = $ws->getMetadata($fbid);
+            $langs[$fbid] = $metadata->lang;
+            $countries[$fbid] = $metadata->settings->country;
+        }
+
+        $options = $this->getCollectionGlobalSettings();
+        $options['scorm_enable'] = true;
+
+
+        if (count($data->publications) >= 2) {
+            if ($data->locale_switch) {
+                $multilang = [];
+                foreach ($langs as $fbid => $lang) {
+                    if ($countries[$fbid]) {
+                        $flag = $countries[$fbid];
+                    } else {
+                        if (strlen($lang) === 5) {
+                            $flag = substr($lang, 3, 2);
+                        } else if (isset($defaultFlags[$lang])) {
+                            $flag = $defaultFlags[$lang];
+                        } else {
+                            $flag = $lang;
+                        }
+                    }
+                    $multilang[] = $lang . ',' . strtolower($flag) . ',../' . $lang . '/index.html';
+                }
+                $options['multilang'] = implode("\n", $multilang);
+                $options['multilangDisplay'] = 'lang';
+            } else {
+                $options['multilang'] = '';
+            }
+
+            foreach ($data->publications as $publication) {
+                $fbid = $publication['fluidbook'];
+                $lang = $langs[$fbid];
+                $dir = $path . '/' . $lang;
+                $ws->installBook($fbid, $dir, $options, 'scorm', 3);
+            }
+
+            if (in_array('en', $langs)) {
+                $default = 'en';
+            } else {
+                $default = $langs[0];
+            }
+
+            $manifestFile = $path . '/imsmanifest.xml';
+            foreach ($langs as $lang) {
+                $manifest = $path . '/' . $lang . '/imsmanifest.xml';
+                if ($lang === $default) {
+                    rename($manifest, $manifestFile);
+                } else if (file_exists($manifest)) {
+                    unlink($manifest);
+                }
+            }
+
+            $manifestContent = file_get_contents($manifestFile);
+            $manifestContent = preg_replace('/\<title\>(.*)\<\/title\>/U', '<title>' . htmlspecialchars($this->entry->title) . '</title>', $manifestContent);
+            file_put_contents($manifestFile, $manifestContent);
+
+            $redirectionScript = self::getRedirectScript($langs, $default);
+
+            file_put_contents($path . '/index.html', $redirectionScript);
+        } else {
+            foreach ($data->publications as $publication) {
+                $fbid = $publication['fluidbook'];
+                $dir = $path;
+                $ws->installBook($fbid, $dir, $options, 'scorm', 3);
+                break;
+            }
+        }
     }
 
     /**
+     * @param $data PageData
+     * @param $path string
+     * @return void
      * @throws \Exception
      */
     protected function compileMultilang($data, $path, $scorm = false)
@@ -229,6 +316,19 @@ class FluidbookCollectionDownload extends DownloadBase
         return $done === $nbjobs;
     }
 
+    protected function _getws2()
+    {
+        $ws = new WorkshopV2();
+        $ws->login($this->user->email, $this->user->api_token);
+        return $ws;
+    }
+
+    /**
+     * @param $data PageData
+     * @param $path string
+     * @return void
+     * @throws \Exception
+     */
     protected function compileExport($data, $path)
     {
         $ws = $this->_getws2();
index 61932e830360f4b82d29c1a113630d9c754f65e0..c48efe4451c4700779670b5a09759cb86a120221 100644 (file)
@@ -37,7 +37,7 @@ class FluidbookCollection extends ToolboxModel
         $this->addField('locale_switch', Checkbox::class, __('Permettre le changement de langue'), ['when' => ['type' => ['scorm_multilang', 'export_multilang']], 'default' => true]);
         $this->addField('version', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export']]);
         $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]);
+        $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]);
     }
 
index 5cd9b455044608c56c76ddde11e667d8fea95429..cca55965e8a18584488b1991dc3185aa93e85429 100644 (file)
@@ -1,21 +1,26 @@
 {{-- __('!! Collections de fluidbooks') --}}
 @php
-    $v=$entry->version?:'online';
-    $servers=\App\Models\FluidbookExternalInstallServer::getAllServers();
-    $vname=\App\Fields\FluidbookExportVersion::getVersions()[$v]['short'];
-    $actions=['download'=>__('Télécharger la version :version',['version'=>$vname])];
 
-    if($entry->install && $entry->install->server && isset($servers[$entry->install->server])){
-        $server=$servers[$entry->install->server];
-        if($entry->install->path || $server['allows_root']){
-            $actions['install']=[
-                'label'=>__('Installer sur le serveur :server',['server'=>'<strong>'.$server['name'].'</strong>']).' <span class="small"><span class="grey">'.$server['base_url'].'</span>'.$entry->install->path.'</span>',
-            ];
-        }
-    }
-
-    if($entry->type==='scorm_multilang'){
+    if($entry->type==='export'){
+        $v=$entry->version?:'online';
+        $vname=\App\Fields\FluidbookExportVersion::getVersions()[$v]['short'];
+        $actions=['export'=>__('Télécharger la version :version',['version'=>$vname])];
+    }else if($entry->type==='scorm_multilang'){
+        $actions['export']=__('Télécharger');
         $actions['scormcloud']=__('Tester sur Scorm Cloud');
+    }else if($entry->type==='export_multilang'){
+        $actions['export']=__('Télécharger');
+    }
+    if($entry->type==='export' || $entry->type==='export_multilang'){
+        $servers=\App\Models\FluidbookExternalInstallServer::getAllServers();
+         if($entry->install && $entry->install->server && isset($servers[$entry->install->server])){
+            $server=$servers[$entry->install->server];
+            if($entry->install->path || $server['allows_root']){
+                $actions['install']=[
+                    'label'=>__('Installer sur le serveur :server',['server'=>'<strong>'.$server['name'].'</strong>']).' <span class="small"><span class="grey">'.$server['base_url'].'</span>'.$entry->install->path.'</span>',
+                ];
+            }
+        }
     }
 @endphp
 <a class="btn btn-sm btn-link exportcollection" href="#"