1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2018 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://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\Model\ChannelActionModel; |
||
15 | use Mautic\ChannelBundle\Model\FrequencyActionModel; |
||
16 | use Mautic\CoreBundle\Controller\AbstractFormController; |
||
17 | use Mautic\LeadBundle\Form\Type\ContactChannelsType; |
||
18 | use Mautic\LeadBundle\Model\LeadModel; |
||
19 | use Symfony\Component\HttpFoundation\JsonResponse; |
||
20 | use Symfony\Component\HttpKernel\Event\FilterControllerEvent; |
||
21 | |||
22 | class BatchContactController extends AbstractFormController |
||
23 | { |
||
24 | /** |
||
25 | * @var ChannelActionModel |
||
26 | */ |
||
27 | private $channelActionModel; |
||
28 | |||
29 | /** |
||
30 | * @var FrequencyActionModel |
||
31 | */ |
||
32 | private $frequencyActionModel; |
||
33 | |||
34 | /** |
||
35 | * @var LeadModel |
||
36 | */ |
||
37 | private $contactModel; |
||
38 | |||
39 | /** |
||
40 | * Initialize object props here to simulate constructor |
||
41 | * and make the future controller refactoring easier. |
||
42 | */ |
||
43 | public function initialize(FilterControllerEvent $event) |
||
44 | { |
||
45 | $this->channelActionModel = $this->container->get('mautic.channel.model.channel.action'); |
||
46 | $this->frequencyActionModel = $this->container->get('mautic.channel.model.frequency.action'); |
||
47 | $this->contactModel = $this->container->get('mautic.lead.model.lead'); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Execute the batch action. |
||
52 | * |
||
53 | * @return JsonResponse |
||
54 | */ |
||
55 | public function setAction() |
||
56 | { |
||
57 | $params = $this->request->get('contact_channels', []); |
||
58 | $ids = empty($params['ids']) ? [] : json_decode($params['ids']); |
||
59 | |||
60 | if ($ids && is_array($ids)) { |
||
61 | $subscribedChannels = isset($params['subscribed_channels']) ? $params['subscribed_channels'] : []; |
||
62 | $preferredChannel = isset($params['preferred_channel']) ? $params['preferred_channel'] : null; |
||
63 | |||
64 | $this->channelActionModel->update($ids, $subscribedChannels); |
||
65 | $this->frequencyActionModel->update($ids, $params, $preferredChannel); |
||
66 | |||
67 | $this->addFlash('mautic.lead.batch_leads_affected', [ |
||
0 ignored issues
–
show
|
|||
68 | 'pluralCount' => count($ids), |
||
69 | '%count%' => count($ids), |
||
70 | ]); |
||
71 | } else { |
||
72 | $this->addFlash('mautic.core.error.ids.missing'); |
||
73 | } |
||
74 | |||
75 | return new JsonResponse([ |
||
76 | 'closeModal' => true, |
||
77 | 'flashes' => $this->getFlashContent(), |
||
78 | ]); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * View for batch action. |
||
83 | * |
||
84 | * @return JsonResponse|\Symfony\Component\HttpFoundation\Response |
||
85 | */ |
||
86 | public function indexAction() |
||
87 | { |
||
88 | $route = $this->generateUrl('mautic_channel_batch_contact_set'); |
||
89 | |||
90 | return $this->delegateView([ |
||
91 | 'viewParameters' => [ |
||
92 | 'form' => $this->createForm(ContactChannelsType::class, [], [ |
||
93 | 'action' => $route, |
||
94 | 'channels' => $this->contactModel->getPreferenceChannels(), |
||
95 | 'public_view' => false, |
||
96 | 'save_button' => true, |
||
97 | ])->createView(), |
||
98 | ], |
||
99 | 'contentTemplate' => 'MauticLeadBundle:Batch:channel.html.php', |
||
100 | 'passthroughVars' => [ |
||
101 | 'activeLink' => '#mautic_contact_index', |
||
102 | 'mauticContent' => 'leadBatch', |
||
103 | 'route' => $route, |
||
104 | ], |
||
105 | ]); |
||
106 | } |
||
107 | } |
||
108 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.