]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5041 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 11 Feb 2022 17:12:26 +0000 (18:12 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 11 Feb 2022 17:12:26 +0000 (18:12 +0100)
.idea/workspace.xml
app/Models/ELearningPackage.php
app/SubForms/ElearningPackageContent.php

index b2c6648217c6bf0260a7d2f127d9080840402b4e..16d303f8abab894e29bff2e4fb4047e3a8cd4dc5 100644 (file)
     <select />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="5d2ecd5e-a05a-4f96-a195-fa6372618165" name="Default Changelist" comment="wip #5041">
+    <list default="true" id="5d2ecd5e-a05a-4f96-a195-fa6372618165" name="Default Changelist" comment="wip #5041 @1">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/app/Models/ELearningMedia.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/ELearningMedia.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/app/Models/ELearningPackage.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Models/ELearningPackage.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/resources/elearningpackage/js/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/resources/elearningpackage/js/app.js" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/resources/views/elearningmedia/index.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/elearningmedia/index.blade.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/SubForms/ElearningPackageContent.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/SubForms/ElearningPackageContent.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
       <workItem from="1644394645639" duration="13635000" />
       <workItem from="1644425348765" duration="2270000" />
       <workItem from="1644508187200" duration="10853000" />
-      <workItem from="1644582031422" duration="1260000" />
-    </task>
-    <task id="LOCAL-00191" summary="wip #3753 @2">
-      <created>1636044131486</created>
-      <option name="number" value="00191" />
-      <option name="presentableId" value="LOCAL-00191" />
-      <option name="project" value="LOCAL" />
-      <updated>1636044131486</updated>
+      <workItem from="1644582031422" duration="5202000" />
     </task>
     <task id="LOCAL-00192" summary="wait #3753 @1">
       <created>1636053838335</created>
       <option name="project" value="LOCAL" />
       <updated>1644578457525</updated>
     </task>
-    <option name="localTasksCounter" value="240" />
+    <task id="LOCAL-00240" summary="wip #5041 @1">
+      <created>1644583408821</created>
+      <option name="number" value="00240" />
+      <option name="presentableId" value="LOCAL-00240" />
+      <option name="project" value="LOCAL" />
+      <updated>1644583408821</updated>
+    </task>
+    <option name="localTasksCounter" value="241" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
     <MESSAGE value="wip #5045 @0.75" />
     <MESSAGE value="wip #5045 @1.1" />
     <MESSAGE value="wait #5045 @0.5" />
-    <MESSAGE value="wip #5041 @1" />
     <MESSAGE value="wip #5041 @3" />
     <MESSAGE value="wip #5041 @1.5" />
     <MESSAGE value="wip #5041" />
-    <option name="LAST_COMMIT_MESSAGE" value="wip #5041" />
+    <MESSAGE value="wip #5041 @1" />
+    <option name="LAST_COMMIT_MESSAGE" value="wip #5041 @1" />
   </component>
   <component name="XSLT-Support.FileAssociations.UIState">
     <expand />
index 6dd88910332d07a779cbfffe7a18309d0f744893..11fe38aa70177d56349c7b6e7ae921e3011f76bf 100644 (file)
@@ -14,6 +14,7 @@ use Cubist\Backpack\Magic\Fields\Textarea;
 use Cubist\Scorm\Manifest;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Files\VirtualDirectory;
+use Cubist\Util\Zip;
 use Spatie\MediaLibrary\MediaCollections\Models\Media;
 
 class ELearningPackage extends ToolboxModel
@@ -57,7 +58,10 @@ class ELearningPackage extends ToolboxModel
         $modules = [];
 
         foreach ($this->contents as $id => $content) {
-            $modules[] = $this->_compileModule($id, $content, $vdir);
+            $m = $this->_compileModule($id, $content, $vdir);
+            if ($m !== false) {
+                $modules[] = $m;
+            }
         }
 
         $data = ['title' => $this->title, 'description' => $this->description, 'modules' => $modules];
@@ -89,29 +93,32 @@ class ELearningPackage extends ToolboxModel
 
         switch ($res['type']) {
             case 'FB':
-                $title = $this->_compileFluidbook($c['fb_id'], $vdir, $basePath);
+                $moduleTitle = $this->_compileFluidbook($c['fb_id'], $vdir, $basePath);
                 break;
             case 'QZ':
-                $title = $this->_compileQuiz($c['quiz_id'], $vdir, $basePath);
+                $moduleTitle = $this->_compileQuiz($c['quiz_id'], $vdir, $basePath);
                 break;
             case 'PD':
-                $title = $this->_compileMedia($c['audio_id'], $c['audio_file'], $vdir, $basePath);
+                $moduleTitle = $this->_compileMedia($c['audio_id'], $c['audio_file'], $vdir, $basePath);
                 break;
             case 'Ti5':
             case 'AN':
-                $title = $this->_compileMedia($c['video_id'], $c['video_file'], $vdir, $basePath);
+                $moduleTitle = $this->_compileMedia($c['video_id'], $c['video_file'], $vdir, $basePath);
                 break;
             case 'IN':
-                $title = $this->_compilePDF($c['infographic_file'], $vdir, $basePath);
+                $moduleTitle = $this->_compilePDF($c['infographic_file'], $vdir, $basePath);
                 break;
             case 'FC':
             default:
-                $title = $this->_compileZip($c['content_file'], $vdir, $basePath);
+                $moduleTitle = $this->_compileZip($c['content_file'], $vdir, $basePath);
                 break;
 
         }
+        if (null === $moduleTitle) {
+            return false;
+        }
         if (!$res['title']) {
-            $res['title'] = $title;
+            $res['title'] = $moduleTitle;
         }
 
         return $res;
@@ -142,6 +149,9 @@ class ELearningPackage extends ToolboxModel
         $vdir->addTemp($tmp);
 
         $quiz = Quiz::find($id);
+        if (null === $quiz) {
+            return null;
+        }
         $quiz->compile($tmp);
 
         $vdir->copyDirectory($tmp, $basePath);
@@ -159,7 +169,11 @@ class ELearningPackage extends ToolboxModel
         $owner = User::withoutGlobalScopes()->findOrFail($this->owner);
         $organization = $owner->companyName;
 
-        $file = $this->getMediaByCollection($media_file)->first()->getPath();
+        $f = $this->getMediaByCollection($media_file)->first();
+        if (null === $f) {
+            return null;
+        }
+        $file = $f->getPath();
         return ELearningMedia::compileFromFile($file, $tmp, '', $organization, 'MEDIA_' . $media_file);
     }
 
