Passed
Push — master ( 359439...6d9231 )
by Romain
03:35
created

EntityNotification::setEventConfigurationFlex()   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 1
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;
18
19
use CuyZ\Notiz\Core\Definition\DefinitionService;
20
use CuyZ\Notiz\Core\Definition\Tree\Definition;
21
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\EventDefinition;
22
use CuyZ\Notiz\Core\Definition\Tree\Notification\Channel\ChannelDefinition;
23
use CuyZ\Notiz\Core\Definition\Tree\Notification\NotificationDefinition;
24
use CuyZ\Notiz\Core\Notification\MultipleChannelsNotification;
25
use CuyZ\Notiz\Core\Notification\Notification;
26
use TYPO3\CMS\Core\Utility\GeneralUtility;
27
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
28
use TYPO3\CMS\Extbase\Service\FlexFormService;
29
30
abstract class EntityNotification extends AbstractEntity implements Notification, MultipleChannelsNotification
31
{
32
    /**
33
     * @var string
34
     */
35
    protected $title;
36
37
    /**
38
     * @var string
39
     */
40
    protected $description;
41
42
    /**
43
     * @var string
44
     */
45
    protected $event;
46
47
    /**
48
     * @var string
49
     */
50
    protected $channel;
51
52
    /**
53
     * @var string
54
     */
55
    protected $eventConfigurationFlex;
56
57
    /**
58
     * @var array
59
     */
60
    protected $eventConfiguration;
61
62
    /**
63
     * @return string
64
     */
65
    public function getTitle()
66
    {
67
        return $this->title;
68
    }
69
70
    /**
71
     * @param string $title
72
     */
73
    public function setTitle($title)
74
    {
75
        $this->title = $title;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getDescription()
82
    {
83
        return $this->description;
84
    }
85
86
    /**
87
     * @param string $description
88
     */
89
    public function setDescription($description)
90
    {
91
        $this->description = $description;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getEvent()
98
    {
99
        return $this->event;
100
    }
101
102
    /**
103
     * @param string $event
104
     */
105
    public function setEvent($event)
106
    {
107
        $this->event = $event;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getChannel()
114
    {
115
        return $this->channel;
116
    }
117
118
    /**
119
     * @param string $channel
120
     */
121
    public function setChannel($channel)
122
    {
123
        $this->channel = $channel;
124
    }
125
126
    /**
127
     * @param string $eventConfigurationFlex
128
     */
129
    public function setEventConfigurationFlex($eventConfigurationFlex)
130
    {
131
        $this->eventConfigurationFlex = $eventConfigurationFlex;
132
    }
133
134
    /**
135
     * @return NotificationDefinition
136
     */
137
    public function getNotificationDefinition()
138
    {
139
        return $this->getDefinition()->getNotification(static::getDefinitionIdentifier());
140
    }
141
142
    /**
143
     * @return EventDefinition
144
     */
145
    public function getEventDefinition()
146
    {
147
        return $this->getDefinition()->getEventFromFullIdentifier($this->getEvent());
148
    }
149
150
    /**
151
     * Returns the event configuration stored as a FlexForm string.
152
     *
153
     * @return array
154
     */
155
    public function getEventConfiguration()
156
    {
157
        if (null === $this->eventConfiguration) {
158
            /** @var FlexFormService $flexFormService */
159
            $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
160
161
            $this->eventConfiguration = $flexFormService->convertFlexFormContentToArray($this->eventConfigurationFlex);
162
        }
163
164
        return $this->eventConfiguration;
165
    }
166
167
    /**
168
     * The selected channel is stored in the `$channel` property.
169
     *
170
     * @inheritdoc
171
     */
172
    public function shouldDispatch(ChannelDefinition $definition)
173
    {
174
        return $definition->getClassName() === $this->getChannel();
175
    }
176
177
    /**
178
     * @return string
179
     */
180
    abstract public static function getDefinitionIdentifier();
181
182
    /**
183
     * @return Definition
184
     */
185
    protected function getDefinition()
186
    {
187
        return DefinitionService::get()->getDefinition();
188
    }
189
}
190