Passed
Pull Request — master (#91)
by Romain
04:18
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 $event;
41
42
    /**
43
     * @var string
44
     */
45
    protected $channel;
46
47
    /**
48
     * @var string
49
     */
50
    protected $eventConfigurationFlex;
51
52
    /**
53
     * @var array
54
     */
55
    protected $eventConfiguration;
56
57
    /**
58
     * @return string
59
     */
60
    public function getTitle()
61
    {
62
        return $this->title;
63
    }
64
65
    /**
66
     * @param string $title
67
     */
68
    public function setTitle($title)
69
    {
70
        $this->title = $title;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getEvent()
77
    {
78
        return $this->event;
79
    }
80
81
    /**
82
     * @param string $event
83
     */
84
    public function setEvent($event)
85
    {
86
        $this->event = $event;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getChannel()
93
    {
94
        return $this->channel;
95
    }
96
97
    /**
98
     * @param string $channel
99
     */
100
    public function setChannel($channel)
101
    {
102
        $this->channel = $channel;
103
    }
104
105
    /**
106
     * @param string $eventConfigurationFlex
107
     */
108
    public function setEventConfigurationFlex($eventConfigurationFlex)
109
    {
110
        $this->eventConfigurationFlex = $eventConfigurationFlex;
111
    }
112
113
    /**
114
     * @return NotificationDefinition
115
     */
116
    public function getNotificationDefinition()
117
    {
118
        return $this->getDefinition()->getNotification(static::getDefinitionIdentifier());
119
    }
120
121
    /**
122
     * @return EventDefinition
123
     */
124
    public function getEventDefinition()
125
    {
126
        return $this->getDefinition()->getEventFromFullIdentifier($this->getEvent());
127
    }
128
129
    /**
130
     * Returns the event configuration stored as a FlexForm string.
131
     *
132
     * @return array
133
     */
134
    public function getEventConfiguration()
135
    {
136
        if (null === $this->eventConfiguration) {
137
            /** @var FlexFormService $flexFormService */
138
            $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
139
140
            $this->eventConfiguration = $flexFormService->convertFlexFormContentToArray($this->eventConfigurationFlex);
141
        }
142
143
        return $this->eventConfiguration;
144
    }
145
146
    /**
147
     * The selected channel is stored in the `$channel` property.
148
     *
149
     * @inheritdoc
150
     */
151
    public function shouldDispatch(ChannelDefinition $definition)
152
    {
153
        return $definition->getClassName() === $this->getChannel();
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    abstract public static function getDefinitionIdentifier();
160
161
    /**
162
     * @return Definition
163
     */
164
    protected function getDefinition()
165
    {
166
        return DefinitionService::get()->getDefinition();
167
    }
168
}
169