]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6300 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 26 Sep 2023 16:42:25 +0000 (18:42 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 26 Sep 2023 16:42:25 +0000 (18:42 +0200)
app/Elearning/QuizCompiler.php
app/Jobs/Maintenance/CheckPublicationsHashAndCid.php
app/Models/Quiz.php
app/Models/QuizTheme.php

index 74ec918aada3ff6dabd996f121e994dc024450bd..8d37a472dfd25c8657dfc6bf8759caeee7b5c0ac 100644 (file)
@@ -115,6 +115,9 @@ class QuizCompiler extends Base
         foreach ($this->theme->getFields() as $f) {
             if ($f instanceof \Cubist\Backpack\Magic\Fields\Files) {
                 $path = $themePageData->getImageFile($f->getName());
+                if(!$path){
+                    continue;
+                }
                 $spl = new \SplFileInfo($path);
                 $dest = 'assets/' . Files::tidyName($spl->getFilename());
                 $themeData[$f->getName()] = $dest;
@@ -202,6 +205,9 @@ class QuizCompiler extends Base
 
     protected function _font($f)
     {
+        if(!$f){
+            $f='SourceSans';
+        }
         $font = FluidbookFont::getAvailableFonts()[$f];
         if ($font['font_kit']) {
             $this->addFontKit($font['font_kit']);
@@ -262,6 +268,9 @@ class QuizCompiler extends Base
 
     protected function _resourcesPath()
     {
+        if(!$this->quiz->dev_version){
+            $this->quiz->dev_version='stable';
+        }
         switch ($this->quiz->dev_version) {
             case 'stable':
                 $branch = 'master';
@@ -280,7 +289,8 @@ class QuizCompiler extends Base
 
     protected function runWebpack($dev = false)
     {
-        $dev = $dev /*|| config('app.env') === 'development'*/;
+        $dev = $dev /*|| config('app.env') === 'development'*/
+        ;
         $mix = 'const mix = require("laravel-mix");';
         foreach ($this->mixDirectories as $from => $to) {
             $mix .= 'mix.copyDirectory("' . $from . '","' . $to . '");';
index 9c038c77c18cc4ce2c793cce1ced54d6dd909149..601b6dd7f5c35467f7ea5f6e1d893d6806abe310 100644 (file)
@@ -20,7 +20,6 @@ class CheckPublicationsHashAndCid extends Base
             foreach ($class::withoutGlobalScopes()->where(function ($query) {
                 $query->whereNull('hash')->orWhere('hash', '');
             })->get() as $instance) {
-                //Log::warning($name . ' #' . $instance->id . ' had empty hash or cid (hash: hash , cid: :cid)', ['hash' => $instance->hash]);
                 $instance->save();
             };
 
@@ -32,7 +31,6 @@ class CheckPublicationsHashAndCid extends Base
         foreach (FluidbookPublication::withoutGlobalScopes()->where(function ($query) {
             $query->whereNull('hash')->orWhere('hash', '')->orWhereNull('cid')->orWhere('cid', '');
         })->get() as $fluidbook) {
-            //Log::warning('Fluidbook #' . $fluidbook->id . ' had empty hash or cid (hash: hash , cid: :cid)', ['hash' => $fluidbook->hash, 'cid' => $fluidbook->cid]);
             $fluidbook->save();
         }
 
index 3bc42e68673a5679bd5e3ba3bbf8b538d3339806..65833567753cf9cffd9fdcc74108dcdff8710de3 100644 (file)
@@ -20,6 +20,7 @@ use Cubist\Backpack\Magic\Fields\FormBigSection;
 use Cubist\Backpack\Magic\Fields\FormSection;
 use Cubist\Backpack\Magic\Fields\FormSeparator;
 use Cubist\Backpack\Magic\Fields\FormSuperSection;
+use Cubist\Backpack\Magic\Fields\Hidden;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
 use Cubist\Backpack\Magic\Fields\Text;
 use Cubist\Backpack\Magic\Fields\Textarea;
@@ -47,7 +48,6 @@ class Quiz extends ToolboxModel
     protected $_operations = [PreviewOperation::class, DownloadOperation::class, LogOperation::class, ReportOperation::class, ChangeownerOperation::class];
 
 
-
     protected static function _getColors()
     {
         return [
@@ -67,6 +67,15 @@ class Quiz extends ToolboxModel
         ];
     }
 
+    protected static function _getMessages()
+    {
+        return [
+            'defaultMessage' => __('Message affiché à la fin du quiz'),
+            'passedMessage' => __('Message affiché lors de la réussite du quiz'),
+            'failedMessage' => __('Message affiché lors de l\'échec du quiz'),
+        ];
+    }
+
 
     protected static function _getImages()
     {
@@ -271,6 +280,27 @@ class Quiz extends ToolboxModel
             'add_label' => __('Nouveau résultat'),
             'when' => ['type' => 'test'],
         ]);
+
+        $default = ['type' => 'Hidden'];
+        foreach (self::_getColors() as $name => $color) {
+            $f = array_merge($default, $color, ['name' => $name]);
+            $this->addField($f);
+        }
+        $default = ['type' => 'Hidden', 'maxFiles' => 1];
+        foreach (self::_getImages() as $name => $label) {
+            $f = array_merge($default, ['name' => $name, 'label' => $label]);
+            $this->addField($f);
+        }
+
+        foreach (self::_getMessages() as $name => $label) {
+            $this->addField(['name' => $name,
+                'label' => $label,
+                'type' => 'Hidden'
+            ]);
+        }
+
+        $this->addField('css', Hidden::class, __('Code CSS supplémentaire'));
+
     }
 
     public function registerMediaConversions(Media $media = null): void
@@ -369,6 +399,10 @@ class Quiz extends ToolboxModel
      */
     public function getTheme()
     {
+        if (!$this->theme) {
+            $this->theme = QuizTheme::createFromOldVersionQuiz($this);
+            $this->saveQuietly();
+        }
         return QuizTheme::withoutGlobalScopes()->find($this->theme ?: 3);
     }
 
index af40d9b358b4c5e727b66fd43634869d79d25367..1e49f0822b476c81b057cb6e4dde1b8f9abc6397 100644 (file)
@@ -14,6 +14,9 @@ use Cubist\Backpack\Magic\Fields\FormSection;
 use Cubist\Backpack\Magic\Fields\FormSectionDescription;
 use Cubist\Backpack\Magic\Fields\FormSeparator;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Cubist\Util\CommandLine\Imagemagick;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Graphics\Resizer;
 
 class QuizTheme extends ToolboxModel
 {
@@ -32,9 +35,6 @@ class QuizTheme extends ToolboxModel
     public function setFields()
     {
         parent::setFields();
-
-        parent::setFields();
-
         $this->addOwnerField();
 
         $this->addField('name', 'Text', __('Nom'), ['column' => true]);
@@ -100,7 +100,7 @@ class QuizTheme extends ToolboxModel
 
     protected function _intro()
     {
-        $this->addField('sectionIntro', FormSection::class, __('Page d\'introduction'));
+        $this->addField('sectionIntro', FormSection::class, __('Écran d\'introduction'));
         $this->addField('introColor', Color::class, __('Couleur et transparence du bloc'), ['hint' => __('Par défaut, la couleur neutre du thème'), 'allows_empty' => true]);
         $this->addField('', FormSeparator::class, '');
         $this->addField('introCustom', Checkbox::class, __('Définir une forme personnalisée'));
@@ -164,4 +164,58 @@ class QuizTheme extends ToolboxModel
         }
         return $this->textsColor;
     }
+
+    /**
+     * @param $quiz Quiz
+     * @return QuizTheme
+     */
+    public static function createFromOldVersionQuiz($quiz)
+    {
+        $theme = new QuizTheme();
+        $theme->name = $quiz->client . ' - ' . $quiz->title;
+        $theme->mainColor = \Cubist\Util\Graphics\Color::colorToCSS($quiz->mainColor);
+        $theme->neutralColor = \Cubist\Util\Graphics\Color::colorToCSS('#333333');
+        $theme->okColor = \Cubist\Util\Graphics\Color::colorToCSS($quiz->okColor);
+        $theme->nokColor = \Cubist\Util\Graphics\Color::colorToCSS($quiz->nokColor);
+        $theme->backgroundColor = '#ffffff';
+
+        $logo = new \SplFileInfo($quiz->getFirstMediaPath($quiz->logo));
+        $tmp = Files::tempnam() . '.' . $logo->getExtension();
+        copy($logo, $tmp);
+        $theme->addMediaToField('logo', $tmp);
+
+        $theme->backgroundCustom = '1';
+        $theme->backgroundSize = ThemeBackgroundSize::RATIO;
+        $theme->backgroundHorizontalAlign = HorizontalAlign::CENTER;
+        $theme->backgroundVerticalAlign = VerticalAlign::MIDDLE;
+
+
+        $tmp = Files::tempnam() . '.jpg';
+        $blur = Files::tempnam() . '.jpg';
+        $banner = $quiz->getFirstMediaPath($quiz->banner);
+
+        $resizer = new Resizer();
+        $resizer->loadImage($banner);
+        $resizer->resize(1200, 680, true, true);
+        $resizer->output('jpg', $tmp);
+        Imagemagick::blur($tmp, $blur);
+        $theme->addMediaToField('backgroundImage', $blur);
+
+        $resizer = new Resizer($banner);
+        $resizer->loadImage($banner);
+        $resizer->resize(390, 844, true, true);
+        $resizer->output('jpg', $tmp);
+        Imagemagick::blur($tmp, $blur);
+        $theme->addMediaToField('backgroundImageMobile', $blur);
+
+        $theme->backgroundCustomMobile = '1';
+        $theme->backgroundSizeMobile = ThemeBackgroundSize::RATIO;
+        $theme->backgroundHorizontalAlignMobile = HorizontalAlign::CENTER;
+        $theme->backgroundVerticalAlignMobile = VerticalAlign::MIDDLE;
+
+        $theme->introCustom = '0';
+
+        $theme->save();
+        return $theme->id;
+    }
 }