Issues (3627)

Controller/BatchContactController.php (1 issue)

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
Deprecated Code introduced by
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 ignore-deprecated  annotation

67
            /** @scrutinizer ignore-deprecated */ $this->addFlash('mautic.lead.batch_leads_affected', [

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...
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