From d16258a2ef711883342da8af97162158b6d3dd8c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 28 Sep 2023 11:38:28 +0200 Subject: [PATCH] wip #6170 @0.25 --- app/Elearning/QuizCompiler.php | 4 ++-- .../Operations/Quiz/PreviewOperation.php | 22 ++++++++++++------- app/Jobs/GenerateQuizThemePreview.php | 1 - app/Models/Quiz.php | 4 ++-- .../quiztheme/theme_preview/theme_preview.js | 1 + 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/Elearning/QuizCompiler.php b/app/Elearning/QuizCompiler.php index 8348f27ca..dc7721601 100644 --- a/app/Elearning/QuizCompiler.php +++ b/app/Elearning/QuizCompiler.php @@ -49,10 +49,10 @@ class QuizCompiler extends Base */ protected $data; - public function __construct($quiz, $dest, $forceScorm = false) + public function __construct($quiz, $dest, $theme = null, $forceScorm = false) { $this->quiz = $quiz instanceof Quiz ? $quiz : Quiz::withoutGlobalScopes()->find($quiz); - $this->theme = $this->quiz->getTheme(); + $this->theme = $theme ?? $this->quiz->getTheme(); $this->compilePath = protected_path($this->getBaseURL() . '/compile/' . $this->quiz->id); $this->dest = $dest; $this->forceScorm = $forceScorm; diff --git a/app/Http/Controllers/Admin/Operations/Quiz/PreviewOperation.php b/app/Http/Controllers/Admin/Operations/Quiz/PreviewOperation.php index 7d2348b4b..c619d5f5f 100644 --- a/app/Http/Controllers/Admin/Operations/Quiz/PreviewOperation.php +++ b/app/Http/Controllers/Admin/Operations/Quiz/PreviewOperation.php @@ -51,15 +51,16 @@ trait PreviewOperation } $nointerface = !!request('nointerface', false); $shortLoading = !!request('shortLoading', false); + $forceTheme = false; - self::_getQuizAndTheme($id, $hash, $quiz, $theme); + self::_getQuizAndTheme($id, $hash, $quiz, $theme, $forceTheme); if (null === $time || ((null === $path || $path === 'index.html') && $time > 0 && $time < (time() - 60) && !$nointerface && !$shortLoading)) { $url = backpack_url($segment . '/preview/' . $id . '_' . $hash . '_' . time()) . '/' . $q; return $this->loadingCompile($url, $id, $hash); } - return $this->preview($quiz, $theme, $path); + return $this->preview($quiz, $theme, $forceTheme, $path); } @@ -69,11 +70,13 @@ trait PreviewOperation * @param string $path * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Foundation\Application|\Illuminate\Http\Response */ - protected function preview($quiz, $theme, $path = 'index.html') + protected function preview($quiz, $theme, $forceTheme = false, $path = 'index.html') { - $dest = protected_path('quiz/final/' . $quiz->id); + $id = $forceTheme ? $quiz->id . '-' . $theme->id : $quiz->id; + + $dest = protected_path('quiz/final/' . $id); if ($path === 'index.html') { - $quiz->compile($dest); + $quiz->compile($dest, $theme); } $p = $dest . '/' . $path; return response(null)->header('Content-Type', Files::_getMimeType($p))->header('X-Sendfile', $p); @@ -89,7 +92,7 @@ trait PreviewOperation { PHP::neverStop(false); - self::_getQuizAndTheme($id, $hash, $quiz, $theme); + self::_getQuizAndTheme($id, $hash, $quiz, $theme, $forceTheme); if (null === $theme || null === $quiz) { abort(404); } @@ -109,7 +112,7 @@ trait PreviewOperation * @param $theme QuizTheme * @return void */ - protected static function _getQuizAndTheme($id, $hash, &$quiz, &$theme) + protected static function _getQuizAndTheme($id, $hash, &$quiz, &$theme, &$forceTheme) { $ee = explode('-', $id); $forceThemeData = request('theme', false); @@ -124,8 +127,11 @@ trait PreviewOperation if (null === $quiz) { abort(404, __('Lien de prévisualisation invalide')); } - if (!isset($theme)) { + if (!isset($theme) || $quiz->theme === $theme->id) { + $forceTheme = false; $theme = $quiz->getTheme(); + } else { + $forceTheme = true; } } } diff --git a/app/Jobs/GenerateQuizThemePreview.php b/app/Jobs/GenerateQuizThemePreview.php index 0735655e6..a738883f5 100644 --- a/app/Jobs/GenerateQuizThemePreview.php +++ b/app/Jobs/GenerateQuizThemePreview.php @@ -49,7 +49,6 @@ class GenerateQuizThemePreview extends Base $url = $this->theme->getPreviewURL(['shortLoading' => 1, 'transition' => 1, 'puppeteer' => 1]); $cl->setArg('url', $url); $cl->execute(); - $cl->debug(); } public function getPreviewPath($type) diff --git a/app/Models/Quiz.php b/app/Models/Quiz.php index 7cc2d4350..92e7490eb 100644 --- a/app/Models/Quiz.php +++ b/app/Models/Quiz.php @@ -315,9 +315,9 @@ class Quiz extends ToolboxModel * @param $quiz self * @throws \JsonException */ - public function compile($dest, $forceScorm = false, $user = null) + public function compile($dest, $theme = null, $forceScorm = false, $user = null) { - $job = new QuizCompiler($this, $dest, $forceScorm); + $job = new QuizCompiler($this, $dest, $theme, $forceScorm); $job->handle(); } diff --git a/resources/quiztheme/theme_preview/theme_preview.js b/resources/quiztheme/theme_preview/theme_preview.js index 1720ea5bb..9c1f13c48 100644 --- a/resources/quiztheme/theme_preview/theme_preview.js +++ b/resources/quiztheme/theme_preview/theme_preview.js @@ -37,6 +37,7 @@ const optionDefinitions = [ // Intro screen await page.goto(options.url, {waitUntil: 'networkidle2'}); + await new Promise(r => setTimeout(r, 1000 * (options.delay + 3))); await page.screenshot({path: options.intro, type: 'jpeg', quality: 95}); // Question 1 -- 2.39.5