Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
63 / 63 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ScopeAppointmentsByDayXlsExport | |
100.00% |
63 / 63 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
54 / 54 |
|
100.00% |
1 / 1 |
5 | |||
convertspecialchars | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * |
5 | * @package Zmsadmin |
6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
7 | * |
8 | */ |
9 | |
10 | namespace BO\Zmsadmin; |
11 | |
12 | use League\Csv\Writer; |
13 | use League\Csv\Reader; |
14 | use League\Csv\EscapeFormula; |
15 | |
16 | /** |
17 | * Handle requests concerning services |
18 | */ |
19 | class ScopeAppointmentsByDayXlsExport extends BaseController |
20 | { |
21 | /** |
22 | * |
23 | * @return String |
24 | */ |
25 | public function readResponse( |
26 | \Psr\Http\Message\RequestInterface $request, |
27 | \Psr\Http\Message\ResponseInterface $response, |
28 | array $args |
29 | ) { |
30 | $workstation = \App::$http->readGetResult('/workstation/', [ |
31 | 'resolveReferences' => 1, |
32 | 'gql' => Helper\GraphDefaults::getWorkstation() |
33 | ])->getEntity(); |
34 | $workstationRequest = new \BO\Zmsclient\WorkstationRequests(\App::$http, $workstation); |
35 | $selectedDateTime = ScopeAppointmentsByDay::readSelectedDateTime($args['date']); |
36 | $scope = ScopeAppointmentsByDay::readSelectedScope($workstation, $workstationRequest, $args['id']); |
37 | $processList = ScopeAppointmentsByDay::readProcessList($workstationRequest, $selectedDateTime); |
38 | |
39 | $xlsSheetTitle = $selectedDateTime->format('d.m.Y'); |
40 | $clusterColumn = $workstation->isClusterEnabled() ? 'Kürzel' : 'Lfd. Nummer'; |
41 | $xlsHeaders = [ |
42 | $clusterColumn, |
43 | 'Uhrzeit/Ankunftszeit', |
44 | 'Nr.', |
45 | 'Name', |
46 | 'Telefon', |
47 | 'Email', |
48 | 'Dienstleistung', |
49 | 'Anmerkungen', |
50 | 'Freitextfeld', |
51 | 'Freitextfeld2' |
52 | ]; |
53 | |
54 | $rows = []; |
55 | $key = 1; |
56 | foreach ($processList as $queueItem) { |
57 | $client = $queueItem->getFirstClient(); |
58 | $request = count($queueItem->requests) > 0 ? $queueItem->requests[0] : []; |
59 | $rows[] = [ |
60 | $workstation->isClusterEnabled() ? $queueItem->getCurrentScope()->shortName : $key++ , |
61 | $queueItem->getArrivalTime()->setTimezone(\App::$now->getTimezone())->format('H:i:s'), |
62 | $queueItem->queue['number'], |
63 | $client['familyName'], |
64 | $client['telephone'], |
65 | $client['email'], |
66 | $queueItem->requests->getCsvForProperty('name'), |
67 | $queueItem->amendment, |
68 | $queueItem->customTextfield, |
69 | $queueItem->customTextfield2, |
70 | ]; |
71 | } |
72 | $writer = Writer::createFromString(); |
73 | $writer->setDelimiter(';'); |
74 | $writer->addFormatter(new EscapeFormula()); |
75 | $writer->insertOne($xlsHeaders); |
76 | $writer->setOutputBOM(Reader::BOM_UTF8); |
77 | $writer->insertAll($rows); |
78 | |
79 | $response->getBody()->write($writer->toString()); |
80 | $fileName = sprintf("Tagesübersicht_%s_%s.csv", $scope->contact['name'], $xlsSheetTitle); |
81 | return $response |
82 | ->withHeader('Content-Type', 'text/csv; charset=UTF-8') |
83 | ->withHeader('Content-Description', 'File Transfer') |
84 | ->withHeader( |
85 | 'Content-Disposition', |
86 | sprintf('download; filename="' . $this->convertspecialChars($fileName) . '"') |
87 | ); |
88 | } |
89 | |
90 | protected function convertspecialchars($string) |
91 | { |
92 | |
93 | $convert = array ( |
94 | array ('ä','ae',), |
95 | array ('ö','oe',), |
96 | array ('ü','ue',), |
97 | array ('ß','ss',), |
98 | ); |
99 | |
100 | |
101 | foreach ($convert as $array) { |
102 | $string = str_replace($array[0], $array[1], $string); |
103 | } |
104 | return $string; |
105 | } |
106 | } |