Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ResponseReportOutput | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
generate | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
generateCsvReportData | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | class ResponseReportOutput extends Report { |
6 | public function generate(bool $useNewVersion = false): bool { |
7 | $this->useNewVersion = $useNewVersion; |
8 | $adminDAO = new AdminDAO(); |
9 | $responses = $adminDAO->getResponseReportData($this->workspaceId, $this->dataIds); |
10 | |
11 | if (empty($responses)) { |
12 | return false; |
13 | |
14 | } else { |
15 | $this->reportData = $responses; |
16 | |
17 | if ($this->format == ReportFormat::CSV) { |
18 | $this->csvReportData = $this->generateCsvReportData($responses); |
19 | } |
20 | } |
21 | |
22 | return true; |
23 | } |
24 | |
25 | private function generateCsvReportData(array $responseData): string { |
26 | $csv[] = implode( |
27 | self::DELIMITER, |
28 | ['groupname', 'loginname', 'code', 'bookletname', 'unitname', 'originalUnitId', 'responses', 'laststate'] |
29 | ); |
30 | |
31 | foreach ($responseData as $row) { |
32 | $csv[] = implode( |
33 | self::DELIMITER, |
34 | [ |
35 | sprintf(self::CSV_CELL_FORMAT, $row['groupname']), |
36 | sprintf(self::CSV_CELL_FORMAT, $row['loginname']), |
37 | sprintf(self::CSV_CELL_FORMAT, $row['code']), |
38 | sprintf(self::CSV_CELL_FORMAT, $row['bookletname']), |
39 | sprintf(self::CSV_CELL_FORMAT, $row['unitname']), |
40 | sprintf(self::CSV_CELL_FORMAT, $row['originalUnitId']), |
41 | sprintf(self::CSV_CELL_FORMAT, preg_replace('/"/', '""', json_encode($row['responses']))), |
42 | sprintf(self::CSV_CELL_FORMAT, preg_replace('/"/', '""', $row['laststate'] ?? '')) |
43 | ] |
44 | ); |
45 | |
46 | } |
47 | |
48 | $csv = implode(self::LINE_ENDING, $csv); |
49 | |
50 | return self::BOM . $csv; |
51 | } |
52 | } |