From: Vincent Vanwaelscappel Date: Tue, 26 Sep 2023 16:42:25 +0000 (+0200) Subject: wip #6300 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=a466db8c75229642e78f5db942b4a41c3587a36b;p=fluidbook-toolbox.git wip #6300 @0.25 --- diff --git a/app/Elearning/QuizCompiler.php b/app/Elearning/QuizCompiler.php index 74ec918aa..8d37a472d 100644 --- a/app/Elearning/QuizCompiler.php +++ b/app/Elearning/QuizCompiler.php @@ -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 . '");'; diff --git a/app/Jobs/Maintenance/CheckPublicationsHashAndCid.php b/app/Jobs/Maintenance/CheckPublicationsHashAndCid.php index 9c038c77c..601b6dd7f 100644 --- a/app/Jobs/Maintenance/CheckPublicationsHashAndCid.php +++ b/app/Jobs/Maintenance/CheckPublicationsHashAndCid.php @@ -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(); } diff --git a/app/Models/Quiz.php b/app/Models/Quiz.php index 3bc42e686..658335677 100644 --- a/app/Models/Quiz.php +++ b/app/Models/Quiz.php @@ -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); } diff --git a/app/Models/QuizTheme.php b/app/Models/QuizTheme.php index af40d9b35..1e49f0822 100644 --- a/app/Models/QuizTheme.php +++ b/app/Models/QuizTheme.php @@ -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; + } }