]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5041 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 8 Feb 2022 19:08:21 +0000 (20:08 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 8 Feb 2022 19:08:21 +0000 (20:08 +0100)
app/Models/ELearningPackage.php [new file with mode: 0644]
app/SubForms/ElearningPackageContent.php [new file with mode: 0644]
resources/views/vendor/backpack/base/inc/sidebar_content.blade.php

diff --git a/app/Models/ELearningPackage.php b/app/Models/ELearningPackage.php
new file mode 100644 (file)
index 0000000..2450dfa
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+namespace App\Models;
+
+use App\Http\Controllers\Admin\Operations\ELearningMedia\ImportOperation;
+use App\Http\Controllers\Admin\Operations\ELearningMedia\PreviewOperation;
+use App\Http\Controllers\Admin\Operations\ELearningMedia\DownloadOperation;
+use App\Models\Base\ToolboxModel;
+use App\SubForms\ElearningPackageContent;
+use Cubist\Backpack\Magic\Fields\BunchOfFieldsMultiple;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\Fields\Textarea;
+use Cubist\Scorm\Manifest;
+use Cubist\Util\Files\VirtualDirectory;
+use Spatie\MediaLibrary\MediaCollections\Models\Media;
+
+class ELearningPackage extends ToolboxModel
+{
+    protected $table = 'elearning_package';
+
+    protected $_options = ['name' => 'elearning-package',
+        'singular' => 'package',
+        'plural' => 'package'];
+
+    protected static $_permissionBase = 'elearning-package';
+
+
+    protected $_operations = [ImportOperation::class, PreviewOperation::class, DownloadOperation::class];
+
+    public function setFields()
+    {
+        parent::setFields();
+
+        $this->addField('title', Text::class, __('Titre'), ['column' => true]);
+        $this->addField('description', Textarea::class, __('Description'));
+
+        $this->addOwnerField();
+        $this->addColumnDateFields();
+
+        $this->addField('contents', BunchOfFieldsMultiple::class, __('Contenus'), ['bunch' => ElearningPackageContent::class, 'edit_label' => __('Editer « :label »', ['label' => '%content_type - %content_title'])]);
+    }
+
+    public function getFinalPath()
+    {
+        return protected_path('elearningpackage/final/' . $this->id);
+    }
+
+    public function compile($dest)
+    {
+        $owner = User::withoutGlobalScopes()->findOrFail($this->owner);
+        $organization = $owner->companyName;
+
+        $vdir = new VirtualDirectory($dest);
+        $vdir->file_put_contents('imsmanifest.xml', new Manifest($this->title, Manifest::SCORM_2004, $organization, 'MEDIA_' . $this->id));
+        $vdir->copyDirectory(resource_path('elearningmedia/dist/css'), 'css');
+        $vdir->copyDirectory(resource_path('elearningmedia/dist/js'), 'js');
+        /** @var Media $file */
+        $file = $this->getMediaInField('file')->first();
+        $spl = new \SplFileInfo($file->getPath());
+        $ext = mb_strtolower($spl->getExtension());
+        $vdir->copy($file->getPath(), 'media.' . $ext);
+        $vdir->file_put_contents('index.html', view('elearningmedia.index', ['media' => $this->getPageData(), 'type' => $ext === 'mp3' ? 'audio' : 'video']));
+        $vdir->sync(true);
+    }
+}
diff --git a/app/SubForms/ElearningPackageContent.php b/app/SubForms/ElearningPackageContent.php
new file mode 100644 (file)
index 0000000..a7ba28e
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+namespace App\SubForms;
+
+use Cubist\Backpack\Magic\Fields\Files;
+use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\SubForm;
+
+
+class ElearningPackageContent extends SubForm
+{
+    public function init()
+    {
+        parent::init();
+        $this->addField('content_title', Text::class, __('Titre'));
+
+        $this->addField('content_type', SelectFromArray::class, __('Type'), [
+            'options' => [
+                'FB' => 'FB - ' . __('Fluidbook'),
+                'IN' => 'IN - ' . __('Infographie'),
+                'AN' => 'AN - ' . __('Animation'),
+                'Ti5' => 'Ti5 - ' . __('Video'),
+                'QZ' => 'QZ - ' . __('Quiz'),
+                'PD' => 'PD - ' . __('Podcast'),
+                'FC' => 'FC - ' . __('Flipcards'),
+            ]
+        ]);
+
+        $this->addField('fb_id', SelectFromArray::class, __('Fluidbook'), ['when' => ['content_type' => 'FB']]);
+        $this->addField('media_id', SelectFromArray::class, __('Media'), ['when' => ['content_type' => ['PD', 'AN', 'Ti5']]]);
+        $this->addField('quiz_id', SelectFromArray::class, __('Quiz'), ['when' => ['content_type' => 'QZ']]);
+        $this->addField('content_file', Files::class, __('Charger un fichier'), ['when' => ['content_type' => ['IN', 'FC']]]);
+        $this->addField('media_file', Files::class, __('Charger un media'), ['when' => ['content_type' => ['PD', 'AN', 'Ti5'], 'media_id' => '']]);
+    }
+}
index 984172cc4e01ed629510e84432f618781be55cc4..ebbf7e5d6faa8dbd3195881f42e51be9c982e0db 100644 (file)
                 <li class="nav-item"><a class="nav-link" href="{{ backpack_url('elearning-media') }}"><i
                             class="la la-photo-video nav-icon"></i> {{__('Media')}}</a></li>
             @endcan
+            @can('elearning-package:read')
+                <li class="nav-item"><a class="nav-link" href="{{ backpack_url('elearning-package') }}"><i
+                            class="la la-cubes nav-icon"></i> {{__('Package')}}</a></li>
+            @endcan
             @can('quiztranslation:read')
                 <li class="nav-item"><a class="nav-link" href="{{ backpack_url('quiztranslation') }}"><i
                             class="la la-language nav-icon"></i> {{__('Traductions')}}</a></li>