]> _ Git - fluidbook-toolbox.git/commitdiff
wait #4179 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Jan 2021 13:11:27 +0000 (14:11 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Jan 2021 13:11:27 +0000 (14:11 +0100)
app/Http/Controllers/Admin/Operations/ReportOperation.php
resources/quiz/js/main.js

index a23fbb84fdaa9c242d9b17afbf3cd1d13d04db83..a42f5db6c1eab0ed6aa03803d08b3eb5cec5df82 100644 (file)
@@ -24,15 +24,18 @@ trait ReportOperation
     protected function report($id)
     {
         $quiz = Quiz::where('id', $id)->first()->getPageData();
-        $first = ['#', 'Date', 'Score', 'Passed'];
+        $first = ['#', 'Date'];
+        if ($quiz->display_score) {
+            $first = array_merge($first, ['Score', 'Passed']);
+        }
 
-        $emailQuestion = 0;
+        $emailQuestion = false;
         $countForScore = [];
 
         foreach ($quiz->questions as $q => $question) {
             $label = $question['report_label'] ?: $question['question'];
             $first[] = $label;
-            if ($question['count_for_score']) {
+            if ($quiz->display_score && $question['count_for_score']) {
                 $first[] = $label . ' status';
                 $countForScore[] = $q;
             }
@@ -46,9 +49,13 @@ trait ReportOperation
         /** @var QuizAttempt[] $attempts */
         $attempts = QuizAttempt::where('quiz', $id)->orderBy('created_at', 'ASC')->get();
         foreach ($attempts as $attempt) {
-            $email = null;
+            $email = $attempt->id;
             $data = $attempt->getPageData();
-            $a = [$data->get('id'), $data->get('created_at'), $data->get('score'), $data->get('passed') ? '1' : '0'];
+            $a = [$data->get('id'), $data->get('created_at')];
+            if ($quiz->display_score) {
+                $a[] = $data->get('score');
+                $a[] = ($data->get('passed') ? '1' : '0');
+            }
             $answers = $data->get('answers', []);
 
             if (null === $answers || !is_array($answers)) {
@@ -59,16 +66,18 @@ trait ReportOperation
                     continue;
                 }
                 $aa = $answer['anwser'] ?? $answer['answer'] ?? '';
-                if ($aid == $emailQuestion + 1) {
-                    $email = trim(mb_strtolower($aa));
+                if ($emailQuestion !== false) {
+                    if ($aid == $emailQuestion + 1) {
+                        $email = trim(mb_strtolower($aa));
+                    }
                 }
                 $a[] = is_array($aa) ? implode(', ', $aa) : $aa;
-                if (in_array($aid - 1, $countForScore, true)) {
+                if ($quiz->display_score && in_array($aid - 1, $countForScore, true)) {
                     $a[] = $answer['score'];
                 }
             }
 
-            if (null !== $email) {
+            if ($emailQuestion !== false) {
                 if (!isset($users[$email])) {
                     $users[$email] = ['totalAttempts' => 0, 'attemptsBeforePassing' => 0, 'passed' => false, 'worstScore' => 100, 'bestScore' => 0];
                 }
@@ -86,23 +95,26 @@ trait ReportOperation
             $attemptsList[] = $a;
         }
 
-        $usersList = [['Email', 'Passed', 'Attempts before passed', 'Total attempts', 'Best score', 'Worst score']];
-        foreach ($users as $email => $user) {
-            $usersList[] = [$email, $user['passed'] ? '1' : '0', $user['attemptsBeforePassing'], $user['totalAttempts'], $user['bestScore'], $user['worstScore']];
-        }
 
         $spreadsheet = new Spreadsheet();
-
         $sheet = $spreadsheet->getActiveSheet();
-        $sheet->setTitle('USERS');
-        $sheet->fromArray($usersList);
-        foreach (range('A', 'Z') as $columnID) {
-            $sheet->getColumnDimension($columnID)->setAutoSize(true);
+
+        if ($emailQuestion !== false) {
+            $usersList = [['Email', 'Passed', 'Attempts before passed', 'Total attempts', 'Best score', 'Worst score']];
+            foreach ($users as $email => $user) {
+                $usersList[] = [$email, $user['passed'] ? '1' : '0', $user['attemptsBeforePassing'], $user['totalAttempts'], $user['bestScore'], $user['worstScore']];
+            }
+
+            $sheet->setTitle('USERS');
+            $sheet->fromArray($usersList);
+            foreach (range('A', 'Z') as $columnID) {
+                $sheet->getColumnDimension($columnID)->setAutoSize(true);
+            }
+            $sheet = $spreadsheet->createSheet();
         }
 
         array_reverse($attemptsList);
-        $sheet = $spreadsheet->createSheet();
-        $sheet->setTitle('ATTEMPTS');
+        $sheet->setTitle('DATA');
         $sheet->fromArray($attemptsList);
         foreach (range('A', 'Z') as $columnID) {
             $sheet->getColumnDimension($columnID)->setAutoSize(true);
index 11f1a291cbb6cbbb411fbcef6409d23b102e193e..6225578c8b83b0277149c20ce8db56b24441daa8 100644 (file)
                     answers.push(a);
                     log.answer = a;
                 } else {
-                    log.answer = $(this).find('input').val();
+                    log.answer = $(this).find('input,textarea').val();
                 }
 
                 if (!count) {