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\Api; |
13
|
|
|
|
14
|
|
|
use Mautic\ApiBundle\Controller\CommonApiController; |
15
|
|
|
use Mautic\ChannelBundle\ChannelEvents; |
16
|
|
|
use Mautic\ChannelBundle\Entity\Message; |
17
|
|
|
use Mautic\ChannelBundle\Event\ChannelEvent; |
18
|
|
|
use Symfony\Component\Form\Form; |
19
|
|
|
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class MessageController. |
23
|
|
|
*/ |
24
|
|
|
class MessageApiController extends CommonApiController |
25
|
|
|
{ |
26
|
|
|
public function initialize(FilterControllerEvent $event) |
27
|
|
|
{ |
28
|
|
|
$this->model = $this->getModel('channel.message'); |
29
|
|
|
$this->entityClass = Message::class; |
30
|
|
|
$this->entityNameOne = 'message'; |
31
|
|
|
$this->entityNameMulti = 'messages'; |
32
|
|
|
$this->serializerGroups = ['messageDetails', 'messageChannelList', 'categoryList', 'publishDetails']; |
33
|
|
|
|
34
|
|
|
parent::initialize($event); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function prepareParametersFromRequest(Form $form, array &$params, $entity = null, $masks = [], $fields = []) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
parent::prepareParametersFromRequest($form, $params, $entity, $masks); |
40
|
|
|
|
41
|
|
|
if ('PATCH' != $this->request->getMethod()) { |
42
|
|
|
$channels = $this->getModel('channel.message')->getChannels(); |
|
|
|
|
43
|
|
|
if (!isset($params['channels'])) { |
44
|
|
|
$params['channels'] = []; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
foreach ($channels as $channelType => $channel) { |
48
|
|
|
if (!isset($params['channels'][$channelType])) { |
49
|
|
|
$params['channels'][$channelType] = [ |
50
|
|
|
'isEnabled' => 0, |
51
|
|
|
'channel' => $channelType, |
52
|
|
|
]; |
53
|
|
|
} else { |
54
|
|
|
$params['channels'][$channelType]['channel'] = $channelType; |
55
|
|
|
$params['channels'][$channelType]['isEnabled'] = (int) $params['channels'][$channelType]['isEnabled']; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Load and set channel names to the response. |
63
|
|
|
* |
64
|
|
|
* @param $entity |
65
|
|
|
* @param string $action |
66
|
|
|
* |
67
|
|
|
* @return mixed |
68
|
|
|
*/ |
69
|
|
|
protected function preSerializeEntity(&$entity, $action = 'view') |
70
|
|
|
{ |
71
|
|
|
$event = $this->dispatcher->dispatch(ChannelEvents::ADD_CHANNEL, new ChannelEvent()); |
72
|
|
|
|
73
|
|
|
if ($channels = $entity->getChannels()) { |
74
|
|
|
foreach ($channels as $channel) { |
75
|
|
|
$repository = $event->getRepositoryName($channel->getChannel()); |
|
|
|
|
76
|
|
|
$nameColumn = $event->getNameColumn($channel->getChannel()); |
|
|
|
|
77
|
|
|
$name = $this->model->getChannelName($channel->getChannelId(), $repository, $nameColumn); |
|
|
|
|
78
|
|
|
$channel->setChannelName($name); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.