]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5045 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 21 Jan 2022 17:33:11 +0000 (18:33 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 21 Jan 2022 17:33:11 +0000 (18:33 +0100)
app/Http/Controllers/Admin/Operations/ELearningMedia/ImportOperation.php [new file with mode: 0644]
app/Models/ELearningMedia.php
composer.lock

diff --git a/app/Http/Controllers/Admin/Operations/ELearningMedia/ImportOperation.php b/app/Http/Controllers/Admin/Operations/ELearningMedia/ImportOperation.php
new file mode 100644 (file)
index 0000000..43a3713
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Operations\ELearningMedia;
+
+use App\Models\Asset;
+use App\Models\ELearningMedia;
+use Prologue\Alerts\Facades\Alert;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+trait ImportOperation
+{
+    use \Cubist\Backpack\Http\Controllers\Operations\Base\ImportOperation;
+
+    protected $_importAccept = ELearningMedia::MEDIA_TYPES;
+
+    /**
+     * @param UploadedFile[] $files
+     * @return void
+     */
+    function importFromFiles($files)
+    {
+        if (!count($files)) {
+            Alert::warning(__('Aucun fichier n\'a été chargé'))->flash();
+            return;
+        }
+
+        $importedFile = 0;
+        foreach ($files as $file) {
+            $name = $file->getClientOriginalName();
+            $e = explode('.', $name);
+            $ext = mb_strtolower(array_pop($e));
+
+            $media = new ELearningMedia();
+            $media->title = $file->getBasename('.' . $ext);
+            $media->owner = backpack_user()->id;
+            $media->addMediaToField('file', $file);
+            $media->save();
+
+            $importedFile++;
+        }
+        if ($importedFile === 0) {
+            Alert::warning(__('Aucun média importé'))->flash();
+        } else {
+            Alert::success('<b>' . $importedFile . ' média</b> crées')->flash();
+        }
+    }
+}
index a1971ac561588b6e3dc6e115e4bf50c9827bff76..adb76eddd702cc0dfdc70287fda3aa14857ac399 100644 (file)
@@ -17,16 +17,18 @@ class ELearningMedia extends ToolboxModel
 
     protected static $_permissionBase = 'elearning-media';
 
+    public const MEDIA_TYPES = ['audio/mpeg', 'video/mp4'];
+
     public function setFields()
     {
         parent::setFields();
 
-        $this->addField('title', Text::class, __('Titre'));
+        $this->addField('title', Text::class, __('Titre'), __('Title'));
 
         $this->addOwnerField();
         $this->addColumnDateFields();
 
         $this->addField('complete_pct', Percent::class, __('Marquer terminé quand ce pourcentage est lu'), ['default' => 75]);
-        $this->addField('file', Files::class, __('Media'));
+        $this->addField('file', Files::class, __('Media'), ['acceptedFiles' => static::MEDIA_TYPES]);
     }
 }
index 0c0ba8320d82064c5821a74e2bce9801c2a34e18..e734ad5bc8c221da30045d8cd2f0cf11a676f840 100644 (file)
         },
         {
             "name": "backpack/crud",
-            "version": "4.1.64",
+            "version": "4.1.65",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Laravel-Backpack/CRUD.git",
-                "reference": "e49566ebd4a55e6849ef7e88822e53195719e2b8"
+                "reference": "e7ab6b798262d847647238f91f88992b457927d9"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Laravel-Backpack/CRUD/zipball/e49566ebd4a55e6849ef7e88822e53195719e2b8",
-                "reference": "e49566ebd4a55e6849ef7e88822e53195719e2b8",
+                "url": "https://api.github.com/repos/Laravel-Backpack/CRUD/zipball/e7ab6b798262d847647238f91f88992b457927d9",
+                "reference": "e7ab6b798262d847647238f91f88992b457927d9",
                 "shasum": ""
             },
             "require": {
             ],
             "support": {
                 "issues": "https://github.com/Laravel-Backpack/CRUD/issues",
-                "source": "https://github.com/Laravel-Backpack/CRUD/tree/4.1.64"
+                "source": "https://github.com/Laravel-Backpack/CRUD/tree/4.1.65"
             },
