Passed
Pull Request — master (#118)
by Romain
03:00
created

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