1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\ContactUsBundle\Controller; |
4
|
|
|
|
5
|
|
|
use FOS\RestBundle\Util\Codes; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManager; |
8
|
|
|
|
9
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
11
|
|
|
|
12
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
13
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
14
|
|
|
|
15
|
|
|
use Oro\Bundle\SecurityBundle\Annotation\Acl; |
16
|
|
|
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor; |
17
|
|
|
|
18
|
|
|
use OroCRM\Bundle\ContactUsBundle\Entity\ContactRequest; |
19
|
|
|
|
20
|
|
|
class ContactRequestController extends Controller |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @Route("/view/{id}", name="orocrm_contactus_request_view", requirements={"id"="\d+"}) |
24
|
|
|
* @Template |
25
|
|
|
* @Acl( |
26
|
|
|
* id="orocrm_contactus_request_view", |
27
|
|
|
* type="entity", |
28
|
|
|
* permission="VIEW", |
29
|
|
|
* class="OroCRMContactUsBundle:ContactRequest" |
30
|
|
|
* ) |
31
|
|
|
*/ |
32
|
|
|
public function viewAction(ContactRequest $contactRequest) |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
|
|
'entity' => $contactRequest |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @Route(name="orocrm_contactus_request_index") |
41
|
|
|
* @Template |
42
|
|
|
* @AclAncestor("orocrm_contactus_request_view") |
43
|
|
|
*/ |
44
|
|
|
public function indexAction() |
45
|
|
|
{ |
46
|
|
|
return [ |
47
|
|
|
'entity_class' => $this->container->getParameter('orocrm_contact_us.contactrequest.entity.class') |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Route("/info/{id}", name="orocrm_contactus_request_info", requirements={"id"="\d+"}) |
53
|
|
|
* @Template |
54
|
|
|
* @AclAncestor("orocrm_contactus_request_view") |
55
|
|
|
*/ |
56
|
|
|
public function infoAction(ContactRequest $contactRequest) |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
'entity' => $contactRequest |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @Route("/update/{id}", name="orocrm_contactus_request_update", requirements={"id"="\d+"}) |
65
|
|
|
* @Template |
66
|
|
|
* @Acl( |
67
|
|
|
* id="orocrm_contactus_request_edit", |
68
|
|
|
* type="entity", |
69
|
|
|
* permission="EDIT", |
70
|
|
|
* class="OroCRMContactUsBundle:ContactRequest" |
71
|
|
|
* ) |
72
|
|
|
*/ |
73
|
|
|
public function updateAction(ContactRequest $contactRequest) |
74
|
|
|
{ |
75
|
|
|
return $this->update($contactRequest); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @Route("/create", name="orocrm_contactus_request_create") |
80
|
|
|
* @Template("OroCRMContactUsBundle:ContactRequest:update.html.twig") |
81
|
|
|
* @Acl( |
82
|
|
|
* id="orocrm_contactus_request_create", |
83
|
|
|
* type="entity", |
84
|
|
|
* permission="CREATE", |
85
|
|
|
* class="OroCRMContactUsBundle:ContactRequest" |
86
|
|
|
* ) |
87
|
|
|
*/ |
88
|
|
|
public function createAction() |
89
|
|
|
{ |
90
|
|
|
return $this->update(new ContactRequest()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @Route("/delete/{id}", name="orocrm_contactus_request_delete", requirements={"id"="\d+"}) |
95
|
|
|
* @Acl( |
96
|
|
|
* id="orocrm_contactus_request_delete", |
97
|
|
|
* type="entity", |
98
|
|
|
* permission="DELETE", |
99
|
|
|
* class="OroCRMContactUsBundle:ContactRequest" |
100
|
|
|
* ) |
101
|
|
|
*/ |
102
|
|
|
public function deleteAction(ContactRequest $contactRequest) |
103
|
|
|
{ |
104
|
|
|
/** @var EntityManager $em */ |
105
|
|
|
$em = $this->get('doctrine.orm.entity_manager'); |
106
|
|
|
|
107
|
|
|
$em->remove($contactRequest); |
108
|
|
|
$em->flush(); |
109
|
|
|
|
110
|
|
|
return new JsonResponse('', Codes::HTTP_OK); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param ContactRequest $contactRequest |
115
|
|
|
* |
116
|
|
|
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse |
117
|
|
|
*/ |
118
|
|
View Code Duplication |
protected function update(ContactRequest $contactRequest) |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$handler = $this->get('orocrm_contact_us.contact_request.form.handler'); |
121
|
|
|
|
122
|
|
|
if ($handler->process($contactRequest)) { |
123
|
|
|
$this->get('session')->getFlashBag()->add( |
124
|
|
|
'success', |
125
|
|
|
$this->get('translator')->trans('orocrm.contactus.contactrequest.entity.saved') |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
return $this->get('oro_ui.router')->redirect($contactRequest); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return [ |
132
|
|
|
'entity' => $contactRequest, |
133
|
|
|
'form' => $handler->getForm()->createView() |
134
|
|
|
]; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
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.