]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6387 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 12 Oct 2023 08:39:04 +0000 (10:39 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 12 Oct 2023 08:39:04 +0000 (10:39 +0200)
app/Elearning/QuizCompiler.php
app/Http/Controllers/Admin/Operations/Quiz/LogOperation.php
app/Http/Controllers/Admin/Operations/Quiz/ReportOperation.php

index 768e1d1bbacbc988c890bf4371cd0e5d97769701..b4b36e9fac5e95c27a9410285ea1c9701ef12ad9 100644 (file)
@@ -134,6 +134,7 @@ class QuizCompiler extends Base
         }
         $this->mixDirectories['assets'] = 'dist/assets';
         $this->data['theme'] = new Data($themeData);
+        $this->data['env'] = config('app.env');
     }
 
 
@@ -231,7 +232,6 @@ class QuizCompiler extends Base
 
     protected function writeData()
     {
-
         $json = $this->data->asJSON();
         $dataSource = $this->compilePath . '/js/quiz.js';
         file_put_contents($dataSource, str_replace('this.data = data;', 'this.data = ' . $json . ';', file_get_contents($dataSource)));
index 5269f80cd0edcc80f3d54fc097c615394d5dc9b5..cfc475378030e78bd79aae12578e503c321ed641 100644 (file)
@@ -15,17 +15,23 @@ trait LogOperation
 {
     protected function setupLogRoutes($segment, $routeName, $controller)
     {
-        Route::match(['post','get'], $segment . '/{id}/log', $controller . '@log')->withoutMiddleware([VerifyCsrfToken::class, Authenticate::class, CheckIfAdmin::class]);
+        Route::match(['post', 'get'], $segment . '/{id}/log', $controller . '@log')->withoutMiddleware([VerifyCsrfToken::class, Authenticate::class, CheckIfAdmin::class]);
     }
 
     protected function log($id)
     {
         $request = request();
 
+        if ($request->getContentTypeFormat() === 'json') {
+            $passed = $request->get('passed') ? '1' : '0';
+        } else {
+            $passed = $request->get('passed') !== 'false' ? '1' : '0';
+        }
+
         $log = new QuizAttempt();
         $log->quiz = $id;
         $log->score = $request->get('score');
-        $log->passed = $request->get('passed') !== 'false' ? '1' : '0';
+        $log->passed = $passed;
         $log->answers = json_encode($request->get('questions'));
         $log->save();
 
index 175828c823d12c6f93c21cb6f501d22e0614ff26..e8aba2aab398ce021d215e32b656440e4da69b99 100644 (file)
@@ -63,6 +63,7 @@ trait ReportOperation
             if (null === $answers || !is_array($answers)) {
                 continue;
             }
+
             foreach ($answers as $aid => $answer) {
                 if (null === $answer) {
                     continue;
@@ -75,7 +76,7 @@ trait ReportOperation
                 }
                 $a[] = is_array($aa) ? implode(', ', $aa) : $aa;
                 if ($quiz->display_score && in_array($aid - 1, $countForScore, true)) {
-                    $a[] = $answer['score'];
+                    $a[] = $answer['score'] ? (int)$answer['score'] : '0';
                 }
             }
 
@@ -97,7 +98,6 @@ trait ReportOperation
             $attemptsList[] = $a;
         }
 
-
         $spreadsheet = new Spreadsheet();
         $sheet = $spreadsheet->getActiveSheet();