Completed
Push — master ( 17edcb...7372de )
by Torben
06:23
created

NotificationService   F

Complexity

Total Complexity 61

Size/Duplication

Total Lines 533
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 17

Test Coverage

Coverage 94.27%

Importance

Changes 0
Metric Value
wmc 61
lcom 2
cbo 17
dl 0
loc 533
ccs 148
cts 157
cp 0.9427
rs 3.52
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A injectAttachmentService() 0 5 1
A injectCustomNotificationLogRepository() 0 5 1
A injectEmailService() 0 4 1
A injectFluidStandaloneService() 0 5 1
A injectHashService() 0 4 1
A injectObjectManager() 0 4 1
A injectRegistrationRepository() 0 5 1
A injectEventDispatcher() 0 4 1
A sendCustomNotification() 0 31 4
A cantSendCustomNotification() 0 5 4
A createCustomNotificationLogentry() 0 10 1
C sendUserMessage() 0 100 10
B getUserMessageTemplateSubject() 0 46 10
C sendAdminMessage() 0 72 14
B getAdminMessageTemplateSubject() 0 34 7
A getNotificationBody() 0 17 3

How to fix   Complexity   

Complex Class

Complex classes like NotificationService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use NotificationService, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.txt file that was distributed with this source code.
8
 */
9
10
namespace DERHANSEN\SfEventMgt\Service;
11
12
use DERHANSEN\SfEventMgt\Domain\Model\Dto\CustomNotification;
13
use DERHANSEN\SfEventMgt\Domain\Model\Event;
14
use DERHANSEN\SfEventMgt\Event\AfterAdminMessageSentEvent;
15
use DERHANSEN\SfEventMgt\Event\AfterUserMessageSentEvent;
16
use DERHANSEN\SfEventMgt\Event\ModifyUserMessageAttachmentsEvent;
17
use DERHANSEN\SfEventMgt\Event\ModifyUserMessageSenderEvent;
18
use DERHANSEN\SfEventMgt\Utility\MessageRecipient;
19
use DERHANSEN\SfEventMgt\Utility\MessageType;
20
use Psr\EventDispatcher\EventDispatcherInterface;
21
use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23
/**
24
 * NotificationService
25
 *
26
 * @author Torben Hansen <[email protected]>
27
 */
28
class NotificationService
29
{
30
    /**
31
     * The object manager
32
     *
33
     * @var \TYPO3\CMS\Extbase\Object\ObjectManager
34
     */
35
    protected $objectManager;
36
37
    /**
38
     * Registration repository
39
     *
40
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository
41
     */
42
    protected $registrationRepository;
43
44
    /**
45
     * Email Service
46
     *
47
     * @var \DERHANSEN\SfEventMgt\Service\EmailService
48
     */
49
    protected $emailService;
50
51
    /**
52
     * Hash Service
53
     *
54
     * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService
55
     */
56
    protected $hashService;
57
58
    /**
59
     * FluidStandaloneService
60
     *
61
     * @var \DERHANSEN\SfEventMgt\Service\FluidStandaloneService
62
     */
63
    protected $fluidStandaloneService;
64
65
    /**
66
     * CustomNotificationLogRepository
67
     *
68
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository
69
     */
70
    protected $customNotificationLogRepository;
71
72
    /**
73
     * AttachmentService
74
     *
75
     * @var \DERHANSEN\SfEventMgt\Service\Notification\AttachmentService
76
     */
77
    protected $attachmentService;
78
79
    /**
80
     * @var EventDispatcherInterface
81
     */
82
    protected $eventDispatcher;
83
84
    /**
85
     * DI for $attachmentService
86
     *
87
     * @param Notification\AttachmentService $attachmentService
88
     */
89
    public function injectAttachmentService(
90
        \DERHANSEN\SfEventMgt\Service\Notification\AttachmentService $attachmentService
91
    ) {
92
        $this->attachmentService = $attachmentService;
93
    }
94
95 8
    /**
96
     * DI for $customNotificationLogRepository
97 8
     *
98 2
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository
99
     */
100 6
    public function injectCustomNotificationLogRepository(
101
        \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository
102 6
    ) {
103 6
        $this->customNotificationLogRepository = $customNotificationLogRepository;
104 6
    }
105
106 6
    /**
107 2
     * DI for $emailService
108 2
     *
109 2
     * @param EmailService $emailService
110 2
     */
111 2
    public function injectEmailService(\DERHANSEN\SfEventMgt\Service\EmailService $emailService)
112
    {
113 2
        $this->emailService = $emailService;
114 2
    }
115 2
116 2
    /**
117 2
     * DI for $fluidStandaloneService
118 6
     *
119 6
     * @param FluidStandaloneService $fluidStandaloneService
120
     */
121
    public function injectFluidStandaloneService(
122
        \DERHANSEN\SfEventMgt\Service\FluidStandaloneService $fluidStandaloneService
123
    ) {
124
        $this->fluidStandaloneService = $fluidStandaloneService;
125
    }
126
127
    /**
128
     * DI for $hashService
129
     *
130
     * @param \TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService
131 8
     */
132
    public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService)
