Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
61 / 61
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ScopeAppointmentsByDayXlsExport
100.00% covered (success)
100.00%
61 / 61
100.00% covered (success)
100.00%
2 / 2
7
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
52 / 52
100.00% covered (success)
100.00%
1 / 1
5
 convertspecialchars
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 *
5 * @package Zmsadmin
6 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
7 *
8 */
9
10namespace BO\Zmsadmin;
11
12use League\Csv\Writer;
13use League\Csv\Reader;
14use League\Csv\EscapeFormula;
15
16/**
17 * Handle requests concerning services
18 */
19class 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        ];
52
53        $rows = [];
54        $key = 1;
55        foreach ($processList as $queueItem) {
56            $client = $queueItem->getFirstClient();
57            $request = count($queueItem->requests) > 0 ? $queueItem->requests[0] : [];
58            $rows[] = [
59                $workstation->isClusterEnabled() ? $queueItem->getCurrentScope()->shortName : $key++ ,
60                $queueItem->getArrivalTime()->setTimezone(\App::$now->getTimezone())->format('H:i:s'),
61                $queueItem->queue['number'],
62                $client['familyName'],
63                $client['telephone'],
64                $client['email'],
65                $queueItem->requests->getCsvForProperty('name'),
66                $queueItem->amendment,
67                $queueItem->customTextfield,
68            ];
69        }
70        $writer = Writer::createFromString();
71        $writer->setDelimiter(';');
72        $writer->addFormatter(new EscapeFormula());
73        $writer->insertOne($xlsHeaders);
74        $writer->setOutputBOM(Reader::BOM_UTF8);
75        $writer->insertAll($rows);
76
77        $response->getBody()->write($writer->toString());
78        $fileName = sprintf("Tagesübersicht_%s_%s.csv", $scope->contact['name'], $xlsSheetTitle);
79        return $response
80            ->withHeader('Content-Type', 'text/csv; charset=UTF-8')
81            ->withHeader('Content-Description', 'File Transfer')
82            ->withHeader(
83                'Content-Disposition',
84                sprintf('download; filename="' . $this->convertspecialChars($fileName) . '"')
85            );
86    }
87
88    protected function convertspecialchars($string)
89    {
90
91        $convert = array (
92            array ('ä','ae',),
93            array ('ö','oe',),
94            array ('ü','ue',),
95            array ('ß','ss',),
96        );
97
98
99        foreach ($convert as $array) {
100            $string = str_replace($array[0], $array[1], $string);
101        }
102        return $string;
103    }
104}