Passed
Push — master ( 22188a...e5f73b )
by Romain
02:58
created

EntityEmailNotification::isSenderCustom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
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;
18
19
use CuyZ\Notiz\Core\Notification\Creatable;
20
use CuyZ\Notiz\Core\Notification\Viewable;
21
use CuyZ\Notiz\Core\Notification\Editable;
22
use CuyZ\Notiz\Core\Notification\CustomSettingsNotification;
23
use CuyZ\Notiz\Core\Property\PropertyEntry;
24
use CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\Processor\EntityEmailNotificationProcessor;
25
use CuyZ\Notiz\Domain\Notification\Email\Application\EntityEmail\Settings\EntityEmailSettings;
26
use CuyZ\Notiz\Domain\Notification\Email\EmailNotification;
27
use CuyZ\Notiz\Domain\Notification\EntityNotification;
28
use CuyZ\Notiz\Domain\Property\Email;
29
use TYPO3\CMS\Core\Utility\GeneralUtility;
30
use TYPO3\CMS\Extbase\Service\FlexFormService;
31
32
class EntityEmailNotification extends EntityNotification implements EmailNotification, CustomSettingsNotification, Creatable, Editable, Viewable
33
{
34
    /**
35
     * @var string
36
     */
37
    protected $layout;
38
39
    /**
40
     * @var string
41
     */
42
    protected $sender;
43
44
    /**
45
     * @var bool
46
     */
47
    protected $senderCustom;
48
49
    /**
50
     * @var string
51
     */
52
    protected $sendTo;
53
54
    /**
55
     * @var string
56
     */
57
    protected $sendToProvided;
58
59
    /**
60
     * @var string
61
     */
62
    protected $sendCc;
63
64
    /**
65
     * @var string
66
     */
67
    protected $sendCcProvided;
68
69
    /**
70
     * @var string
71
     */
72
    protected $sendBcc;
73
74
    /**
75
     * @var string
76
     */
77
    protected $sendBccProvided;
78
79
    /**
80
     * @var string
81
     */
82
    protected $subject;
83
84
    /**
85
     * @var string
86
     */
87
    protected $body;
88
89
    /**
90
     * @var array
91
     */
92
    protected $bodySlots = [];
93
94
    /**
95
     * @return string
96
     */
97
    public function getLayout()
98
    {
99
        return $this->layout;
100
    }
101
102
    /**
103
     * @param string $layout
104
     */
105
    public function setLayout($layout)
106
    {
107
        $this->layout = $layout;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getSender()
114
    {
115
        return $this->sender;
116
    }
117
118
    /**
119
     * @param string $sender
120
     */
121
    public function setSender($sender)
122
    {
123
        $this->sender = $sender;
124
    }
125
126
    /**
127
     * @return bool
128
     */
129
    public function isSenderCustom()
130
    {
131
        return $this->senderCustom;
132
    }
133
134
    /**
135
     * @param bool $senderCustom
136
     */
137
    public function setSenderCustom($senderCustom)
138
    {
139
        $this->senderCustom = $senderCustom;
140
    }
141
142
    /**
143
     * @return string
144
     */
145
    public function getSendTo()
146
    {
147
        return $this->sendTo;
148
    }
149
150
    /**
151
     * @param string $sendTo
152
     */
153
    public function setSendTo($sendTo)
154
    {
155
        $this->sendTo = $sendTo;
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    public function getSendToProvided()
162
    {
163
        return $this->sendToProvided;
164
    }
165
166
    /**
167
     * @return Email[]
168
     */
169
    public function getSelectedSendToProvided()
170
    {
171
        return $this->getSelectedProvidedRecipients($this->sendToProvided);
172
    }
173
174
    /**
175
     * @param string $sendToProvided
176
     */
177
    public function setSendToProvided($sendToProvided)
178
    {
179
        $this->sendToProvided = $sendToProvided;
180
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getSendCc()
186
    {
187
        return $this->sendCc;
188
    }
189
190
    /**
191
     * @param string $sendCc
192
     */
193
    public function setSendCc($sendCc)
194
    {
195
        $this->sendCc = $sendCc;
196
    }
197
198
    /**
199
     * @return string
200
     */
201
    public function getSendCcProvided()
202
    {
203
        return $this->sendCcProvided;
204
    }
205
206
    /**
207
     * @return Email[]
208
     */
209
    public function getSelectedSendCcProvided()
210
    {
211
        return $this->getSelectedProvidedRecipients($this->sendCcProvided);
212
    }
213
214
    /**
215
     * @param string $sendCcProvided
216
     */
217
    public function setSendCcProvided($sendCcProvided)
218
    {
219
        $this->sendCcProvided = $sendCcProvided;
220
    }
221
222
    /**
223
     * @return string
224
     */
225
    public function getSendBcc()
226
    {
227
        return $this->sendBcc;
228
    }
229
230
    /**
231
     * @param string $sendBcc
232
     */
233
    public function setSendBcc($sendBcc)
234
    {
235
        $this->sendBcc = $sendBcc;
236
    }
237
238
    /**
239
     * @return string
240
     */
241
    public function getSendBccProvided()
242
    {
243
        return $this->sendBccProvided;
244
    }
245
246
    /**
247
     * @return Email[]
248
     */
249
    public function getSelectedSendBccProvided()
250
    {
251
        return $this->getSelectedProvidedRecipients($this->sendBccProvided);
252
    }
253
254
    /**
255
     * @param string $sendBccProvided
256
     */
257
    public function setSendBccProvided($sendBccProvided)
258
    {
259
        $this->sendBccProvided = $sendBccProvided;
260
    }
261
262
    /**
263
     * @return string
264
     */
265
    public function getSubject()
266
    {
267
        return $this->subject;
268
    }
269
270
    /**
271
     * @param string $subject
272
     */
273
    public function setSubject($subject)
274
    {
275
        $this->subject = $subject;
276
    }
277
278
    /**
279
     * @return string
280
     */
281
    public function getBody()
282
    {
283
        return $this->body;
284
    }
285
286
    /**
287
     * @return array
288
     */
289
    public function getBodySlots()
290
    {
291
        if (empty($this->bodySlots)) {
292
            /** @var FlexFormService $flexFormService */
293
            $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
294
295
            $this->bodySlots = $flexFormService->convertFlexFormContentToArray($this->body);
296
        }
297
298
        return $this->bodySlots;
299
    }
300
301
    /**
302
     * @param string $body
303
     */
304
    public function setBody($body)
305
    {
306
        $this->body = $body;
307
    }
308
309
    /**
310
     * @return string
311
     */
312
    public static function getProcessorClassName()
313
    {
314
        return EntityEmailNotificationProcessor::class;
315
    }
316
317
    /**
318
     * @return string
319
     */
320
    public static function getDefinitionIdentifier()
321
    {
322
        return 'entityEmail';
323
    }
324
325
    /**
326
     * @return string
327
     */
328
    public static function getSettingsClassName()
329
    {
330
        return EntityEmailSettings::class;
331
    }
332
333
    /**
334
     * @param string $providedRecipients
335
     * @return Email[]
336
     */
337
    protected function getSelectedProvidedRecipients($providedRecipients)
338
    {
339
        if (!$this->hasEventDefinition()) {
340
            return [];
341
        }
342
343
        $providedRecipients = GeneralUtility::trimExplode(',', $providedRecipients);
344
345
        return array_filter(
346
            $this->getEmailProperties(),
347
            function (Email $email) use ($providedRecipients) {
348
                return in_array($email->getName(), $providedRecipients);
349
            }
350
        );
351
    }
352
353
    /**
354
     * @return PropertyEntry[]|Email[]
355
     */
356
    protected function getEmailProperties()
357
    {
358
        return $this->getEventDefinition()
359
            ->getPropertyDefinition(Email::class, $this)
360
            ->getEntries();
361
    }
362
}
363