133 8
    {
134
        $this->hashService = $hashService;
135
    }
136
137
    /**
138
     * DI for $objectManager
139
     *
140
     * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
141
     */
142
    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
143
    {
144
        $this->objectManager = $objectManager;
145 2
    }
146
147 2
    /**
148 2
     * DI for $registrationRepository
149 2
     *
150 2
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository $registrationRepository
151 2
     */
152 2
    public function injectRegistrationRepository(
153 2
        \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository $registrationRepository
154
    ) {
155
        $this->registrationRepository = $registrationRepository;
156
    }
157
158
    /**
159
     * @param EventDispatcherInterface $eventDispatcher
160
     */
161
    public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher)
162
    {
163
        $this->eventDispatcher = $eventDispatcher;
164
    }
165
166 34
    /**
167
     * Sends a custom notification defined by the given customNotification key
168 34
     * to all confirmed users of the event
169
     *
170 34
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event
171 4
     * @param CustomNotification $customNotification
172
     * @param array $settings Settings
173
     *
174 30
     * @return int Number of notifications sent
175 20
     */
176 20
    public function sendCustomNotification(Event $event, CustomNotification $customNotification, array $settings = [])
177 20
    {
178 20
        if ($this->cantSendCustomNotification($event, $settings, $customNotification)) {
179 20
            return 0;
180
        }
181 20
        $count = 0;
182 20
183 20
        $customNotificationSettings = $settings['notification']['customNotifications'];
184 20
        $constraints = $customNotificationSettings[$customNotification->getTemplate()]['constraints'] ?? [];
185 20
        $registrations = $this->registrationRepository->findNotificationRegistrations(
186 20
            $event,
187 20
            $customNotification,
188
            $constraints
189 20
        );
190
191 10
        foreach ($registrations as $registration) {
192
            /** @var \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration */
193
            $result = $this->sendUserMessage(
194
                $event,
195
                $registration,
196
                $settings,
197
                MessageType::CUSTOM_NOTIFICATION,
198
                $customNotification
199
            );
200
            if ($result) {
201
                $count += 1;
202 34
            }
203
        }
204 34
205 34
        return $count;
206
    }
207 34
208 6
    /**
209 6
     * Returns true if conditions are not met to send a custom notification
210 6
     *
211 28
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event
212 6
     * @param array $settings
213 6
     * @param CustomNotification $customNotification
214 6
     *
215 22
     * @return bool
216 6
     */
217 6
    protected function cantSendCustomNotification($event, $settings, $customNotification)
218 6
    {
219 16
        return is_null($event) || $customNotification === null || $customNotification->getTemplate() === '' ||
220
            empty($settings);
221
    }
222
223 16
    /**
224 2
     * Adds a logentry to the custom notification log
225 2
     *
226 2
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
227 14
     * @param string $details Details
228 14
     * @param int $emailsSent E-Mails sent
229 14
     */
230
    public function createCustomNotificationLogentry($event, $details, $emailsSent)
231 34
    {
232
        $notificationlogEntry = new \DERHANSEN\SfEventMgt\Domain\Model\CustomNotificationLog();
233 34
        $notificationlogEntry->setPid($event->getPid());
234
        $notificationlogEntry->setEvent($event);
235
        $notificationlogEntry->setDetails($details);
236
        $notificationlogEntry->setEmailsSent($emailsSent);
237
        $notificationlogEntry->setCruserId($GLOBALS['BE_USER']->user['uid']);
238
        $this->customNotificationLogRepository->add($notificationlogEntry);
239
    }