@@ -169,6 +183,9 @@ class ELearningPackage extends ToolboxModel
         $vdir->addTemp($tmp);
 
         $media = ELearningMedia::find($id);
+        if (null === $media) {
+            return null;
+        }
         $media->compile($tmp);
 
         $vdir->copyDirectory($tmp, $basePath);
@@ -177,11 +194,28 @@ class ELearningPackage extends ToolboxModel
 
     protected function _compilePDF($collection, $vdir, $basePath)
     {
-
+        $f = $this->getMediaByCollection($collection)->first();
+        if (null === $f) {
+            return null;
+        }
+        $spf = new \SplFileInfo($f->getPath());
+        $vdir->copy($spf->getPathname(), $basePath . '/infographic.pdf');
+        return $spf->getBasename('.' . $spf->getExtension());
     }
 
     protected function _compileZip($collection, $vdir, $basePath)
     {
+        $tmp = Files::tmpdir();
+        $vdir->addTemp($tmp);
+
+        $f=$this->getMediaByCollection($collection)->first();
+        if(null===$f){
+            return null;
+        }
+        $spf = new \SplFileInfo($f->getPath());
+        Zip::extract($spf->getPathname(), $tmp);
+        $vdir->copyDirectory($tmp, $basePath);
 
+        return $spf->getBasename('.' . $spf->getExtension());
     }
 }
index 637106e078d77ff3e1a7b3540952fbef372c3ac5..620dee1bf0d66aac59e62058f4b2d3b9855623e8 100644 (file)
@@ -45,7 +45,7 @@ class ElearningPackageContent extends SubForm
 
         $this->addField('infographic_file', Files::class, __('Charger une infographie'), ['when' => ['content_type' => ['IN']], 'acceptedFiles' => ['application/pdf']]);
 
-        $this->addField('content_file', Files::class, __('Charger un contnue'), ['when' => ['content_type' => ['FC']], 'acceptedFiles' => ['application/zip']]);
+        $this->addField('content_file', Files::class, __('Charger un contenu'), ['when' => ['content_type' => ['FC']], 'acceptedFiles' => ['application/zip']]);
 
         $this->addField('mandatory', Checkbox::class, __('Obligatoire'), ['default' => true]);
         $this->addField('content_title', Text::class, __('Titre'), ['hint' => __('Laisser vide pour utiliser le titre par défaut')]);