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;
protected function _font($f)
{
+ if(!$f){
+ $f='SourceSans';
+ }
$font = FluidbookFont::getAvailableFonts()[$f];
if ($font['font_kit']) {
$this->addFontKit($font['font_kit']);
protected function _resourcesPath()
{
+ if(!$this->quiz->dev_version){
+ $this->quiz->dev_version='stable';
+ }
switch ($this->quiz->dev_version) {
case 'stable':
$branch = 'master';
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 . '");';
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();
};
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();
}
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;
protected $_operations = [PreviewOperation::class, DownloadOperation::class, LogOperation::class, ReportOperation::class, ChangeownerOperation::class];
-
protected static function _getColors()
{
return [
];
}
+ 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()
{
'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
*/
public function getTheme()
{
+ if (!$this->theme) {
+ $this->theme = QuizTheme::createFromOldVersionQuiz($this);
+ $this->saveQuietly();
+ }
return QuizTheme::withoutGlobalScopes()->find($this->theme ?: 3);
}
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
{
public function setFields()
{
parent::setFields();
-
- parent::setFields();
-
$this->addOwnerField();
$this->addField('name', 'Text', __('Nom'), ['column' => true]);
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'));
}
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;
+ }
}