240
241
    /**
242
     * Sends a message to the user based on the given type
243
     *
244
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
245
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
246 52
     * @param array $settings Settings
247
     * @param int $type Type
248 52
     * @param CustomNotification $customNotification
249
     *
250
     * @return bool TRUE if successful, else FALSE
251 52
     */
252 50
    public function sendUserMessage($event, $registration, $settings, $type, $customNotification = null)
253 52
    {
254 12
        list($template, $subject) = $this->getUserMessageTemplateSubject(
255
            $settings,
256
            $type,
257 40
            $customNotification
258 40
        );
259 40
260 40
        if (is_null($event) || is_null($registration) || is_null($type) || !is_array($settings) ||
261 40
            (substr($template, -5) != '.html') || (bool)$settings['notification']['disabled']
262 40
        ) {
263
            return false;
264 40
        }
265 40
266 30
        $additionalBodyVariables = [
267 30
            'customNotification' => $customNotification
268 30
        ];
269 30
270 30
        if (!$registration->isIgnoreNotifications()) {
271 30
            $body = $this->getNotificationBody($event, $registration, $template, $settings, $additionalBodyVariables);
272 30
            $subject = $this->fluidStandaloneService->parseStringFluid(
273 30
                $subject,
274
                [
275 30
                    'event' => $event,
276 30
                    'registration' => $registration
277 30
                ]
278 40
            );
279 10
            $attachments = $this->attachmentService->getAttachments(
280 10
                $settings,
281 10
                $registration,
282 10
                $type,
283 10
                MessageRecipient::USER
284 10
            );
285
286 10
            // Get iCal attachment if configured
287 10
            $iCalAttachment = $this->attachmentService->getICalAttachment(
288 40
                $settings,
289
                $registration,
290
                $type,
291
                MessageRecipient::USER
292
            );
293
294
            if ($iCalAttachment !== '') {
295
                $attachments[] = $iCalAttachment;
296
            }
297
298 52
            $modifyUserMessageSenderEvent = new ModifyUserMessageSenderEvent(
299
                $settings['notification']['senderName'] ?? '',
300 52
                $settings['notification']['senderEmail'] ?? '',
301 52
                $settings['notification']['replyToEmail'] ?? '',
302
                $registration,
303 52
                $type,
304 10
                $this
305 10
            );
306 10
            $this->eventDispatcher->dispatch($modifyUserMessageSenderEvent);
0 ignored issues
show
Documentation introduced by
$modifyUserMessageSenderEvent is of type object<DERHANSEN\SfEvent...UserMessageSenderEvent>, but the function expects a object<Psr\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
307 42
            $senderName = $modifyUserMessageSenderEvent->getSenderName();
308 10
            $senderEmail = $modifyUserMessageSenderEvent->getSenderEmail();
309 10
            $replyToEmail = $modifyUserMessageSenderEvent->getReplyToEmail();
310 10
311 32
            $modifyUserAttachmentsEvent = new ModifyUserMessageAttachmentsEvent(
312 10
                $attachments,
313 10
                $registration,
314 10
                $type,
315 22
                $this
316
            );
317
            $this->eventDispatcher->dispatch($modifyUserAttachmentsEvent);
0 ignored issues
show
Documentation introduced by
$modifyUserAttachmentsEvent is of type object<DERHANSEN\SfEvent...essageAttachmentsEvent>, but the function expects a object<Psr\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
318
            $attachments = $modifyUserAttachmentsEvent->getAttachments();
319 22
320 22
            $result = $this->emailService->sendEmailMessage(
321 22
                $senderEmail,
322
                $registration->getEmail(),
323 52
                $subject,
324
                $body,
325 52
                $senderName,
326
                $attachments,
327
                $replyToEmail
328
            );
329
330
            $afterUserMessageSentEvent = new AfterUserMessageSentEvent(
331
                $registration,
332
                $body,
333
                $subject,
334
                $attachments,
335
                $senderName,
336
                $senderEmail,
337
                $replyToEmail,
338 60
                $this
339
            );
340
            $this->eventDispatcher->dispatch($afterUserMessageSentEvent);
0 ignored issues
show
Documentation introduced by
$afterUserMessageSentEvent is of type object<DERHANSEN\SfEvent...erUserMessageSentEvent>, but the function expects a object<Psr\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
341 60
342 60
            // Cleanup iCal attachment if available
343 60
            if ($iCalAttachment !== '') {
344 60
                \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($iCalAttachment);
345
            }
346 60
347
            return $result;
348
        }
349
350
        return false;
351
    }
