From: Vincent Vanwaelscappel Date: Tue, 12 Jan 2021 13:11:27 +0000 (+0100) Subject: wait #4179 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=45c8322335a84336eca407801c5001435945b70c;p=fluidbook-toolbox.git wait #4179 @2 --- diff --git a/app/Http/Controllers/Admin/Operations/ReportOperation.php b/app/Http/Controllers/Admin/Operations/ReportOperation.php index a23fbb84f..a42f5db6c 100644 --- a/app/Http/Controllers/Admin/Operations/ReportOperation.php +++ b/app/Http/Controllers/Admin/Operations/ReportOperation.php @@ -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); diff --git a/resources/quiz/js/main.js b/resources/quiz/js/main.js index 11f1a291c..6225578c8 100644 --- a/resources/quiz/js/main.js +++ b/resources/quiz/js/main.js @@ -433,7 +433,7 @@ answers.push(a); log.answer = a; } else { - log.answer = $(this).find('input').val(); + log.answer = $(this).find('input,textarea').val(); } if (!count) {