1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (C) 2017 |
5
|
|
|
* Nathan Boiron <[email protected]> |
6
|
|
|
* Romain Canon <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This file is part of the TYPO3 NotiZ project. |
9
|
|
|
* It is free software; you can redistribute it and/or modify it |
10
|
|
|
* under the terms of the GNU General Public License, either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* For the full copyright and license information, see: |
14
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\Service; |
18
|
|
|
|
19
|
|
|
use CuyZ\Notiz\Channel\Payload; |
20
|
|
|
use CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\EntityEmailNotification; |
21
|
|
|
use CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\Settings\EntityEmailSettings; |
22
|
|
|
use CuyZ\Notiz\Domain\Property\Marker; |
23
|
|
|
use CuyZ\Notiz\Event\Event; |
24
|
|
|
use CuyZ\Notiz\Property\Service\MarkerParser; |
25
|
|
|
use CuyZ\Notiz\View\Slot\Service\SlotViewService; |
26
|
|
|
|
27
|
|
|
class EntityEmailTemplateBuilder |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var EntityEmailNotification |
31
|
|
|
*/ |
32
|
|
|
protected $notification; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var EntityEmailSettings |
36
|
|
|
*/ |
37
|
|
|
protected $notificationSettings; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Event |
41
|
|
|
*/ |
42
|
|
|
protected $event; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var MarkerParser |
46
|
|
|
*/ |
47
|
|
|
protected $markerParser; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Marker[] |
51
|
|
|
*/ |
52
|
|
|
protected $markers = []; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var SlotViewService |
56
|
|
|
*/ |
57
|
|
|
protected $slotViewService; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Payload $payload |
61
|
|
|
* @param MarkerParser $markerParser |
62
|
|
|
* @param SlotViewService $slotViewService |
63
|
|
|
*/ |
64
|
|
|
public function __construct(Payload $payload, MarkerParser $markerParser, SlotViewService $slotViewService) |
65
|
|
|
{ |
66
|
|
|
$this->notification = $payload->getNotification(); |
67
|
|
|
$this->notificationSettings = $payload->getNotificationDefinition()->getSettings(); |
68
|
|
|
|
69
|
|
|
$this->event = $payload->getEvent(); |
70
|
|
|
|
71
|
|
|
$this->markerParser = $markerParser; |
72
|
|
|
$this->markers = $payload->getEvent()->getProperties(Marker::class); |
73
|
|
|
|
74
|
|
|
$this->slotViewService = $slotViewService; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getSubject() |
81
|
|
|
{ |
82
|
|
|
return $this->markerParser->replaceMarkers( |
83
|
|
|
$this->notification->getSubject(), |
84
|
|
|
$this->markers |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getBody() |
92
|
|
|
{ |
93
|
|
|
$eventDefinition = $this->event->getDefinition(); |
94
|
|
|
$viewSettings = $this->notificationSettings->getView(); |
95
|
|
|
|
96
|
|
|
$view = $this->slotViewService->buildView($eventDefinition, $viewSettings); |
97
|
|
|
|
98
|
|
|
$layout = $viewSettings->getLayout($this->notification->getLayout()); |
99
|
|
|
|
100
|
|
|
$view->assign('layout', $layout->getPath()); |
101
|
|
|
$view->assign('markers', $this->markers); |
102
|
|
|
|
103
|
|
|
return $view->renderWithSlots($this->notification->getBodySlots(), $this->markers); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|