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\Slack\Application\EntitySlack\TCA; |
18
|
|
|
|
19
|
|
|
use CuyZ\Notiz\Core\Notification\Service\NotificationTcaService; |
20
|
|
|
use CuyZ\Notiz\Core\Notification\Settings\NotificationSettings; |
21
|
|
|
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\EntitySlackNotification; |
22
|
|
|
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\EntitySlackSettings; |
23
|
|
|
|
24
|
|
|
class EntitySlackTcaService extends NotificationTcaService |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Loads all bots provided by the notification and stores them as an array |
28
|
|
|
* to be used in the TCA. |
29
|
|
|
* |
30
|
|
|
* @param array $parameters |
31
|
|
|
*/ |
32
|
|
|
public function getBotsList(array &$parameters) |
33
|
|
|
{ |
34
|
|
|
if ($this->definitionHasErrors()) { |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
foreach ($this->getNotificationSettings()->getBots() as $bot) { |
|
|
|
|
39
|
|
|
$parameters['items'][] = [ |
40
|
|
|
$bot->getName(), |
41
|
|
|
$bot->getIdentifier(), |
42
|
|
|
]; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Loads all Slack channels provided by the notification and stores them as |
48
|
|
|
* an array to be used in the TCA. |
49
|
|
|
* |
50
|
|
|
* @param array $parameters |
51
|
|
|
*/ |
52
|
|
|
public function getSlackChannelsList(array &$parameters) |
53
|
|
|
{ |
54
|
|
|
if ($this->definitionHasErrors()) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
foreach ($this->getNotificationSettings()->getChannels() as $channel) { |
|
|
|
|
59
|
|
|
$parameters['items'][] = [ |
60
|
|
|
$channel->getLabel(), |
61
|
|
|
$channel->getIdentifier(), |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function hasDefinedBot() |
70
|
|
|
{ |
71
|
|
|
if ($this->definitionHasErrors()) { |
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return count($this->getNotificationSettings()->getBots()) > 0; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
|
|
public function hasNoDefinedBot() |
82
|
|
|
{ |
83
|
|
|
return !$this->hasDefinedBot(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getNoDefinedBotText() |
90
|
|
|
{ |
91
|
|
|
$view = $this->viewService->getStandaloneView('Backend/TCA/NoDefinedBotMessage'); |
92
|
|
|
|
93
|
|
|
return $view->render(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
|
|
public function hasDefinedSlackChannel() |
100
|
|
|
{ |
101
|
|
|
if ($this->definitionHasErrors()) { |
102
|
|
|
return false; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return count($this->getNotificationSettings()->getChannels()) > 0; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return bool |
110
|
|
|
*/ |
111
|
|
|
public function hasNoDefinedSlackChannel() |
112
|
|
|
{ |
113
|
|
|
return !$this->hasDefinedSlackChannel(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function getNoDefinedSlackChannelText() |
120
|
|
|
{ |
121
|
|
|
$view = $this->viewService->getStandaloneView('Backend/TCA/NoDefinedSlackChannel'); |
122
|
|
|
|
123
|
|
|
return $view->render(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return EntitySlackSettings|NotificationSettings |
128
|
|
|
*/ |
129
|
|
|
protected function getNotificationSettings() |
130
|
|
|
{ |
131
|
|
|
return $this->getNotificationDefinition()->getSettings(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
protected function getDefinitionIdentifier() |
138
|
|
|
{ |
139
|
|
|
return EntitySlackNotification::getDefinitionIdentifier(); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|