Completed
Push — master ( 92cdd1...0ac209 )
by
unknown
15:06
created

LeadController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 21
Ratio 100 %
Metric Value
dl 21
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\Request;
7
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
11
12
use Oro\Bundle\SecurityBundle\Annotation\Acl;
13
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;
14
15
use OroCRM\Bundle\AccountBundle\Entity\Account;
16
use OroCRM\Bundle\SalesBundle\Entity\Lead;
17
use OroCRM\Bundle\ChannelBundle\Entity\Channel;
18
19
/**
20
 * @Route("/lead")
21
 */
22
class LeadController extends Controller
23
{
24
    /**
25
     * @Route("/view/{id}", name="orocrm_sales_lead_view", requirements={"id"="\d+"})
26
     * @Template
27
     * @Acl(
28
     *      id="orocrm_sales_lead_view",
29
     *      type="entity",
30
     *      permission="VIEW",
31
     *      class="OroCRMSalesBundle:Lead"
32
     * )
33
     */
34
    public function viewAction(Lead $lead)
35
    {
36
        return array(
37
            'entity' => $lead
38
        );
39
    }
40
41
    /**
42
     * @Route("/info/{id}", name="orocrm_sales_lead_info", requirements={"id"="\d+"})
43
     * @AclAncestor("orocrm_sales_lead_view")
44
     * @Template()
45
     */
46
    public function infoAction(Lead $lead)
47
    {
48
        return array(
49
            'entity'  => $lead
50
        );
51
    }
52
53
    /**
54
     * @Route("/address-book/{id}", name="orocrm_sales_lead_address_book", requirements={"id"="\d+"})
55
     * @AclAncestor("orocrm_sales_lead_view")
56
     * @Template()
57
     */
58
    public function addressBookAction(Lead $lead)
59
    {
60
        return array(
61
            'entity' => $lead
62
        );
63
    }
64
65
    /**
66
     * Create lead form
67
     * @Route("/create", name="orocrm_sales_lead_create")
68
     * @Template("OroCRMSalesBundle:Lead:update.html.twig")
69
     * @Acl(
70
     *      id="orocrm_sales_lead_create",
71
     *      type="entity",
72
     *      permission="CREATE",
73
     *      class="OroCRMSalesBundle:Lead"
74
     * )
75
     */
76
    public function createAction()
77
    {
78
        return $this->update(new Lead());
79
    }
80
81
    /**
82
     * Update user form
83
     * @Route("/update/{id}", name="orocrm_sales_lead_update", requirements={"id"="\d+"}, defaults={"id"=0})
84
     *
85
     * @Template
86
     * @Acl(
87
     *      id="orocrm_sales_lead_update",
88
     *      type="entity",
89
     *      permission="EDIT",
90
     *      class="OroCRMSalesBundle:Lead"
91
     * )
92
     */
93
    public function updateAction(Lead $entity)
94
    {
95
        return $this->update($entity);
96
    }
97
98
    /**
99
     * @Route(
100
     *      "/{_format}",
101
     *      name="orocrm_sales_lead_index",
102
     *      requirements={"_format"="html|json"},
103
     *      defaults={"_format" = "html"}
104
     * )
105
     * @Template
106
     * @AclAncestor("orocrm_sales_lead_view")
107
     */
108
    public function indexAction()
109
    {
110
        return [
111
            'entity_class' => $this->container->getParameter('orocrm_sales.lead.entity.class')
112
        ];
113
    }
114
115
    /**
116
     * @Route("/widget/account-leads/{id}", name="orocrm_sales_widget_account_leads", requirements={"id"="\d+"})
117
     * @AclAncestor("orocrm_sales_lead_view")
118
     * @Template()
119
     */
120
    public function accountLeadsAction(Account $account)
121
    {
122
        return array('entity' => $account);
123
    }
124
125
    /**
126
     * Create lead form with data channel
127
     *
128
     * @Route("/create/{channelIds}", name="orocrm_sales_lead_data_channel_aware_create")
129
     * @Template("OroCRMSalesBundle:Lead:update.html.twig")
130
     * @AclAncestor("orocrm_sales_lead_view")
131
     *
132
     * @ParamConverter(
133
     *      "channel",
134
     *      class="OroCRMChannelBundle:Channel",
135
     *      options={"id" = "channelIds"}
136
     * )
137
     */
138
    public function leadWithDataChannelCreateAction(Channel $channel)
139
    {
140
        $lead = new Lead();
141
        $lead->setDataChannel($channel);
142
143
        return $this->update($lead);
144
    }
145
146
    /**
147
     * @Route("/datagrid/lead-with-datachannel/{channelIds}", name="orocrm_sales_datagrid_lead_datachannel_aware")
148
     * @Template("OroCRMSalesBundle:Widget:entityWithDataChannelGrid.html.twig")
149
     * @AclAncestor("orocrm_sales_lead_view")
150
     */
151 View Code Duplication
    public function leadWithDataChannelGridAction($channelIds, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        $gridName = $request->query->get('gridName');
154
155
        if (!$gridName) {
156
            return $this->createNotFoundException('`gridName` Should be defined.');
157
        }
158
159
        return [
160
            'channelId'    => $channelIds,
161
            'gridName'     => $gridName,
162
            'params'       => $request->query->get('params', []),
163
            'renderParams' => $request->query->get('renderParams', []),
164
            'multiselect'  => $request->query->get('multiselect', false)
165
        ];
166
    }
167
168
    /**
169
     * @param Lead $entity
170
     *
171
     * @return array
172
     */
173 View Code Duplication
    protected function update(Lead $entity)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
174
    {
175
        return $this->get('oro_form.model.update_handler')->handleUpdate(
176
            $entity,
177
            $this->get('orocrm_sales.lead.form'),
178
            function (Lead $entity) {
179
                return array(
180
                    'route' => 'orocrm_sales_lead_update',
181
                    'parameters' => array('id' => $entity->getId())
182
                );
183
            },
184
            function (Lead $entity) {
185
                return array(
186
                    'route' => 'orocrm_sales_lead_view',
187
                    'parameters' => array('id' => $entity->getId())
188
                );
189
            },
190
            $this->get('translator')->trans('orocrm.sales.controller.lead.saved.message'),
191
            $this->get('orocrm_sales.lead.form.handler')
192
        );
193
    }
194
}
195