1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\ChannelBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
6
|
|
|
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
9
|
|
|
|
10
|
|
|
use Oro\Bundle\SecurityBundle\Annotation\Acl; |
11
|
|
|
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor; |
12
|
|
|
|
13
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Channel; |
14
|
|
|
use OroCRM\Bundle\ChannelBundle\Event\ChannelChangeStatusEvent; |
15
|
|
|
|
16
|
|
|
class ChannelController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @Route( |
20
|
|
|
* "/{_format}", |
21
|
|
|
* name="orocrm_channel_index", |
22
|
|
|
* requirements={"_format"="html|json"}, |
23
|
|
|
* defaults={"_format"="html"} |
24
|
|
|
* ) |
25
|
|
|
* @Acl( |
26
|
|
|
* id="orocrm_channel_view", |
27
|
|
|
* type="entity", |
28
|
|
|
* permission="VIEW", |
29
|
|
|
* class="OroCRMChannelBundle:Channel" |
30
|
|
|
* ) |
31
|
|
|
* @Template() |
32
|
|
|
*/ |
33
|
|
|
public function indexAction() |
34
|
|
|
{ |
35
|
|
|
return []; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @Route("/create", name="orocrm_channel_create") |
40
|
|
|
* @Acl( |
41
|
|
|
* id="orocrm_channel_create", |
42
|
|
|
* type="entity", |
43
|
|
|
* permission="CREATE", |
44
|
|
|
* class="OroCRMChannelBundle:Channel" |
45
|
|
|
* ) |
46
|
|
|
* @Template("OroCRMChannelBundle:Channel:update.html.twig") |
47
|
|
|
*/ |
48
|
|
|
public function createAction() |
49
|
|
|
{ |
50
|
|
|
return $this->update(new Channel()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Route("/update/{id}", requirements={"id"="\d+"}, name="orocrm_channel_update") |
55
|
|
|
* @Acl( |
56
|
|
|
* id="orocrm_channel_update", |
57
|
|
|
* type="entity", |
58
|
|
|
* permission="EDIT", |
59
|
|
|
* class="OroCRMChannelBundle:Channel" |
60
|
|
|
* ) |
61
|
|
|
* @Template() |
62
|
|
|
*/ |
63
|
|
|
public function updateAction(Channel $channel) |
64
|
|
|
{ |
65
|
|
|
return $this->update($channel); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param Channel $channel |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
protected function update(Channel $channel) |
74
|
|
|
{ |
75
|
|
|
$handler = $this->get('orocrm_channel.channel_form.handler'); |
76
|
|
|
|
77
|
|
|
if ($handler->process($channel)) { |
78
|
|
|
$this->get('session')->getFlashBag()->add( |
79
|
|
|
'success', |
80
|
|
|
$this->get('translator')->trans('orocrm.channel.controller.message.saved') |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
return $this->get('oro_ui.router')->redirect($channel); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return [ |
87
|
|
|
'entity' => $channel, |
88
|
|
|
'form' => $handler->getFormView(), |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @Route( |
94
|
|
|
* "/status/change/{id}", |
95
|
|
|
* requirements={"id"="\d+"}, |
96
|
|
|
* name="orocrm_channel_change_status" |
97
|
|
|
* ) |
98
|
|
|
* @AclAncestor("orocrm_channel_update") |
99
|
|
|
*/ |
100
|
|
|
public function changeStatusAction(Channel $channel) |
101
|
|
|
{ |
102
|
|
|
if ($channel->getStatus() == Channel::STATUS_ACTIVE) { |
103
|
|
|
$message = 'orocrm.channel.controller.message.status.deactivated'; |
104
|
|
|
$channel->setStatus(Channel::STATUS_INACTIVE); |
105
|
|
|
} else { |
106
|
|
|
$message = 'orocrm.channel.controller.message.status.activated'; |
107
|
|
|
$channel->setStatus(Channel::STATUS_ACTIVE); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$this->getDoctrine() |
111
|
|
|
->getManager() |
112
|
|
|
->flush(); |
113
|
|
|
|
114
|
|
|
$event = new ChannelChangeStatusEvent($channel); |
115
|
|
|
|
116
|
|
|
$this->get('event_dispatcher')->dispatch(ChannelChangeStatusEvent::EVENT_NAME, $event); |
117
|
|
|
$this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans($message)); |
118
|
|
|
|
119
|
|
|
return $this->redirect( |
120
|
|
|
$this->generateUrl( |
121
|
|
|
'orocrm_channel_view', |
122
|
|
|
[ |
123
|
|
|
'id' => $channel->getId(), |
124
|
|
|
'_enableContentProviders' => 'mainMenu' |
125
|
|
|
] |
126
|
|
|
) |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @Route("/view/{id}", requirements={"id"="\d+"}, name="orocrm_channel_view") |
132
|
|
|
* @AclAncestor("orocrm_channel_view") |
133
|
|
|
* @Template() |
134
|
|
|
*/ |
135
|
|
|
public function viewAction(Channel $channel) |
136
|
|
|
{ |
137
|
|
|
return [ |
138
|
|
|
'entity' => $channel, |
139
|
|
|
]; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @Route("/widget/info/{id}", name="orocrm_channel_widget_info", requirements={"id"="\d+"}) |
144
|
|
|
* @AclAncestor("orocrm_channel_view") |
145
|
|
|
* @Template() |
146
|
|
|
*/ |
147
|
|
|
public function infoAction(Channel $channel) |
148
|
|
|
{ |
149
|
|
|
return [ |
150
|
|
|
'channel' => $channel |
151
|
|
|
]; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|