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\ChannelBundle\Entity\Channel; |
16
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\Opportunity; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @Route("/opportunity") |
20
|
|
|
*/ |
21
|
|
|
class OpportunityController extends Controller |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @Route("/view/{id}", name="orocrm_sales_opportunity_view", requirements={"id"="\d+"}) |
25
|
|
|
* @Template |
26
|
|
|
* @Acl( |
27
|
|
|
* id="orocrm_sales_opportunity_view", |
28
|
|
|
* type="entity", |
29
|
|
|
* permission="VIEW", |
30
|
|
|
* class="OroCRMSalesBundle:Opportunity" |
31
|
|
|
* ) |
32
|
|
|
*/ |
33
|
|
|
public function viewAction(Opportunity $entity) |
34
|
|
|
{ |
35
|
|
|
return array( |
36
|
|
|
'entity' => $entity, |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @Route("/info/{id}", name="orocrm_sales_opportunity_info", requirements={"id"="\d+"}) |
42
|
|
|
* @Template |
43
|
|
|
* @AclAncestor("orocrm_sales_opportunity_view") |
44
|
|
|
*/ |
45
|
|
|
public function infoAction(Opportunity $entity) |
46
|
|
|
{ |
47
|
|
|
return array( |
48
|
|
|
'entity' => $entity |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Route("/create", name="orocrm_sales_opportunity_create") |
54
|
|
|
* @Template("OroCRMSalesBundle:Opportunity:update.html.twig") |
55
|
|
|
* @Acl( |
56
|
|
|
* id="orocrm_sales_opportunity_create", |
57
|
|
|
* type="entity", |
58
|
|
|
* permission="CREATE", |
59
|
|
|
* class="OroCRMSalesBundle:Opportunity" |
60
|
|
|
* ) |
61
|
|
|
*/ |
62
|
|
|
public function createAction() |
63
|
|
|
{ |
64
|
|
|
return $this->update(new Opportunity()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @Route("/update/{id}", name="orocrm_sales_opportunity_update", requirements={"id"="\d+"}, defaults={"id"=0}) |
69
|
|
|
* @Template |
70
|
|
|
* @Acl( |
71
|
|
|
* id="orocrm_sales_opportunity_update", |
72
|
|
|
* type="entity", |
73
|
|
|
* permission="EDIT", |
74
|
|
|
* class="OroCRMSalesBundle:Opportunity" |
75
|
|
|
* ) |
76
|
|
|
*/ |
77
|
|
|
public function updateAction(Opportunity $entity) |
78
|
|
|
{ |
79
|
|
|
return $this->update($entity); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @Route( |
84
|
|
|
* "/{_format}", |
85
|
|
|
* name="orocrm_sales_opportunity_index", |
86
|
|
|
* requirements={"_format"="html|json"}, |
87
|
|
|
* defaults={"_format" = "html"} |
88
|
|
|
* ) |
89
|
|
|
* @Template |
90
|
|
|
* @AclAncestor("orocrm_sales_opportunity_view") |
91
|
|
|
*/ |
92
|
|
|
public function indexAction() |
93
|
|
|
{ |
94
|
|
|
return [ |
95
|
|
|
'entity_class' => $this->container->getParameter('orocrm_sales.opportunity.class') |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Create opportunity form with data channel |
101
|
|
|
* |
102
|
|
|
* @Route("/create/{channelIds}", name="orocrm_sales_opportunity_data_channel_aware_create") |
103
|
|
|
* @Template("OroCRMSalesBundle:Opportunity:update.html.twig") |
104
|
|
|
* @AclAncestor("orocrm_sales_opportunity_create") |
105
|
|
|
* |
106
|
|
|
* @ParamConverter( |
107
|
|
|
* "channel", |
108
|
|
|
* class="OroCRMChannelBundle:Channel", |
109
|
|
|
* options={"id" = "channelIds"} |
110
|
|
|
* ) |
111
|
|
|
*/ |
112
|
|
|
public function opportunityWithDataChannelCreateAction(Channel $channel) |
113
|
|
|
{ |
114
|
|
|
$opportunity = new Opportunity(); |
115
|
|
|
$opportunity->setDataChannel($channel); |
116
|
|
|
|
117
|
|
|
return $this->update($opportunity); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @Route( |
122
|
|
|
* "/datagrid/opportunity-with-datachannel/{channelIds}", |
123
|
|
|
* name="orocrm_sales_datagrid_opportunity_datachannel_aware" |
124
|
|
|
* ) |
125
|
|
|
* @Template("OroCRMSalesBundle:Widget:entityWithDataChannelGrid.html.twig") |
126
|
|
|
* @AclAncestor("orocrm_sales_opportunity_view") |
127
|
|
|
*/ |
128
|
|
View Code Duplication |
public function opportunityWithDataChannelGridAction($channelIds, Request $request) |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
$gridName = $request->query->get('gridName'); |
131
|
|
|
|
132
|
|
|
if (!$gridName) { |
133
|
|
|
return $this->createNotFoundException('`gridName` Should be defined.'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return [ |
137
|
|
|
'channelId' => $channelIds, |
138
|
|
|
'gridName' => $gridName, |
139
|
|
|
'params' => $request->query->get('params', []), |
140
|
|
|
'renderParams' => $request->query->get('renderParams', []), |
141
|
|
|
'multiselect' => $request->query->get('multiselect', false) |
142
|
|
|
]; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param Opportunity $entity |
147
|
|
|
* @return array |
148
|
|
|
*/ |
149
|
|
View Code Duplication |
protected function update(Opportunity $entity) |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
return $this->get('oro_form.model.update_handler')->handleUpdate( |
152
|
|
|
$entity, |
153
|
|
|
$this->get('orocrm_sales.opportunity.form'), |
154
|
|
|
function (Opportunity $entity) { |
155
|
|
|
return array( |
156
|
|
|
'route' => 'orocrm_sales_opportunity_update', |
157
|
|
|
'parameters' => array('id' => $entity->getId()) |
158
|
|
|
); |
159
|
|
|
}, |
160
|
|
|
function (Opportunity $entity) { |
161
|
|
|
return array( |
162
|
|
|
'route' => 'orocrm_sales_opportunity_view', |
163
|
|
|
'parameters' => array('id' => $entity->getId()) |
164
|
|
|
); |
165
|
|
|
}, |
166
|
|
|
$this->get('translator')->trans('orocrm.sales.controller.opportunity.saved.message'), |
167
|
|
|
$this->get('orocrm_sales.opportunity.form.handler') |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
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.