]> _ Git - fluidbook-toolbox.git/commitdiff
wait #4949 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 8 Dec 2021 17:53:38 +0000 (18:53 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 8 Dec 2021 17:53:38 +0000 (18:53 +0100)
app/Jobs/FluidbookCollectionDownload.php
app/Models/FluidbookCollection.php
app/SubForms/Fluidbook_Setting.php [new file with mode: 0644]

index 101c63300166a08c82423c495a2f9b9af5812683..0dc3483733efd1fd065e858e4b1fa3d466a084f1 100644 (file)
@@ -39,6 +39,7 @@ class FluidbookCollectionDownload implements ShouldQueue
      */
     protected $action;
 
+
     /**
      * @param $collection FluidbookCollection
      * @param $user User
@@ -71,13 +72,18 @@ class FluidbookCollectionDownload implements ShouldQueue
 
             $url = url('storage/collection/download/' . $fname);
 
-            $subject = __('Collection :nb prête au téléchargement', ['nb' => $this->collection->id]);
+            $subject = __('Collection ":title" (#:nb) prête au téléchargement', ['title' => $this->collection->title, 'nb' => $this->collection->id]);
             $body = __('Le fichier est disponible à l\'adresse suivante : <a href=":url">:url</a>', ['url' => $url]);
 
-            if ($this->action === 'scormcloud') {
-                $scormURL = $this->sendToSCORMCloud($url);
+            try {
+                if ($this->action === 'scormcloud') {
+                    $scormURL = $this->sendToSCORMCloud($dest);
+                    $body .= "<br><br>";
+                    $body .= __('La collection peut être testée sur SCORM Cloud : <a href=":url">:url</a>', ['url' => $scormURL]);
+                }
+            } catch (\Exception $e) {
                 $body .= "<br><br>";
-                $body .= __('La collection peut être testée sur SCORM Cloud : <a href=":url">:url</a>', ['url' => $scormURL]);
+                $body .= __('Une erreur s\'est produite lors de l\'envoi sur SCORM Cloud : :error', ['error' => $e->getMessage()]);
             }
 
 
@@ -119,6 +125,18 @@ class FluidbookCollectionDownload implements ShouldQueue
         return $ws;
     }
 
+    protected function getCollectionGlobalSettings()
+    {
+
+        $options = [];
+        foreach ($this->collection->getPageData()->override_settings as $setting) {
+            $options[$setting['key']] = $setting['value'];
+        }
+
+        return $options;
+    }
+
+
     /**
      * @throws \Exception
      */
@@ -137,8 +155,7 @@ class FluidbookCollectionDownload implements ShouldQueue
             $countries[$fbid] = $metadata->settings->country;
         }
 
-
-        $options = [];
+        $options = $this->getCollectionGlobalSettings();
 
         if ($data->locale_switch) {
             $multilang = [];
@@ -185,9 +202,9 @@ class FluidbookCollectionDownload implements ShouldQueue
             }
         }
 
-        $manifestContent=file_get_contents($manifestFile);
-        $manifestContent=preg_replace('/\<title\>(.*)\<\/title\>/U','<title>'.htmlspecialchars($this->collection->title).'</title>',$manifestContent);
-        file_put_contents($manifestFile,$manifestContent);
+        $manifestContent = file_get_contents($manifestFile);
+        $manifestContent = preg_replace('/\<title\>(.*)\<\/title\>/U', '<title>' . htmlspecialchars($this->collection->title) . '</title>', $manifestContent);
+        file_put_contents($manifestFile, $manifestContent);
 
         $redirectionScript = "<html>
 <head></head>
@@ -243,7 +260,7 @@ window.location='./' + locale + '/index.html';
     {
         $ws = $this->_getws2();
 
-        $options = [];
+        $options = $this->getCollectionGlobalSettings();
 
         $zipmerge = in_array($data->version, ['online', 'scorm', 'sharepoint', 'precompiled', 'win_exe_html', 'win_html', 'win_cd_html', 'mac_exe_html']);
         foreach ($data->publications as $publication) {
@@ -267,7 +284,7 @@ window.location='./' + locale + '/index.html';
         }
     }
 
-    public function sendToSCORMCloud($url)
+    public function sendToSCORMCloud($file)
     {
         $config = new ScormCloud\Configuration();
         $appId = env('SCORM_CLOUD_APP_ID');
@@ -277,28 +294,20 @@ window.location='./' + locale + '/index.html';
 
         $courseId = 'toolbox_collection_' . $this->collection->getKey();
         $courseAPI = new ScormCloud\Api\CourseApi();
-        $request = new ScormCloud\Model\ImportFetchRequestSchema(['url' => $url, 'content_type' => 'application/zip', 'media_file_metadata' => ['title' => $this->collection->title]]);
-        while (true) {
-            try {
-                $jobId = $courseAPI->createFetchAndImportCourseJob($courseId, $request, true);
-                break;
-            } catch (\Exception $e) {
-                sleep(1);
-            }
+
+        try {
+            $courseAPI->deleteCourse($courseId);
+        } catch (\Exception $e) {
+
         }
 
-        while (true) {
-            try {
-                $jobResult = $courseAPI->getImportJobStatus($jobId->getResult());
+        $jobId = $courseAPI->createUploadAndImportCourseJob($courseId, true, null, 'application/zip', null, new \SplFileObject($file));
 
-                if ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_RUNNING) {
-                    sleep(1);
-                } else {
-                    break;
-                }
-            } catch (\Exception $e) {
-                sleep(1);
-            }
+
+        $jobResult = $courseAPI->getImportJobStatus($jobId->getResult());
+        while ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_RUNNING) {
+            sleep(1);
+            $jobResult = $courseAPI->getImportJobStatus($jobId->getResult());
         }
 
         if ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_ERROR)
index 3ee1f578e26b8538d2a274142fc7758f692d62b1..965f48b8d8950c897c8ea006bc836d31a5492a55 100644 (file)
@@ -6,6 +6,7 @@ use App\Fields\FluidbookExportVersion;
 use App\Fields\User;
 use App\Http\Controllers\Admin\Operations\FluidbookCollection\DownloadOperation;
 use App\SubForms\CollectionPublication;
+use App\SubForms\Fluidbook_Setting;
 use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple;
 use Cubist\Backpack\Magic\Fields\Checkbox;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
@@ -54,6 +55,7 @@ class FluidbookCollection extends CubistMagicAbstractModel
         $this->addField('locale_switch', Checkbox::class, __('Permettre le changement de langue'), ['when' => ['type' => 'scorm_multilang'], 'default' => true]);
         $this->addField('version', FluidbookExportVersion::class, __('Version'), ['when' => ['type' => 'export']]);
         $this->addField('publications', BunchOfFieldsMultiple::class, __('Publications'), ['bunch' => CollectionPublication::class]);
+        $this->addField('override_settings',BunchOfFieldsMultiple::class,__('Redéfinir les paramètres lors de l\'export'),['bunch'=>Fluidbook_Setting::class]);
     }
 
 
diff --git a/app/SubForms/Fluidbook_Setting.php b/app/SubForms/Fluidbook_Setting.php
new file mode 100644 (file)
index 0000000..5b25ddc
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\SubForms;
+
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\Fields\Textarea;
+use Cubist\Backpack\Magic\SubForm;
+
+class Fluidbook_Setting extends SubForm
+{
+    public function init()
+    {
+        parent::init();
+        $this->addField('key', Text::class, __('Nom du paramètre'));
+        $this->addField('value', Textarea::class, __('Valeur'));
+    }
+}