]> _ Git - fluidbook-toolbox.git/commitdiff
wait #4928 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 Dec 2021 13:04:22 +0000 (14:04 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 Dec 2021 13:04:22 +0000 (14:04 +0100)
app/Http/Controllers/Admin/Operations/FluidbookCollection/DownloadOperation.php
app/Jobs/FluidbookCollectionDownload.php
resources/views/vendor/backpack/crud/buttons/fluidbook_collection/download.blade.php

index eb3469ef63b17b0b933a4ca9d19f6e89eaabfe9a..789e8b87e34c6d127b414b125753aca2df04dc7d 100644 (file)
@@ -11,7 +11,7 @@ trait DownloadOperation
 {
     protected function setupDownloadRoutes($segment, $routeName, $controller)
     {
-        Route::match(['get'], $segment . '/{id}/download', $controller . '@download');
+        Route::match(['get'], $segment . '/{id}/download/{action}', $controller . '@download');
     }
 
     protected function setupDownloadDefaults()
@@ -19,9 +19,9 @@ trait DownloadOperation
         $this->crud->addButtonFromView('line', 'download', 'fluidbook_collection.download', 'end');
     }
 
-    protected function download($id)
+    protected function download($id, $action)
     {
-        FluidbookCollectionDownload::dispatch(FluidbookCollection::find($id), backpack_user());
+        FluidbookCollectionDownload::dispatch(FluidbookCollection::find($id), $action, backpack_user());
         Alert::add('success', __('La compilation a été placée en file d\'attente. Vous recevrez un email lorsqu\'elle sera terminée.'))->flash();
         return redirect(backpack_url('fluidbook-collection'));
     }
index 761010351cbce47dcb634880037ce9ff893b155a..1d73b1909a8b48eb2d9b0b8a0ab9477b59521aeb 100644 (file)
@@ -15,6 +15,9 @@ use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
 use Illuminate\Support\Facades\Mail;
+use InvalidArgumentException;
+use RusticiSoftware\Cloud\V2 as ScormCloud;
+
 
 class FluidbookCollectionDownload implements ShouldQueue
 {
@@ -30,13 +33,20 @@ class FluidbookCollectionDownload implements ShouldQueue
      */
     protected $user;
 
+
+    /**
+     * @var string
+     */
+    protected $action;
+
     /**
      * @param $collection FluidbookCollection
      * @param $user User
      */
-    public function __construct($collection, $user)
+    public function __construct($collection, $action, $user)
     {
         $this->collection = $collection;
+        $this->action = $action;
         $this->user = $user;
 
     }
@@ -63,6 +73,14 @@ class FluidbookCollectionDownload implements ShouldQueue
 
             $subject = __('Collection :nb prête au téléchargement', ['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);
+                $body .= "\n\n";
+                $body .= __('La collection peut être testée sur SCORM Cloud : <a href=":url">:url</a>', ['url' => $scormURL]);
+            }
+
+
         } catch (\Exception $e) {
             $subject = __('Erreur lors de la compilation de la collection :nb', ['nb' => $this->collection->id]);
             $body = __('Détails de l\'erreur :message', ['message' => $e->getMessage() . ' at line ' . $e->getLine() . ' of ' . $e->getFile()]);
@@ -243,4 +261,45 @@ window.location='./' + locale + '/index.html';
             }
         }
     }
+
+    public function sendToSCORMCloud($url)
+    {
+        $config = new ScormCloud\Configuration();
+        $appId = env('SCORM_CLOUD_APP_ID');
+        $config->setUsername($appId);
+        $config->setPassword(env('SCORM_CLOUD_SECRET_KEY'));
+        ScormCloud\Configuration::setDefaultConfiguration($config);
+
+
+        $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);
+            }
+        }
+
+        while (true) {
+            try {
+                $jobResult = $courseAPI->getImportJobStatus($jobId->getResult());
+
+                if ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_RUNNING) {
+                    sleep(1);
+                } else {
+                    break;
+                }
+            } catch (\Exception $e) {
+                sleep(1);
+            }
+        }
+
+        if ($jobResult->getStatus() == ScormCloud\Model\ImportJobResultSchema::STATUS_ERROR)
+            throw new InvalidArgumentException('Course is not properly formatted: ' . $jobResult->getMessage());
+
+        return 'https://cloud.scorm.com/sc/user/Course?appId=' . $appId . '&courseId=' . $courseId;
+    }
 }
index 7507f65167aa0e3356899ace776abdfccd1acc88..5e94a06e023110f2992e950c5feeadaab643f26a 100644 (file)
@@ -1,2 +1,54 @@
-<a class="btn btn-sm btn-link" href="{{$crud->route}}/{{$entry->getKey()}}/download" data-toggle="tooltip"
-   title="{{__('Télécharger la collection')}}"><i class="la la-arrow-circle-down"></i> {{__('Télécharger')}}</a>
+@once
+@php
+$showjs=false;
+if($crud->getValue('seenExportJS')===null){
+$showjs =true;
+$crud->setValue('seenExportJS',true);
+}
+@endphp
+@if($showjs)
+<style>
+    a.exportcollection {
+        position: relative;
+    }
+
+    a.exportcollection select {
+        opacity: 0;
+        width: 100%;
+        height: 100%;
+        position: absolute;
+        top: 0;
+        left: 0;
+        cursor: pointer;
+    }
+</style>
+<script>
+    jQuery(document).ready(function ($) {
+        $('a.exportcollection').on('click', function () {
+            return false;
+        });
+        $('a.exportcollection select').on('change', function () {
+            var val = $(this).val();
+            if (val <= 0 || val == null || val == 'null') {
+                return;
+            }
+            var id = $(this).data('id');
+            window.location = $(this).data('route') + "/" + id + "/download/" + val;
+        });
+    });
+</script>
+@endif
+@endonce
+
+<a class="btn btn-sm btn-link exportcollection" href="#"
+   data-toggle="tooltip"
+   title="{{__('Exporter la collection')}}"><i class="la la-arrow-circle-down"></i> {{__('Exporter')}}
+    <select data-route="{{$crud->route}}" data-id="{{$entry->getKey()}}">
+        <option value="" selected style="display: none">--</option>
+        <option value="download">{{__('Télécharger')}}</option>
+        @if($entry->type==='scorm_multilang')
+        <option value="scormcloud">{{__('Tester sur Scorm Cloud')}}</option>
+        @endif
+    </select>
+</a>
+