|
1
|
|
|
<?php |
|
2
|
|
|
namespace EWW\Dpf\Services\Email; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
use \TYPO3\CMS\Core\Log\LogLevel; |
|
18
|
|
|
use \TYPO3\CMS\Core\Log\LogManager; |
|
19
|
|
|
use \TYPO3\CMS\Core\Utility\GeneralUtility; |
|
20
|
|
|
|
|
21
|
|
|
class Notifier |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* clientRepository |
|
26
|
|
|
* |
|
27
|
|
|
* @var \EWW\Dpf\Domain\Repository\ClientRepository |
|
28
|
|
|
* @inject |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $clientRepository = null; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* documentTypeRepository |
|
35
|
|
|
* |
|
36
|
|
|
* @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
|
37
|
|
|
* @inject |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $documentTypeRepository = null; |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
public function sendNewDocumentNotification(\EWW\Dpf\Domain\Model\Document $document) |
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
|
|
try { |
|
46
|
|
|
$client = $this->clientRepository->findAll()->current(); |
|
47
|
|
|
$clientAdminEmail = $client->getAdminEmail(); |
|
48
|
|
|
$mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
|
49
|
|
|
$slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
|
50
|
|
|
$submitterEmail = $slub->getSubmitterEmail(); |
|
51
|
|
|
$documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
|
|
|
|
|
|
52
|
|
|
$authors = $document->getAuthors(); |
|
53
|
|
|
|
|
54
|
|
|
$args['###CLIENT###'] = $client->getClient(); |
|
|
|
|
|
|
55
|
|
|
$args['###PROCESS_NUMBER###'] = $document->getProcessNumber(); |
|
56
|
|
|
$args['###DOCUMENT_TYPE###'] = $documentType->getDisplayName(); |
|
|
|
|
|
|
57
|
|
|
$args['###TITLE###'] = $document->getTitle(); |
|
58
|
|
|
$args['###AUTHOR###'] = array_shift($authors); |
|
59
|
|
|
|
|
60
|
|
|
$args['###SUBMITTER_NAME###'] = $slub->getSubmitterName(); |
|
61
|
|
|
$args['###SUBMITTER_EMAIL###'] = $submitterEmail; // |
|
62
|
|
|
$args['###SUBMITTER_NOTICE###'] = $slub->getSubmitterNotice(); |
|
63
|
|
|
|
|
64
|
|
|
$args['###DATE###'] = (new \DateTime)->format("d-m-Y H:i:s"); |
|
65
|
|
|
$args['###URN###'] = $mods->getQucosaUrn(); |
|
66
|
|
|
$args['###URL###'] = 'http://nbn-resolving.de/' . $mods->getQucosaUrn(); |
|
67
|
|
|
|
|
68
|
|
|
// Notify client admin |
|
69
|
|
|
if ($clientAdminEmail) { |
|
70
|
|
|
$subject = $client->getAdminNewDocumentNotificationSubject(); |
|
71
|
|
|
$body = $client->getAdminNewDocumentNotificationBody(); |
|
72
|
|
|
$mailType = 'text/html'; |
|
73
|
|
|
|
|
74
|
|
|
if (empty($subject)) { |
|
75
|
|
|
$subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.admin.subject', 'dpf'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (empty($body)) { |
|
79
|
|
|
$body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.admin.body', 'dpf'); |
|
80
|
|
|
$mailType = 'text/plain'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
// Notify submitter |
|
89
|
|
|
if ($submitterEmail) { |
|
90
|
|
|
$subject = $client->getSubmitterNewDocumentNotificationSubject(); |
|
91
|
|
|
$body = $client->getSubmitterNewDocumentNotificationBody(); |
|
92
|
|
|
$mailType = 'text/html'; |
|
93
|
|
|
|
|
94
|
|
|
if (empty($subject)) { |
|
95
|
|
|
$subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.submitter.subject', 'dpf'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if (empty($body)) { |
|
99
|
|
|
$body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.newDocument.submitter.body', 'dpf'); |
|
100
|
|
|
$mailType = 'text/plain'; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$this->sendMail($submitterEmail, $subject, $body, $args, $mailType); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
} catch (\Exception $e) { |
|
107
|
|
|
/** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
|
108
|
|
|
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
|
109
|
|
|
|
|
110
|
|
|
$logger->log( |
|
111
|
|
|
LogLevel::ERROR, "sendNewDocumentNotification failed", |
|
112
|
|
|
array( |
|
113
|
|
|
'document' => $document |
|
114
|
|
|
) |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function sendIngestNotification(\EWW\Dpf\Domain\Model\Document $document) |
|
121
|
|
|
{ |
|
122
|
|
|
|
|
123
|
|
|
try { |
|
124
|
|
|
$client = $this->clientRepository->findAll()->current(); |
|
125
|
|
|
$clientAdminEmail = $client->getAdminEmail(); |
|
|
|
|
|
|
126
|
|
|
$mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
|
127
|
|
|
$slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
|
128
|
|
|
$submitterEmail = $slub->getSubmitterEmail(); |
|
129
|
|
|
$documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
|
130
|
|
|
$authors = $document->getAuthors(); |
|
131
|
|
|
|
|
132
|
|
|
$args['###CLIENT###'] = $client->getClient(); |
|
|
|
|
|
|
133
|
|
|
$args['###PROCESS_NUMBER###'] = $document->getProcessNumber(); |
|
134
|
|
|
$args['###DOCUMENT_TYPE###'] = $documentType->getDisplayName(); |
|
135
|
|
|
$args['###TITLE###'] = $document->getTitle(); |
|
136
|
|
|
$args['###AUTHOR###'] = array_shift($authors); |
|
137
|
|
|
|
|
138
|
|
|
$args['###SUBMITTER_NAME###'] = $slub->getSubmitterName(); |
|
139
|
|
|
$args['###SUBMITTER_EMAIL###'] = $submitterEmail; // |
|
140
|
|
|
$args['###SUBMITTER_NOTICE###'] = $slub->getSubmitterNotice(); |
|
141
|
|
|
|
|
142
|
|
|
$args['###DATE###'] = (new \DateTime)->format("d-m-Y H:i:s"); |
|
143
|
|
|
$args['###URN###'] = $mods->getQucosaUrn(); |
|
144
|
|
|
$args['###URL###'] = 'http://nbn-resolving.de/' . $mods->getQucosaUrn(); |
|
145
|
|
|
|
|
146
|
|
|
// Notify submitter |
|
147
|
|
|
if ($submitterEmail) { |
|
148
|
|
|
$subject = $client->getSubmitterIngestNotificationSubject(); |
|
149
|
|
|
$body = $client->getSubmitterIngestNotificationBody(); |
|
150
|
|
|
$mailType = 'text/html'; |
|
151
|
|
|
|
|
152
|
|
|
if (empty($subject)) { |
|
153
|
|
|
$subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.ingestDocument.submitter.subject', 'dpf'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
if (empty($body)) { |
|
157
|
|
|
$body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.ingestDocument.submitter.body', 'dpf'); |
|
158
|
|
|
$mailType = 'text/plain'; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
$this->sendMail($submitterEmail, $subject, $body, $args, $mailType); |
|
162
|
|
|
} |
|
163
|
|
|
} catch (\Exception $e) { |
|
164
|
|
|
/** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
|
165
|
|
|
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
|
166
|
|
|
|
|
167
|
|
|
$logger->log( |
|
168
|
|
|
LogLevel::ERROR, "sendIngestNotification failed", |
|
169
|
|
|
array( |
|
170
|
|
|
'document' => $document |
|
171
|
|
|
) |
|
172
|
|
|
); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function sendEmbargoNotification(\EWW\Dpf\Domain\Model\Document $document) { |
|
178
|
|
|
try { |
|
179
|
|
|
$client = $this->clientRepository->findAllByPid($document->getPid())->current(); |
|
180
|
|
|
$clientAdminEmail = $client->getAdminEmail(); |
|
181
|
|
|
$mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
|
182
|
|
|
$slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
|
183
|
|
|
$submitterEmail = $slub->getSubmitterEmail(); |
|
184
|
|
|
// $documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
|
185
|
|
|
$authors = $document->getAuthors(); |
|
186
|
|
|
|
|
187
|
|
|
$args['###CLIENT###'] = $client->getClient(); |
|
|
|
|
|
|
188
|
|
|
$args['###PROCESS_NUMBER###'] = $document->getProcessNumber(); |
|
189
|
|
|
// $args['###DOCUMENT_TYPE###'] = $documentType->getDisplayName(); |
|
190
|
|
|
$args['###TITLE###'] = $document->getTitle(); |
|
191
|
|
|
$args['###AUTHOR###'] = array_shift($authors); |
|
192
|
|
|
|
|
193
|
|
|
$args['###SUBMITTER_NAME###'] = $slub->getSubmitterName(); |
|
194
|
|
|
$args['###SUBMITTER_EMAIL###'] = $submitterEmail; // |
|
195
|
|
|
$args['###SUBMITTER_NOTICE###'] = $slub->getSubmitterNotice(); |
|
196
|
|
|
|
|
197
|
|
|
$args['###DATE###'] = (new \DateTime)->format("d-m-Y H:i:s"); |
|
198
|
|
|
$args['###URN###'] = $mods->getQucosaUrn(); |
|
199
|
|
|
$args['###URL###'] = 'http://nbn-resolving.de/' . $mods->getQucosaUrn(); |
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
// Notify client admin |
|
203
|
|
|
if ($clientAdminEmail) { |
|
204
|
|
|
|
|
205
|
|
|
$mailType = 'text/html'; |
|
206
|
|
|
|
|
207
|
|
|
if (empty($subject)) { |
|
|
|
|
|
|
208
|
|
|
$subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.document.embargo.admin.subject', 'dpf'); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
if (empty($body)) { |
|
|
|
|
|
|
212
|
|
|
$body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.document.embargo.admin.body', 'dpf'); |
|
213
|
|
|
$mailType = 'text/plain'; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
$this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
|
217
|
|
|
|
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
} catch (\Exception $e) { |
|
221
|
|
|
/** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
|
222
|
|
|
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
|
223
|
|
|
|
|
224
|
|
|
$logger->log( |
|
225
|
|
|
LogLevel::ERROR, "sendRegisterNotification failed", |
|
226
|
|
|
array( |
|
227
|
|
|
'document' => $document |
|
228
|
|
|
) |
|
229
|
|
|
); |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
public function sendRegisterNotification(\EWW\Dpf\Domain\Model\Document $document) |
|
234
|
|
|
{ |
|
235
|
|
|
|
|
236
|
|
|
try { |
|
237
|
|
|
$client = $this->clientRepository->findAll()->current(); |
|
238
|
|
|
$clientAdminEmail = $client->getAdminEmail(); |
|
239
|
|
|
$mods = new \EWW\Dpf\Helper\Mods($document->getXmlData()); |
|
240
|
|
|
$slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData()); |
|
241
|
|
|
$submitterEmail = $slub->getSubmitterEmail(); |
|
242
|
|
|
$documentType = $this->documentTypeRepository->findOneByUid($document->getDocumentType()); |
|
243
|
|
|
$authors = $document->getAuthors(); |
|
244
|
|
|
|
|
245
|
|
|
$args['###CLIENT###'] = $client->getClient(); |
|
|
|
|
|
|
246
|
|
|
$args['###PROCESS_NUMBER###'] = $document->getProcessNumber(); |
|
247
|
|
|
$args['###DOCUMENT_TYPE###'] = $documentType->getDisplayName(); |
|
248
|
|
|
$args['###TITLE###'] = $document->getTitle(); |
|
249
|
|
|
$args['###AUTHOR###'] = array_shift($authors); |
|
250
|
|
|
|
|
251
|
|
|
$args['###SUBMITTER_NAME###'] = $slub->getSubmitterName(); |
|
252
|
|
|
$args['###SUBMITTER_EMAIL###'] = $submitterEmail; // |
|
253
|
|
|
$args['###SUBMITTER_NOTICE###'] = $slub->getSubmitterNotice(); |
|
254
|
|
|
|
|
255
|
|
|
$args['###DATE###'] = (new \DateTime)->format("d-m-Y H:i:s"); |
|
256
|
|
|
$args['###URN###'] = $mods->getQucosaUrn(); |
|
257
|
|
|
$args['###URL###'] = 'http://nbn-resolving.de/' . $mods->getQucosaUrn(); |
|
258
|
|
|
|
|
259
|
|
|
|
|
260
|
|
|
// Notify client admin |
|
261
|
|
|
if ($clientAdminEmail) { |
|
262
|
|
|
$subject = $client->getAdminRegisterDocumentNotificationSubject(); |
|
263
|
|
|
$body = $client->getAdminRegisterDocumentNotificationBody(); |
|
264
|
|
|
$mailType = 'text/html'; |
|
265
|
|
|
|
|
266
|
|
|
if (empty($subject)) { |
|
267
|
|
|
$subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.registerDocument.admin.subject', 'dpf'); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
if (empty($body)) { |
|
271
|
|
|
$body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:notification.registerDocument.admin.body', 'dpf'); |
|
272
|
|
|
$mailType = 'text/plain'; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
$this->sendMail($clientAdminEmail, $subject, $body, $args, $mailType); |
|
276
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
} catch (\Exception $e) { |
|
280
|
|
|
/** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
|
281
|
|
|
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
|
282
|
|
|
|
|
283
|
|
|
$logger->log( |
|
284
|
|
|
LogLevel::ERROR, "sendRegisterNotification failed", |
|
285
|
|
|
array( |
|
286
|
|
|
'document' => $document |
|
287
|
|
|
) |
|
288
|
|
|
); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
protected function replaceMarkers($message, $args) |
|
294
|
|
|
{ |
|
295
|
|
|
if (is_array($args)) { |
|
296
|
|
|
foreach ($args as $key => $value) { |
|
297
|
|
|
$message = str_replace($key, $value, $message); |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
return $message; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
protected function sendMail($reveiver, $subject, $body, $args, $mailType) |
|
305
|
|
|
{ |
|
306
|
|
|
$emailReceiver = array(); |
|
307
|
|
|
$emailReceiver[$reveiver] = $reveiver; |
|
308
|
|
|
$message = (new \TYPO3\CMS\Core\Mail\MailMessage()) |
|
309
|
|
|
->setFrom(array('[email protected]' => '[email protected]')) |
|
310
|
|
|
->setTo($emailReceiver) |
|
311
|
|
|
->setSubject($this->replaceMarkers($subject,$args)) |
|
312
|
|
|
->setBody($this->replaceMarkers($body,$args),$mailType); |
|
313
|
|
|
$message->send(); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
} |
|
317
|
|
|
|