-            "time": "2022-01-14T08:59:01+00:00"
+            "time": "2022-01-21T15:41:05+00:00"
         },
         {
             "name": "backpack/logmanager",
             "source": {
                 "type": "git",
                 "url": "git://git.cubedesigners.com/cubist_cms-back.git",
-                "reference": "6c9993581e0abf2f551fa1ce66783571911810fa"
+                "reference": "fca3b3920a28bdd2f32aa5af8492a51ad610108c"
             },
             "dist": {
                 "type": "tar",
-                "url": "https://composer.cubedesigners.com/dist/cubist/cms-back/cubist-cms-back-dev-master-926445.tar",
-                "reference": "6c9993581e0abf2f551fa1ce66783571911810fa",
-                "shasum": "77d16e40a8d7c66a1a0ec551b185a5c4b9fad5b3"
+                "url": "https://composer.cubedesigners.com/dist/cubist/cms-back/cubist-cms-back-dev-master-07eb1e.tar",
+                "reference": "fca3b3920a28bdd2f32aa5af8492a51ad610108c",
+                "shasum": "ac24c6155f337241353db93431250bfdf2dfc281"
             },
             "require": {
                 "backpack/backupmanager": "^3.0",
                 }
             ],
             "description": "Cubist Backpack extension",
-            "time": "2022-01-20T17:16:11+00:00"
+            "time": "2022-01-21T16:53:45+00:00"
         },
         {
             "name": "cubist/cms-front",
         },
         {
             "name": "composer/composer",
-            "version": "2.2.4",
+            "version": "2.2.5",
             "source": {
                 "type": "git",
                 "url": "https://github.com/composer/composer.git",
-                "reference": "8a5ad75194f901e3b39ece4bbd22cbdabc79ae8f"
+                "reference": "22c41ef275c7bb64fa28fb2c0871a39666832cb9"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/composer/composer/zipball/8a5ad75194f901e3b39ece4bbd22cbdabc79ae8f",
-                "reference": "8a5ad75194f901e3b39ece4bbd22cbdabc79ae8f",
+                "url": "https://api.github.com/repos/composer/composer/zipball/22c41ef275c7bb64fa28fb2c0871a39666832cb9",
+                "reference": "22c41ef275c7bb64fa28fb2c0871a39666832cb9",
                 "shasum": ""
             },
             "require": {
             "support": {
                 "irc": "ircs://irc.libera.chat:6697/composer",
                 "issues": "https://github.com/composer/composer/issues",
-                "source": "https://github.com/composer/composer/tree/2.2.4"
+                "source": "https://github.com/composer/composer/tree/2.2.5"
             },
             "funding": [
                 {
                     "type": "tidelift"
                 }
             ],
-            "time": "2022-01-08T11:30:42+00:00"
+            "time": "2022-01-21T16:25:52+00:00"
         },
         {
             "name": "composer/metadata-minifier",
         },
         {
             "name": "phpunit/phpunit",
-            "version": "8.5.22",
+            "version": "8.5.23",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
-                "reference": "ddd05b9d844260353895a3b950a9258126c11503"
+                "reference": "efb20ff3623b9d09bf190a68fdfe574538a8d496"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ddd05b9d844260353895a3b950a9258126c11503",
-                "reference": "ddd05b9d844260353895a3b950a9258126c11503",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/efb20ff3623b9d09bf190a68fdfe574538a8d496",
+                "reference": "efb20ff3623b9d09bf190a68fdfe574538a8d496",
                 "shasum": ""
             },
             "require": {
             ],
             "support": {
                 "issues": "https://github.com/sebastianbergmann/phpunit/issues",
-                "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.22"
+                "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.23"
             },
             "funding": [
                 {
                     "type": "github"
                 }
             ],
-            "time": "2021-12-25T06:58:09+00:00"
+            "time": "2022-01-21T05:50:34+00:00"
         },
         {
             "name": "psy/psysh",