352 60
353 60
    /**
354 60
     * Returns an array with template and subject for the user message
355 60
     *
356 60
     * @param array $settings
357 60
     * @param int $type Type
358 60
     * @param CustomNotification $customNotification
359 60
     * @return array
360 60
     */
361 60
    protected function getUserMessageTemplateSubject($settings, $type, $customNotification = null)
362 60
    {
363 60
        switch ($type) {
364
            case MessageType::REGISTRATION_NEW:
365
                $template = 'Notification/User/RegistrationNew.html';
366
                $subject = $settings['notification']['registrationNew']['userSubject'];
367
                break;
368
            case MessageType::REGISTRATION_WAITLIST_NEW:
369
                $template = 'Notification/User/RegistrationWaitlistNew.html';
370
                $subject = $settings['notification']['registrationWaitlistNew']['userSubject'];
371
                break;
372
            case MessageType::REGISTRATION_CONFIRMED:
373
                $template = 'Notification/User/RegistrationConfirmed.html';
374
                $subject = $settings['notification']['registrationConfirmed']['userSubject'];
375
                break;
376
            case MessageType::REGISTRATION_WAITLIST_CONFIRMED:
377
                $template = 'Notification/User/RegistrationWaitlistConfirmed.html';
378
                $subject = $settings['notification']['registrationWaitlistConfirmed']['userSubject'];
379
                break;
380
            case MessageType::REGISTRATION_CANCELLED:
381
                $template = 'Notification/User/RegistrationCancelled.html';
382
                $subject = $settings['notification']['registrationCancelled']['userSubject'];
383
                break;
384
            case MessageType::REGISTRATION_WAITLIST_MOVE_UP:
385
                $template = 'Notification/User/RegistrationWaitlistMoveUp.html';
386
                $subject = $settings['notification']['registrationWaitlistMoveUp']['userSubject'];
387
                break;
388
            case MessageType::CUSTOM_NOTIFICATION && $customNotification:
389
                $customNotificationSettings = $settings['notification']['customNotifications'];
390
                $templateKey = $customNotification->getTemplate();
0 ignored issues
show
Bug introduced by
It seems like $customNotification is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
391
                $template = 'Notification/User/Custom/' . $customNotificationSettings[$templateKey]['template'];
392
                $subject = $customNotificationSettings[$templateKey]['subject'];
393
                if ($customNotification->getOverwriteSubject() !== '') {
394
                    $subject = $customNotification->getOverwriteSubject();
395
                }
396
                break;
397
            default:
398
                $template = '';
399
                $subject = '';
400
        }
401
402
        return [
403
            $template,
404
            $subject
405
        ];
406
    }
407
408
    /**
409
     * Sends a message to the admin based on the given type
410
     *
411
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
412
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
413
     * @param array $settings Settings
414
     * @param int $type Type
415
     *
416
     * @return bool TRUE if successful, else FALSE
417
     */
418
    public function sendAdminMessage($event, $registration, $settings, $type)
