1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* @copyright 2016 Mautic Contributors. All rights reserved |
5
|
|
|
* @author Mautic, Inc. |
6
|
|
|
* |
7
|
|
|
* @link https://mautic.org |
8
|
|
|
* |
9
|
|
|
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mautic\ChannelBundle\Controller; |
13
|
|
|
|
14
|
|
|
use Mautic\ChannelBundle\Entity\Channel; |
15
|
|
|
use Mautic\ChannelBundle\Model\MessageModel; |
16
|
|
|
use Mautic\CoreBundle\Controller\AbstractStandardFormController; |
17
|
|
|
use Mautic\CoreBundle\Helper\Chart\LineChart; |
18
|
|
|
use Mautic\LeadBundle\Controller\EntityContactsTrait; |
19
|
|
|
use Symfony\Component\Form\Form; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class MessageController. |
23
|
|
|
*/ |
24
|
|
|
class MessageController extends AbstractStandardFormController |
25
|
|
|
{ |
26
|
|
|
use EntityContactsTrait; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
30
|
|
|
*/ |
31
|
|
|
public function batchDeleteAction() |
32
|
|
|
{ |
33
|
|
|
return $this->batchDeleteStandard(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param $objectId |
38
|
|
|
* |
39
|
|
|
* @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
public function cloneAction($objectId) |
42
|
|
|
{ |
43
|
|
|
return $this->cloneStandard($objectId); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param $objectId |
48
|
|
|
* @param bool $ignorePost |
49
|
|
|
* |
50
|
|
|
* @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse |
51
|
|
|
*/ |
52
|
|
|
public function editAction($objectId, $ignorePost = false) |
53
|
|
|
{ |
54
|
|
|
return $this->editStandard($objectId, $ignorePost); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param int $page |
59
|
|
|
* |
60
|
|
|
* @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
61
|
|
|
*/ |
62
|
|
|
public function indexAction($page = 1) |
63
|
|
|
{ |
64
|
|
|
return $this->indexStandard($page); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return \Mautic\CoreBundle\Controller\Response|\Symfony\Component\HttpFoundation\JsonResponse |
69
|
|
|
*/ |
70
|
|
|
public function newAction() |
71
|
|
|
{ |
72
|
|
|
return $this->newStandard(); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param $objectId |
77
|
|
|
* |
78
|
|
|
* @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
79
|
|
|
*/ |
80
|
|
|
public function viewAction($objectId) |
81
|
|
|
{ |
82
|
|
|
return $this->viewStandard($objectId, 'message', 'channel'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $args |
87
|
|
|
* @param $action |
88
|
|
|
* |
89
|
|
|
* @return mixed |
90
|
|
|
*/ |
91
|
|
|
protected function getViewArguments(array $args, $action) |
92
|
|
|
{ |
93
|
|
|
/** @var MessageModel $model */ |
94
|
|
|
$model = $this->getModel($this->getModelName()); |
95
|
|
|
$viewParameters = []; |
96
|
|
|
switch ($action) { |
97
|
|
|
case 'index': |
98
|
|
|
$viewParameters = [ |
99
|
|
|
'headerTitle' => $this->get('translator')->trans('mautic.channel.messages'), |
100
|
|
|
'listHeaders' => [ |
101
|
|
|
[ |
102
|
|
|
'text' => 'mautic.core.channels', |
103
|
|
|
'class' => 'visible-md visible-lg', |
104
|
|
|
], |
105
|
|
|
], |
106
|
|
|
'listItemTemplate' => 'MauticChannelBundle:Message:list_item.html.php', |
107
|
|
|
'enableCloneButton' => true, |
108
|
|
|
]; |
109
|
|
|
|
110
|
|
|
break; |
111
|
|
|
case 'view': |
112
|
|
|
$message = $args['viewParameters']['item']; |
113
|
|
|
|
114
|
|
|
// Init the date range filter form |
115
|
|
|
$returnUrl = $this->generateUrl( |
116
|
|
|
'mautic_message_action', |
117
|
|
|
[ |
118
|
|
|
'objectAction' => 'view', |
119
|
|
|
'objectId' => $message->getId(), |
120
|
|
|
] |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
list($dateFrom, $dateTo) = $this->getViewDateRange($message->getId(), $returnUrl, 'local', $dateRangeForm); |
124
|
|
|
$chart = new LineChart(null, $dateFrom, $dateTo); |
125
|
|
|
|
126
|
|
|
/** @var Channel[] $channels */ |
127
|
|
|
$channels = $model->getChannels(); |
128
|
|
|
$messageChannels = $message->getChannels(); |
129
|
|
|
$chart->setDataset( |
130
|
|
|
$this->get('translator')->trans('mautic.core.all'), |
131
|
|
|
$model->getLeadStatsPost($message->getId(), $dateFrom, $dateTo) |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
$messagedLeads = [ |
135
|
|
|
'all' => $this->forward( |
136
|
|
|
'MauticChannelBundle:Message:contacts', |
137
|
|
|
[ |
138
|
|
|
'objectId' => $message->getId(), |
139
|
|
|
'page' => $this->get('session')->get('mautic.'.$this->getSessionBase('all').'.contact.page', 1), |
140
|
|
|
'ignoreAjax' => true, |
141
|
|
|
'channel' => 'all', |
142
|
|
|
] |
143
|
|
|
)->getContent(), |
144
|
|
|
]; |
145
|
|
|
|
146
|
|
|
foreach ($messageChannels as $channel) { |
147
|
|
|
if ($channel->isEnabled() && isset($channels[$channel->getChannel()])) { |
148
|
|
|
$chart->setDataset( |
149
|
|
|
$channels[$channel->getChannel()]['label'], |
150
|
|
|
$model->getLeadStatsPost($message->getId(), $dateFrom, $dateTo, $channel->getChannel()) |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
$messagedLeads[$channel->getChannel()] = $this->forward( |
154
|
|
|
'MauticChannelBundle:Message:contacts', |
155
|
|
|
[ |
156
|
|
|
'objectId' => $message->getId(), |
157
|
|
|
'page' => $this->get('session')->get( |
158
|
|
|
'mautic.'.$this->getSessionBase($channel->getChannel()).'.contact.page', |
159
|
|
|
1 |
160
|
|
|
), |
161
|
|
|
'ignoreAjax' => true, |
162
|
|
|
'channel' => $channel->getChannel(), |
163
|
|
|
] |
164
|
|
|
)->getContent(); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$viewParameters = [ |
169
|
|
|
'channels' => $channels, |
170
|
|
|
'channelContents' => $model->getMessageChannels($message->getId()), |
171
|
|
|
'dateRangeForm' => $dateRangeForm->createView(), |
172
|
|
|
'eventCounts' => $chart->render(), |
173
|
|
|
'messagedLeads' => $messagedLeads, |
174
|
|
|
]; |
175
|
|
|
break; |
176
|
|
|
case 'new': |
177
|
|
|
case 'edit': |
178
|
|
|
$viewParameters = [ |
179
|
|
|
'channels' => $model->getChannels(), |
180
|
|
|
]; |
181
|
|
|
|
182
|
|
|
break; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$args['viewParameters'] = array_merge($args['viewParameters'], $viewParameters); |
186
|
|
|
|
187
|
|
|
return $args; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param $objectId |
192
|
|
|
* |
193
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse |
194
|
|
|
*/ |
195
|
|
|
protected function deleteAction($objectId) |
196
|
|
|
{ |
197
|
|
|
return $this->deleteStandard($objectId); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* {@inheritdoc} |
202
|
|
|
*/ |
203
|
|
|
protected function getControllerBase() |
204
|
|
|
{ |
205
|
|
|
return 'MauticChannelBundle:Message'; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param $view |
210
|
|
|
* |
211
|
|
|
* @return \Symfony\Component\Form\FormView |
212
|
|
|
*/ |
213
|
|
|
protected function getFormView(Form $form, $view) |
214
|
|
|
{ |
215
|
|
|
$themes = ['MauticChannelBundle:FormTheme']; |
216
|
|
|
/** @var MessageModel $model */ |
217
|
|
|
$model = $this->getModel($this->getModelName()); |
218
|
|
|
$channels = $model->getChannels(); |
219
|
|
|
foreach ($channels as $channel) { |
220
|
|
|
if (isset($channel['formTheme'])) { |
221
|
|
|
$themes[] = $channel['formTheme']; |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
return $this->setFormTheme($form, 'MauticChannelBundle:Message:form.html.php', $themes); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* {@inheritdoc} |
230
|
|
|
*/ |
231
|
|
|
protected function getJsLoadMethodPrefix() |
232
|
|
|
{ |
233
|
|
|
return 'messages'; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* {@inheritdoc} |
238
|
|
|
*/ |
239
|
|
|
protected function getModelName() |
240
|
|
|
{ |
241
|
|
|
return 'channel.message'; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* {@inheritdoc} |
246
|
|
|
*/ |
247
|
|
|
protected function getRouteBase() |
248
|
|
|
{ |
249
|
|
|
return 'message'; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/*** |
253
|
|
|
* @param null $objectId |
254
|
|
|
* |
255
|
|
|
* @return string |
256
|
|
|
*/ |
257
|
|
|
protected function getSessionBase($objectId = null) |
258
|
|
|
{ |
259
|
|
|
return 'message'.(($objectId) ? '.'.$objectId : ''); |
|
|
|
|
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* {@inheritdoc} |
264
|
|
|
*/ |
265
|
|
|
protected function getTranslationBase() |
266
|
|
|
{ |
267
|
|
|
return 'mautic.channel.message'; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @param $objectId |
272
|
|
|
* @param int $page |
273
|
|
|
* |
274
|
|
|
* @return JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response |
|
|
|
|
275
|
|
|
*/ |
276
|
|
|
public function contactsAction($objectId, $channel, $page = 1) |
277
|
|
|
{ |
278
|
|
|
$filter = []; |
279
|
|
|
if ('all' !== $channel) { |
280
|
|
|
$returnUrl = $this->generateUrl( |
281
|
|
|
'mautic_message_action', |
282
|
|
|
[ |
283
|
|
|
'objectAction' => 'view', |
284
|
|
|
'objectId' => $objectId, |
285
|
|
|
] |
286
|
|
|
); |
287
|
|
|
list($dateFrom, $dateTo) = $this->getViewDateRange($objectId, $returnUrl, 'UTC'); |
288
|
|
|
|
289
|
|
|
$filter = [ |
290
|
|
|
'channel' => $channel, |
291
|
|
|
[ |
292
|
|
|
'col' => 'entity.date_triggered', |
293
|
|
|
'expr' => 'between', |
294
|
|
|
'val' => [ |
295
|
|
|
$dateFrom->format('Y-m-d H:i:s'), |
296
|
|
|
$dateTo->format('Y-m-d H:i:s'), |
297
|
|
|
], |
298
|
|
|
], |
299
|
|
|
]; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
return $this->generateContactsGrid( |
|
|
|
|
303
|
|
|
$objectId, |
304
|
|
|
$page, |
305
|
|
|
'channel:messages:view', |
306
|
|
|
'message.'.$channel, |
307
|
|
|
'campaign_lead_event_log', |
308
|
|
|
$channel, |
309
|
|
|
null, |
310
|
|
|
$filter, |
311
|
|
|
[ |
312
|
|
|
[ |
313
|
|
|
'type' => 'join', |
314
|
|
|
'from_alias' => 'entity', |
315
|
|
|
'table' => 'campaign_events', |
316
|
|
|
'alias' => 'event', |
317
|
|
|
'condition' => "entity.event_id = event.id and event.channel = 'channel.message' and event.channel_id = ".(int) $objectId, |
318
|
|
|
], |
319
|
|
|
], |
320
|
|
|
null, |
321
|
|
|
[ |
322
|
|
|
'channel' => ($channel) ? $channel : 'all', |
323
|
|
|
], |
324
|
|
|
'.message-'.$channel |
325
|
|
|
); |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths