--- /dev/null
+<?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);
+ }
+}
--- /dev/null
+<?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' => '']]);
+ }
+}