From 673b5832665605da290d73b8b043d6ceeaf1b422 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 12 Oct 2023 10:39:04 +0200 Subject: [PATCH] wip #6387 @0.5 --- app/Elearning/QuizCompiler.php | 2 +- .../Controllers/Admin/Operations/Quiz/LogOperation.php | 10 ++++++++-- .../Admin/Operations/Quiz/ReportOperation.php | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Elearning/QuizCompiler.php b/app/Elearning/QuizCompiler.php index 768e1d1bb..b4b36e9fa 100644 --- a/app/Elearning/QuizCompiler.php +++ b/app/Elearning/QuizCompiler.php @@ -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))); diff --git a/app/Http/Controllers/Admin/Operations/Quiz/LogOperation.php b/app/Http/Controllers/Admin/Operations/Quiz/LogOperation.php index 5269f80cd..cfc475378 100644 --- a/app/Http/Controllers/Admin/Operations/Quiz/LogOperation.php +++ b/app/Http/Controllers/Admin/Operations/Quiz/LogOperation.php @@ -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(); diff --git a/app/Http/Controllers/Admin/Operations/Quiz/ReportOperation.php b/app/Http/Controllers/Admin/Operations/Quiz/ReportOperation.php index 175828c82..e8aba2aab 100644 --- a/app/Http/Controllers/Admin/Operations/Quiz/ReportOperation.php +++ b/app/Http/Controllers/Admin/Operations/Quiz/ReportOperation.php @@ -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(); -- 2.39.5