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\LeadBundle\Controller; |
||||
13 | |||||
14 | use Mautic\CoreBundle\Controller\AbstractFormController; |
||||
15 | use Mautic\LeadBundle\Form\Type\BatchType; |
||||
16 | use Mautic\LeadBundle\Model\ListModel; |
||||
17 | use Mautic\LeadBundle\Model\SegmentActionModel; |
||||
18 | use Symfony\Component\HttpFoundation\JsonResponse; |
||||
19 | use Symfony\Component\HttpKernel\Event\FilterControllerEvent; |
||||
20 | |||||
21 | class BatchSegmentController extends AbstractFormController |
||||
22 | { |
||||
23 | private $actionModel; |
||||
24 | |||||
25 | private $segmentModel; |
||||
26 | |||||
27 | /** |
||||
28 | * Initialize object props here to simulate constructor |
||||
29 | * and make the future controller refactoring easier. |
||||
30 | */ |
||||
31 | public function initialize(FilterControllerEvent $event) |
||||
32 | { |
||||
33 | $this->actionModel = $this->container->get('mautic.lead.model.segment.action'); |
||||
34 | $this->segmentModel = $this->container->get('mautic.lead.model.list'); |
||||
35 | } |
||||
36 | |||||
37 | /** |
||||
38 | * API for batch action. |
||||
39 | * |
||||
40 | * @return JsonResponse |
||||
41 | */ |
||||
42 | public function setAction() |
||||
43 | { |
||||
44 | $params = $this->request->get('lead_batch', []); |
||||
45 | $ids = empty($params['ids']) ? [] : json_decode($params['ids']); |
||||
46 | |||||
47 | if ($ids && is_array($ids)) { |
||||
48 | $segmentsToAdd = isset($params['add']) ? $params['add'] : []; |
||||
49 | $segmentsToRemove = isset($params['remove']) ? $params['remove'] : []; |
||||
50 | $contactIds = json_decode($params['ids']); |
||||
51 | |||||
52 | $this->actionModel->addContacts($contactIds, $segmentsToAdd); |
||||
53 | $this->actionModel->removeContacts($contactIds, $segmentsToRemove); |
||||
54 | |||||
55 | $this->addFlash('mautic.lead.batch_leads_affected', [ |
||||
0 ignored issues
–
show
|
|||||
56 | 'pluralCount' => count($ids), |
||||
57 | '%count%' => count($ids), |
||||
58 | ]); |
||||
59 | } else { |
||||
60 | $this->addFlash('mautic.core.error.ids.missing'); |
||||
0 ignored issues
–
show
The function
Mautic\CoreBundle\Contro...nController::addFlash() has been deprecated: Will be removed in Mautic 3.0. Use CommonController::flashBag->addFlash() instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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.
Loading history...
|
|||||
61 | } |
||||
62 | |||||
63 | return new JsonResponse([ |
||||
64 | 'closeModal' => true, |
||||
65 | 'flashes' => $this->getFlashContent(), |
||||
66 | ]); |
||||
67 | } |
||||
68 | |||||
69 | /** |
||||
70 | * View for batch action. |
||||
71 | * |
||||
72 | * @return JsonResponse|\Symfony\Component\HttpFoundation\Response |
||||
73 | */ |
||||
74 | public function indexAction() |
||||
75 | { |
||||
76 | $route = $this->generateUrl('mautic_segment_batch_contact_set'); |
||||
77 | $lists = $this->segmentModel->getUserLists(); |
||||
78 | $items = []; |
||||
79 | |||||
80 | foreach ($lists as $list) { |
||||
81 | $items[$list['name']] = $list['id']; |
||||
82 | } |
||||
83 | |||||
84 | return $this->delegateView( |
||||
85 | [ |
||||
86 | 'viewParameters' => [ |
||||
87 | 'form' => $this->createForm( |
||||
88 | BatchType::class, |
||||
89 | [], |
||||
90 | [ |
||||
91 | 'items' => $items, |
||||
92 | 'action' => $route, |
||||
93 | ] |
||||
94 | )->createView(), |
||||
95 | ], |
||||
96 | 'contentTemplate' => 'MauticLeadBundle:Batch:form.html.php', |
||||
97 | 'passthroughVars' => [ |
||||
98 | 'activeLink' => '#mautic_contact_index', |
||||
99 | 'mauticContent' => 'leadBatch', |
||||
100 | 'route' => $route, |
||||
101 | ], |
||||
102 | ] |
||||
103 | ); |
||||
104 | } |
||||
105 | } |
||||
106 |
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.