]> _ Git - odl.git/commitdiff
wip #4750 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Oct 2021 13:26:32 +0000 (15:26 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Oct 2021 13:26:32 +0000 (15:26 +0200)
app/Http/Controllers/Admin/MédiathèqueCrudController.php [deleted file]
app/Jobs/ProcessFluidbook.php
app/Models/Asset.php

diff --git a/app/Http/Controllers/Admin/MédiathèqueCrudController.php b/app/Http/Controllers/Admin/MédiathèqueCrudController.php
deleted file mode 100644 (file)
index bbf6242..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Admin;
-
-class MédiathèqueCrudController extends \Cubist\Backpack\Magic\Controllers\CubistMagicController
-{
-    use \Cubist\Backpack\Magic\Operations\CreateOperation;
-       use \Cubist\Backpack\Magic\Operations\UpdateOperation;
-       use \Cubist\Backpack\Http\Controllers\Operations\BulkPublishOperation;
-       use \Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation;
-       use \Backpack\CRUD\app\Http\Controllers\Operations\BulkCloneOperation;
-       use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
-       use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
-       use \Cubist\Backpack\Http\Controllers\Operations\ReviseOperation;
-       
-
-
-    /*
-       __('Element de la médiathèque')
-       __('Eléments de la médiathèque')
-       */
-
-    protected $_modelNamespace = 'App\Models\Asset';
-    protected $_routeURL = 'médiathèque';
-    protected $_singular = 'Element de la médiathèque';
-    protected $_plural = 'Eléments de la médiathèque';
-    protected $_oneInstance= false;
-}
index ce9ce170b61fc23d1170494a2d6237b821f514b7..31a15cf54cf05aa524713f5a72829b8b835fd885 100644 (file)
@@ -2,7 +2,9 @@
 
 namespace App\Jobs;
 
+use App\Models\Asset;
 use App\Models\Publication;
+use Cubist\Util\Files\Files;
 use Cubist\Util\Zip;
 use Fluidbook\Tools\Compiler\Compiler;
 use Spatie\MediaLibrary\MediaCollections\Models\Media;
@@ -34,8 +36,58 @@ class ProcessFluidbook extends Compiler
         $this->out = storage_path('fluidbook/out/');
     }
 
+    /**
+     * @param $id
+     * @return string
+     */
+    protected function _getAssetFile($id)
+    {
+        /** @var Asset $asset */
+        $asset = Asset::find($id);
+        $path = $asset->getMediaInField($asset->getAttributeValue('file_upload'))->first()->getPath();
+        $spl = new \SplFileInfo($path);
+        $fname = $spl->getFilename();
+        if (file_exists($path)) {
+            $dir = resource_path('fluidbook/working/');
+            Files::mkdir($dir);
+            copy($path, $dir . $fname);
+        }
+        return $fname;
+    }
+
     public function getLinks()
     {
-        return $this->getLinksFromPDF();
+        $links = $this->getLinksFromPDF();
+        $res = [];
+        foreach ($links as $k => $link) {
+            $e = explode(':', $link['to']);
+            if ($e[0] === 'pdf') {
+                $ee = explode('#', $e[1]);
+                $link['type'] = 16;
+                $link['to'] = $this->_getAssetFile($ee[0]);
+                $link['target'] = '_popupiframe';
+                $link['extras'] = 'page=' . ($ee[1] ?? 1);
+            } else if (stripos($e[0], 'video/') === 0) {
+                $link['type'] = 4;
+                $link['inline'] = $e[0] === 'video/inline';
+                $link['to'] = $this->_getAssetFile($e[1]);
+                if ($link['inline']) {
+                    $link['video_auto_start'] = false;
+                    $link['video_controls'] = true;
+                    $link['loop'] = false;
+                    $link['sound'] = true;
+                } else {
+                    $link['video_auto_start'] = true;
+                    $link['video_controls'] = true;
+                    $link['loop'] = false;
+                    $link['sound'] = true;
+                }
+            }
+            $res[$k] = $link;
+        }
+
+        return $res;
     }
+
+
 }
index c92561ba990e31c7e67adfec25ac2fe37efbc080..a85b68714e074aab1287fb0d8d2626ce5afd3ba6 100644 (file)
@@ -25,13 +25,16 @@ class Asset extends CubistMagicAbstractModel
 
         $this->addField('title', Text::class, 'Titre', ['column' => true]);
         $this->addField('type', SelectFromArray::class, 'Type',
-            ['options' => [
-                'image' => 'Image',
-                'inlinevideo' => 'Vidéo (intégrée à la page)',
-                'popupvideo' => 'Vidéo (popup)',
-                'pdf' => 'Document PDF',
-                'download' => 'Fichier à télécharger'],
-                'column' => true,
+            [
+                'options' =>
+                    [
+                        'image' => 'Image',
+                        'inlinevideo' => 'Vidéo (intégrée à la page)',
+                        'popupvideo' => 'Vidéo (popup)',
+                        'pdf' => 'Document PDF',
+                        //'download' => 'Fichier à télécharger'],
+                        'column' => true,
+                    ]
             ]);
         $this->addField('file_upload', Files::class, 'Fichier');
         $this->addField('keywords', Tags::class, 'Mots-clé', ['column' => true]);