]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6170 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 28 Sep 2023 09:38:28 +0000 (11:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 28 Sep 2023 09:38:28 +0000 (11:38 +0200)
app/Elearning/QuizCompiler.php
app/Http/Controllers/Admin/Operations/Quiz/PreviewOperation.php
app/Jobs/GenerateQuizThemePreview.php
app/Models/Quiz.php
resources/quiztheme/theme_preview/theme_preview.js

index 8348f27cab1198dca493426a13c316f6775002a0..dc7721601b0930fceff7ebd827b6343b0441b9e4 100644 (file)
@@ -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;
index 7d2348b4b77bd6150f30e88a1e3a5617c617558e..c619d5f5f1b9d4b7177d46863c0139e51909e920 100644 (file)
@@ -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;
         }
     }
 }
index 0735655e61100cc3c7a0cc25b0e4b002740bc3f8..a738883f5a224e1d36deae0077bff84746305314 100644 (file)
@@ -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)
index 7cc2d4350ad2d6b61f35808b3de3481848880e75..92e7490eb380eeb104c70146ca610cec93e31d95 100644 (file)
@@ -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();
     }
 
index 1720ea5bbbcd042c60ed3a6382b886e22914c30f..9c1f13c4860548ebfea36427862e9fd77abe9085 100644 (file)
@@ -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