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;
}
/** @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)) {
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];
}
$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);