419
    {
420
        list($template, $subject) = $this->getAdminMessageTemplateSubject($settings, $type);
421
422
        if (is_null($event) || is_null($registration || !is_array($settings)) ||
423
            ($event->getNotifyAdmin() === false && $event->getNotifyOrganisator() === false) ||
424
            (bool)$settings['notification']['disabled']
425
        ) {
426
            return false;
427
        }
428
429
        $allEmailsSent = true;
430
        $body = $this->getNotificationBody($event, $registration, $template, $settings);
431
        $subject = $this->fluidStandaloneService->parseStringFluid(
432
            $subject,
433
            [
434
                'event' => $event,
435
                'registration' => $registration
436
            ]
437
        );
438
        $attachments = $this->attachmentService->getAttachments(
439
            $settings,
440
            $registration,
441
            $type,
442
            MessageRecipient::ADMIN
443
        );
444
445
        $senderName = $settings['notification']['senderName'];
446
        $senderEmail = $settings['notification']['senderEmail'];
447
        if ((bool)$settings['notification']['registrationDataAsSenderForAdminEmails']) {
448
            $senderName = $registration->getFullname();
449
            $senderEmail = $registration->getEmail();
450
        }
451
452
        if ($event->getNotifyAdmin()) {
453
            $adminEmailArr = GeneralUtility::trimExplode(',', $settings['notification']['adminEmail'], true);
454
            foreach ($adminEmailArr as $adminEmail) {
455
                $allEmailsSent = $allEmailsSent && $this->emailService->sendEmailMessage(
456
                    $senderEmail,
457
                    $adminEmail,
458
                    $subject,
459
                    $body,
460
                    $senderName,
461
                    $attachments
462
                );
463
            }
464
        }
465
466
        if ($event->getNotifyOrganisator() && $event->getOrganisator()) {
467
            $allEmailsSent = $allEmailsSent && $this->emailService->sendEmailMessage(
468
                $senderEmail,
469
                $event->getOrganisator()->getEmail(),
470
                $subject,
471
                $body,
472
                $senderName,
473
                $attachments
474
            );
475
        }
476
477
        $afterAdminMessageSentEvent = new AfterAdminMessageSentEvent(
478
            $registration,
479
            $body,
480
            $subject,
481
            $attachments,
482
            $senderName,
483
            $senderEmail,
484
            $this
485
        );
486
        $this->eventDispatcher->dispatch($afterAdminMessageSentEvent);
0 ignored issues
show
Documentation introduced by
$afterAdminMessageSentEvent is of type object<DERHANSEN\SfEvent...rAdminMessageSentEvent>, but the function expects a object<Psr\EventDispatcher\object>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
487
488
        return $allEmailsSent;
489
    }
490
491
    /**
492
     * Returns an array with template and subject for the admin message
493
     *
494
     * @param array $settings
495
     * @param int $type Type
496
     * @return array
497
     */
498
    protected function getAdminMessageTemplateSubject($settings, $type)
499
    {
500
        $template = 'Notification/Admin/RegistrationNew.html';
501
        $subject = $settings['notification']['registrationNew']['adminSubject'];
502
        switch ($type) {
503
            case MessageType::REGISTRATION_WAITLIST_NEW:
504
                $template = 'Notification/Admin/RegistrationWaitlistNew.html';
505
                $subject = $settings['notification']['registrationWaitlistNew']['adminSubject'];
506
                break;
507
            case MessageType::REGISTRATION_CONFIRMED:
508
                $template = 'Notification/Admin/RegistrationConfirmed.html';
509
                $subject = $settings['notification']['registrationConfirmed']['adminSubject'];
510
                break;
511
            case MessageType::REGISTRATION_WAITLIST_CONFIRMED:
512
                $template = 'Notification/Admin/RegistrationWaitlistConfirmed.html';
513
                $subject = $settings['notification']['registrationWaitlistConfirmed']['adminSubject'];
514
                break;
515
            case MessageType::REGISTRATION_CANCELLED:
516
                $template = 'Notification/Admin/RegistrationCancelled.html';
517
                $subject = $settings['notification']['registrationCancelled']['adminSubject'];
518
                break;
519
            case MessageType::REGISTRATION_WAITLIST_MOVE_UP:
520
                $template = 'Notification/Admin/RegistrationWaitlistMoveUp.html';
521
                $subject = $settings['notification']['registrationWaitlistMoveUp']['adminSubject'];
522
                break;
523
            case MessageType::REGISTRATION_NEW:
524
            default:
525
        }
526
527
        return [
528
            $template,
529
            $subject
530
        ];
531
    }
532
533
    /**
534
     * Returns the rendered HTML for the given template
535
     *
536
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
537
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
538
     * @param string $template Template
539
     * @param array $settings Settings
540
     * @param array $additionalBodyVariables
541
     * @return string
542
     */
543
    protected function getNotificationBody($event, $registration, $template, $settings, $additionalBodyVariables = [])
544
    {
545
        if (TYPO3_MODE === 'BE' && $registration->getLanguage() !== '') {
546
            // Temporary set Language of current BE user to given language
547
            $GLOBALS['BE_USER']->uc['lang'] = $registration->getLanguage();
548
        }
549
        $defaultVariables = [
550
            'event' => $event,
551
            'registration' => $registration,
552
            'settings' => $settings,
553
            'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid()),
554
            'reghmac' => $this->hashService->appendHmac((string)$registration->getUid())
555
        ];
556
        $variables = array_merge($additionalBodyVariables, $defaultVariables);
557
558
        return $this->fluidStandaloneService->renderTemplate($template, $variables);
559
    }
560
}
561