]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6765 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 4 Mar 2024 13:25:59 +0000 (14:25 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 4 Mar 2024 13:25:59 +0000 (14:25 +0100)
app/Elearning/QuizCompiler.php
app/Models/QuizTheme.php

index bc0e1f15c9c15fc2a1cf5e22e497b25a76800a51..5e390a1b05d856361597f3be707c8d72de957fe7 100644 (file)
@@ -85,7 +85,7 @@ class QuizCompiler extends Base
         $vdir = new VirtualDirectory($this->dest);
         $vdir->copyDirectory($this->compilePath . '/dist/css', 'css');
         $vdir->copyDirectory($this->compilePath . '/dist/js', 'js');
-        $vdir->copyDirectory($this->compilePath . '/dist/assets', 'assets');
+        $vdir->copyDirectory($this->compilePath . '/dist/assets', 'assets',false);
 
         $l10n = $this->data->l10n;
         $blade = new Blade($this->_resourcesPath() . '/views', $this->_resourcesPath() . '/cache/' . md5(rand(100000, 10000000)) . '/');
index 3bdc8cd2f82bf45392404d576c81be1da75c5ba6..907ead57f4fcf290406b703a34910a192a4233aa 100644 (file)
@@ -223,8 +223,8 @@ class QuizTheme extends ToolboxModel
         $data = ['mainColor' => (string)$quiz->mainColor,
             'okColor' => (string)$quiz->okColor,
             'nokColor' => (string)$quiz->nokColor,
-            'logo' => hash_file('sha256', $logo),
-            'banner' => hash_file('sha256', $banner),
+            'logo' => $logo ? hash_file('sha256', $logo) : '',
+            'banner' => $banner ? hash_file('sha256', $banner) : '',
             'overlay' => (string)$quiz->overlay,
         ];
         $hash = hash('sha256', print_r($data, true));
@@ -246,27 +246,32 @@ class QuizTheme extends ToolboxModel
 
         $theme->owner = $quiz->owner;
 
-        $logo = new \SplFileInfo($logo);
-        $tmp = Files::tempnam() . '.' . $logo->getExtension();
-        copy($logo, $tmp);
-        $theme->addMediaToField('logo', $tmp);
-
-        $theme->backgroundCustom = '1';
+        if ($logo) {
+            $logo = new \SplFileInfo($logo);
+            $tmp = Files::tempnam() . '.' . $logo->getExtension();
+            copy($logo, $tmp);
+            $theme->addMediaToField('logo', $tmp);
+            $theme->backgroundCustom = '1';
+        }
 
         $theme->font = 'SourceSans';
 
-        $avg = Imagemagick::getAverageColor($banner);
-        $distance = $avg->distance(new \Cubist\Util\Graphics\Color('#fff'));
-        $darken = $distance <= 20000000;
+        if ($banner) {
+            $avg = Imagemagick::getAverageColor($banner);
+            $distance = $avg->distance(new \Cubist\Util\Graphics\Color('#fff'));
+            $darken = $distance <= 20000000;
 
-        if ($darken) {
-            $tmp = Files::tempnam() . '.jpg';
-            Imagemagick::brightnessContrast($banner, $tmp, -20);
-            $banner = $tmp;
-        }
+            if ($darken) {
+                $tmp = Files::tempnam() . '.jpg';
+                Imagemagick::brightnessContrast($banner, $tmp, -20);
+                $banner = $tmp;
+            }
 
-        $theme->addMediaToField('backgroundImage', self::resizeAndBlur($banner, 1200, 680));
-        $theme->addMediaToField('backgroundImageMobile', self::resizeAndBlur($banner, 390, 844));
+            $theme->addMediaToField('backgroundImage', self::resizeAndBlur($banner, 1200, 680));
+            $theme->addMediaToField('backgroundImageMobile', self::resizeAndBlur($banner, 390, 844));
+        } else {
+            $theme->backgroundColor = '#aaa';
+        }
 
         $theme->save();
         return $theme->id;
@@ -283,10 +288,9 @@ class QuizTheme extends ToolboxModel
         $resizer->resize($width, $height, true, true);
         $resizer->output('jpg', $tmp);
 
-
         Imagemagick::blur($tmp, $blur);
 
-        unlink($tmp);
+        Files::unlink($tmp);
         return $blur;
     }