1 | <?php |
||
25 | class ExportService |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * Repository with registrations for the events |
||
30 | * |
||
31 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository |
||
32 | * @inject |
||
33 | */ |
||
34 | protected $registrationRepository; |
||
35 | |||
36 | /** |
||
37 | * ResourceFactory |
||
38 | * |
||
39 | * @var \TYPO3\CMS\Core\Resource\ResourceFactory |
||
40 | * @inject |
||
41 | */ |
||
42 | protected $resourceFactory = null; |
||
43 | |||
44 | /** |
||
45 | * Initiates the CSV downloads for registrations of the given event uid |
||
46 | * |
||
47 | * @param int $eventUid EventUid |
||
48 | * @param array $settings Settings |
||
49 | * |
||
50 | * @throws \RuntimeException RuntimeException |
||
51 | * @return void |
||
52 | */ |
||
53 | 2 | public function downloadRegistrationsCsv($eventUid, $settings = []) |
|
66 | |||
67 | /** |
||
68 | * Returns all Registrations for the given eventUid as a CSV string |
||
69 | * |
||
70 | * @param int $eventUid EventUid |
||
71 | * @param array $settings Settings |
||
72 | * |
||
73 | * @throws \RuntimeException RuntimeException |
||
74 | * @return string |
||
75 | */ |
||
76 | 5 | public function exportRegistrationsCsv($eventUid, $settings = []) |
|
77 | { |
||
78 | 5 | $fieldsArray = array_map('trim', explode(',', $settings['fields'])); |
|
79 | 5 | $registrations = $this->registrationRepository->findByEvent($eventUid); |
|
80 | 5 | $exportedRegistrations = GeneralUtility::csvValues($fieldsArray, |
|
81 | 5 | $settings['fieldDelimiter'], $settings['fieldQuoteCharacter']) . chr(10); |
|
82 | 5 | foreach ($registrations as $registration) { |
|
83 | 5 | $exportedRegistration = []; |
|
84 | 5 | foreach ($fieldsArray as $field) { |
|
85 | 5 | if ($registration->_hasProperty($field)) { |
|
86 | 5 | $exportedRegistration[] = $this->getFieldValue($registration, $field); |
|
87 | 5 | } else { |
|
88 | 1 | throw new RuntimeException('Field ' . $field . |
|
89 | 1 | ' is not a Property of Model Registration, please check your TS configuration', 1475590002); |
|
90 | } |
||
91 | 5 | } |
|
92 | 4 | $exportedRegistrations .= GeneralUtility::csvValues($exportedRegistration, |
|
93 | 4 | $settings['fieldDelimiter'], $settings['fieldQuoteCharacter']) . chr(10); |
|
94 | 4 | } |
|
95 | 4 | return $exportedRegistrations; |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * Returns the requested field from the given registration. If the field is a DateTime object, |
||
100 | * a formatted date string is returned |
||
101 | * |
||
102 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration |
||
103 | * @param string $field |
||
104 | * @return string |
||
105 | */ |
||
106 | 5 | protected function getFieldValue($registration, $field) |
|
114 | } |