--- /dev/null
+<?php
+
+namespace App\Http\Controllers\Admin\Operations\QuizTheme;
+
+use App\Http\Controllers\Admin\Operations\FluidbookPreviewOperation;
+use App\Jobs\GenerateQuizThemePreview;
+use App\Models\QuizTheme;
+use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
+use Illuminate\Support\Facades\Route;
+
+// __('!! e-Learning')
+
+trait PreviewOperation
+{
+ use FluidbookPreviewOperation;
+
+ protected function setupPreviewRoutes($segment, $routeName, $controller)
+ {
+ Route::match(['get'], 'quizthemepreview/{id}/{type}.jpg', $controller . '@previewImage')
+ ->whereIn('type', ['intro', 'outro', 'standard', 'draganddrop'])
+ ->whereNumber('id');
+ }
+
+ protected function previewImage($id, $type)
+ {
+ if (!QuizTheme::hasPermission($id, 'read')) {
+ abort(401);
+ }
+
+ /** @var QuizTheme $theme */
+ $theme = QuizTheme::withoutGlobalScopes()->find($id);
+ $path = $theme->getPreviewImagePath($type);
+ if (!file_exists($path)) {
+ $job = new GenerateQuizThemePreview($theme);
+ $job->handle();
+ }
+ if (!file_exists($path)) {
+ abort(404, 'Unable to generate theme ' . $theme->id . ' preview :' . $path);
+ }
+ return XSendFileController::sendfileNoCache($path);
+ }
+}
$cl->setArg('height', 680);
$cl->setArg('delay', 2);
$cl->setArg('scale', 1);
- $cl->setArg('intro', self::getPreviewPath($this->theme->getIdValue(), 'intro'));
- $cl->setArg('standard', self::getPreviewPath($this->theme->getIdValue(), 'standard'));
- $cl->setArg('draganddrop', self::getPreviewPath($this->theme->getIdValue(), 'draganddrop'));
- $cl->setArg('outro', self::getPreviewPath($this->theme->getIdValue(), 'outro'));
+ $cl->setArg('intro', $this->getPreviewPath('intro'));
+ $cl->setArg('standard', $this->getPreviewPath('standard'));
+ $cl->setArg('draganddrop', $this->getPreviewPath('draganddrop'));
+ $cl->setArg('outro', $this->getPreviewPath('outro'));
$url = $this->theme->getPreviewURL(['shortLoading' => 1, 'transition' => 1, 'puppeteer' => 1]);
$cl->setArg('url', $url);
$cl->execute();
$cl->debug();
}
- public static function getPreviewPath($themeId, $variant = '')
+ public function getPreviewPath($type)
{
- return Files::mkdir(storage_path('quizthemes') . '/' . $themeId) . $variant . '.jpg';
+ return $this->theme->getPreviewImagePath($type);
}
}
use App\Fields\ThemeBackgroundSize;
use App\Fields\VerticalAlign;
use App\Http\Controllers\Admin\Operations\ChangeownerOperation;
-use App\Jobs\GenerateSecondPagePreview;
+use App\Http\Controllers\Admin\Operations\QuizTheme\PreviewOperation;
use App\Jobs\GenerateThemePreview;
use App\Jobs\UpdateWS2ThemeTable;
use App\Models\Base\ToolboxSettingsModel;
public static $updateWS2ViewOnChange = true;
public static $updateWS2SyncViewOnChange = false;
- protected $_operations = [ChangeownerOperation::class];
+ protected $_operations = [ChangeownerOperation::class, PreviewOperation::class];
public function setFields()
{
]);
$this->addField(['name' => 'interfaceFont',
- 'type'=>FluidbookFont::class,
+ 'type' => FluidbookFont::class,
'default' => 'OpenSans',
'label' => __('Police de caractères'),
'translatable' => false,
use App\Fields\HorizontalAlign;
use App\Fields\ThemeBackgroundSize;
use App\Fields\VerticalAlign;
+use App\Jobs\GenerateQuizThemePreview;
use App\Models\Base\ToolboxModel;
use Cubist\Backpack\Magic\Fields\Checkbox;
use Cubist\Backpack\Magic\Fields\Color;
use Cubist\Backpack\Magic\Fields\FormSeparator;
use Cubist\Backpack\Magic\Fields\Hidden;
use Cubist\Backpack\Magic\Fields\SelectFromArray;
-use Cubist\Backpack\Magic\Fields\Text;
use Cubist\Util\CommandLine\Imagemagick;
use Cubist\Util\Files\Files;
use Cubist\Util\Graphics\Resizer;
return $theme->id;
}
-
$theme = new QuizTheme();
$theme->hash = $hash;
$theme->name = $quiz->client . ' - ' . $quiz->title;
return $blur;
}
- public function getPreviewURL($params = [], $page = 2)
+ public function getPreviewURL($params = [])
{
- return self::getThemePreviewURL($this->getIdValue(), $params, $page);
+ return self::getThemePreviewURL($this->getIdValue(), $params);
}
public static function getThemePreviewURL($id, $params = [])
}
- public function getPreviewImage()
+ public function getPreviewImage($type = 'intro')
+ {
+ return clean('<img src="' . backpack_url('quizthemepreview/' . $this->getIdValue() . '/' . $type . '.jpg') . '" width="200" height="113" alt="" />');
+ }
+
+ public function getPreviewImagePath($type)
{
- return clean('<img src="' . backpack_url('quizthemepreview/' . $this->getIdValue() . '-intro.jpg') . '" width="200" height="140" alt="" />');
+ return \Cubist\Util\Files\Files::mkdir(storage_path('quizthemes') . '/' . $this->id) . $type . '.jpg';
}
+ public function postSave()
+ {
+ parent::postSave();
+ $this->_generateThemePreview();
+ }
+ protected function _generateThemePreview($sync = false)
+ {
+ dispatch(new GenerateQuizThemePreview($this))->onQueue('theme');
+ }
}
];
(async () => {
- const {installMouseHelper} = require('./install-mouse-helper');
const options = commandLineArgs(optionDefinitions);
const browser = await puppeteer.launch({
headless: 'new',