33namespace Webkul \UVDesk \AutomationBundle \Controller \Automations ;
44
55use Doctrine \Common \Collections \Criteria ;
6- use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
6+ use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
77use Symfony \Component \HttpFoundation \Request ;
88use Symfony \Component \HttpFoundation \Response ;
99use Symfony \Bundle \FrameworkBundle \Routing \Router ;
1010use Webkul \UVDesk \AutomationBundle \Form \DefaultForm ;
1111use Webkul \UVDesk \AutomationBundle \Entity ;
1212use Symfony \Component \Security \Core \SecurityContextInterface ;
13+ use Webkul \UVDesk \CoreFrameworkBundle \Services \UserService ;
14+ use Symfony \Component \Translation \TranslatorInterface ;
1315
14-
15- class PreparedResponse extends Controller
16+ class PreparedResponse extends AbstractController
1617{
1718 const ROLE_REQUIRED_MANUAL = 'ROLE_AGENT_MANAGE_WORKFLOW_MANUAL ' ;
1819 const LIMIT = 20 ;
@@ -21,9 +22,18 @@ class PreparedResponse extends Controller
2122 const NAME_LENGTH = 100 ;
2223 const DESCRIPTION_LENGTH = 200 ;
2324
25+ private $ userService ;
26+ private $ translator ;
27+
28+ public function __construct (UserService $ userService , TranslatorInterface $ translator )
29+ {
30+ $ this ->userService = $ userService ;
31+ $ this ->translator = $ translator ;
32+ }
33+
2434 public function prepareResponseList (Request $ request )
2535 {
26- if (!$ this ->get ( ' user.service ' ) ->isAccessAuthorized ('ROLE_AGENT_MANAGE_WORKFLOW_MANUAL ' )) {
36+ if (!$ this ->userService ->isAccessAuthorized ('ROLE_AGENT_MANAGE_WORKFLOW_MANUAL ' )) {
2737 return $ this ->redirect ($ this ->generateUrl ('helpdesk_member_dashboard ' ));
2838 }
2939
@@ -32,7 +42,7 @@ public function prepareResponseList(Request $request)
3242
3343 public function createPrepareResponse (Request $ request )
3444 {
35- if (!$ this ->get ( ' user.service ' ) ->isAccessAuthorized ('ROLE_AGENT_MANAGE_WORKFLOW_MANUAL ' )) {
45+ if (!$ this ->userService ->isAccessAuthorized ('ROLE_AGENT_MANAGE_WORKFLOW_MANUAL ' )) {
3646 return $ this ->redirect ($ this ->generateUrl ('helpdesk_member_dashboard ' ));
3747 }
3848
@@ -85,7 +95,7 @@ public function createPrepareResponse(Request $request)
8595 }
8696 }
8797
88- if ($ this ->get ( ' user.service ' ) ->isAccessAuthorized ('ROLE_ADMIN ' )) {
98+ if ($ this ->userService ->isAccessAuthorized ('ROLE_ADMIN ' )) {
8999 /* groups */
90100 $ groups = explode (', ' , $ request ->request ->get ('tempGroups ' ));
91101 $ previousGroupIds = [];
@@ -135,12 +145,12 @@ public function createPrepareResponse(Request $request)
135145 $ newWorkflow ->setDescription ($ formData ->get ('description ' ));
136146 $ newWorkflow ->setStatus ($ formData ->get ('status ' ) == 'on ' ? true : false );
137147
138- $ userData = $ this ->get ( ' user.service ' ) ->getUserDetailById ($ this ->getUser ()->getId ());
148+ $ userData = $ this ->userService ->getUserDetailById ($ this ->getUser ()->getId ());
139149 if (!$ newWorkflow ->getUser ()) {
140150 $ newWorkflow ->setUser ($ userData );
141151 }
142152
143- if ($ newWorkflow ->getUser ()->getId () == $ userData ->getId () || $ this ->get ( ' user.service ' ) ->isAccessAuthorized ('ROLE_ADMIN ' )) {
153+ if ($ newWorkflow ->getUser ()->getId () == $ userData ->getId () || $ this ->userService ->isAccessAuthorized ('ROLE_ADMIN ' )) {
144154 $ newWorkflow ->setActions ($ workflowActionsArray );
145155 }
146156
@@ -149,8 +159,8 @@ public function createPrepareResponse(Request $request)
149159 $ entityManager ->flush ();
150160
151161 $ this ->addFlash ('success ' , $ request ->attributes ->get ('id ' )
152- ? $ this ->get ( ' translator ' ) ->trans ('Success! Prepared Response has been updated successfully. ' )
153- : $ this ->get ( ' translator ' ) ->trans ('Success! Prepared Response has been added successfully. ' )
162+ ? $ this ->translator ->trans ('Success! Prepared Response has been updated successfully. ' )
163+ : $ this ->translator ->trans ('Success! Prepared Response has been added successfully. ' )
154164 );
155165
156166 return $ this ->redirectToRoute ('prepare_response_action ' );
@@ -178,7 +188,7 @@ public function createPrepareResponse(Request $request)
178188
179189 public function editPrepareResponse (Request $ request )
180190 {
181- if (!$ this ->get ( ' user.service ' ) ->isAccessAuthorized ('ROLE_AGENT_MANAGE_WORKFLOW_MANUAL ' )) {
191+ if (!$ this ->userService ->isAccessAuthorized ('ROLE_AGENT_MANAGE_WORKFLOW_MANUAL ' )) {
182192 return $ this ->redirect ($ this ->generateUrl ('helpdesk_member_dashboard ' ));
183193 }
184194
@@ -255,7 +265,7 @@ public function editPrepareResponse(Request $request)
255265 }
256266 }
257267
258- if ($ this ->get ( ' user.service ' ) ->isAccessAuthorized ('ROLE_ADMIN ' )) {
268+ if ($ this ->userService ->isAccessAuthorized ('ROLE_ADMIN ' )) {
259269 /* groups */
260270 $ groups = explode (', ' , $ request ->request ->get ('tempGroups ' ));
261271 $ previousGroupIds = [];
@@ -305,12 +315,12 @@ public function editPrepareResponse(Request $request)
305315 $ newWorkflow ->setDescription ($ formData ->get ('description ' ));
306316 $ newWorkflow ->setStatus ($ formData ->get ('status ' ) == 'on ' ? true : false );
307317
308- $ userData = $ this ->get ( ' user.service ' ) ->getUserDetailById ($ this ->getUser ()->getId ());
318+ $ userData = $ this ->userService ->getUserDetailById ($ this ->getUser ()->getId ());
309319 if (!$ newWorkflow ->getUser ()) {
310320 $ newWorkflow ->setUser ($ userData );
311321 }
312322
313- if ($ newWorkflow ->getUser ()->getId () == $ userData ->getId () || $ this ->get ( ' user.service ' ) ->isAccessAuthorized ('ROLE_ADMIN ' )) {
323+ if ($ newWorkflow ->getUser ()->getId () == $ userData ->getId () || $ this ->userService ->isAccessAuthorized ('ROLE_ADMIN ' )) {
314324 $ newWorkflow ->setActions ($ workflowActionsArray );
315325 }
316326
@@ -319,8 +329,8 @@ public function editPrepareResponse(Request $request)
319329 $ entityManager ->flush ();
320330
321331 $ this ->addFlash ('success ' , $ request ->attributes ->get ('id ' )
322- ? $ this ->get ( ' translator ' ) ->trans ('Success! Prepared Response has been updated successfully. ' )
323- : $ this ->get ( ' translator ' ) ->trans ('Success! Prepared Response has been added successfully. ' )
332+ ? $ this ->translator ->trans ('Success! Prepared Response has been updated successfully. ' )
333+ : $ this ->translator ->trans ('Success! Prepared Response has been added successfully. ' )
324334 );
325335
326336 return $ this ->redirectToRoute ('prepare_response_action ' );
0 commit comments