77use Hackzilla \Bundle \TicketBundle \Event \TicketEvent ;
88use Hackzilla \Bundle \TicketBundle \Form \Type \TicketMessageType ;
99use Hackzilla \Bundle \TicketBundle \Form \Type \TicketType ;
10+ use Hackzilla \Bundle \TicketBundle \Model \TicketMessageInterface ;
1011use Hackzilla \Bundle \TicketBundle \TicketEvents ;
1112use Hackzilla \Bundle \TicketBundle \TicketRole ;
1213use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
13- use Symfony \Component \Form \AbstractType ;
1414use Symfony \Component \Form \Extension \Core \Type \HiddenType ;
1515use Symfony \Component \HttpFoundation \Request ;
1616
@@ -29,19 +29,16 @@ class TicketController extends Controller
2929 public function indexAction (Request $ request )
3030 {
3131 $ userManager = $ this ->get ('hackzilla_ticket.user_manager ' );
32+ $ ticketManager = $ this ->get ('hackzilla_ticket.ticket_manager ' );
3233 $ translator = $ this ->get ('translator ' );
3334
3435 $ ticketState = $ request ->get ('state ' , $ translator ->trans ('STATUS_OPEN ' ));
3536 $ ticketPriority = $ request ->get ('priority ' , null );
3637
37- $ repositoryTicket = $ this ->getDoctrine ()->getRepository ('HackzillaTicketBundle:Ticket ' );
38-
39- $ repositoryTicketMessage = $ this ->getDoctrine ()->getRepository ('HackzillaTicketBundle:TicketMessage ' );
40-
41- $ query = $ repositoryTicket ->getTicketList (
38+ $ query = $ ticketManager ->getTicketList (
4239 $ userManager ,
43- $ repositoryTicketMessage ->getTicketStatus ($ translator , $ ticketState ),
44- $ repositoryTicketMessage ->getTicketPriority ($ translator , $ ticketPriority )
40+ $ ticketManager ->getTicketStatus ($ translator , $ ticketState ),
41+ $ ticketManager ->getTicketPriority ($ translator , $ ticketPriority )
4542 );
4643
4744 $ paginator = $ this ->get ('knp_paginator ' );
@@ -74,12 +71,12 @@ public function createAction(Request $request)
7471 $ ticketManager = $ this ->get ('hackzilla_ticket.ticket_manager ' );
7572
7673 $ ticket = $ ticketManager ->createTicket ();
77- $ form = $ this ->createForm ($ this -> formType ( TicketType::class, new TicketType ( $ userManager )) , $ ticket );
74+ $ form = $ this ->createForm (TicketType::class, $ ticket );
7875 $ form ->handleRequest ($ request );
7976
8077 if ($ form ->isValid ()) {
8178 $ message = $ ticket ->getMessages ()->current ();
82- $ message ->setStatus (TicketMessage ::STATUS_OPEN )
79+ $ message ->setStatus (TicketMessageInterface ::STATUS_OPEN )
8380 ->setUser ($ userManager ->getCurrentUser ())
8481 ->setTicket ($ ticket );
8582
@@ -106,8 +103,7 @@ public function createAction(Request $request)
106103 public function newAction ()
107104 {
108105 $ entity = new Ticket ();
109- $ userManager = $ this ->get ('hackzilla_ticket.user_manager ' );
110- $ form = $ this ->createForm ($ this ->formType (TicketType::class, new TicketType ($ userManager )), $ entity );
106+ $ form = $ this ->createForm (TicketType::class, $ entity );
111107
112108 return $ this ->render (
113109 'HackzillaTicketBundle:Ticket:new.html.twig ' ,
@@ -139,9 +135,9 @@ public function showAction(Ticket $ticket = null)
139135 $ message ->setPriority ($ ticket ->getPriority ());
140136 $ message ->setStatus ($ ticket ->getStatus ());
141137
142- if (TicketMessage ::STATUS_CLOSED != $ ticket ->getStatus ()) {
138+ if (TicketMessageInterface ::STATUS_CLOSED != $ ticket ->getStatus ()) {
143139 $ data ['form ' ] = $ this ->createForm (
144- $ this -> formType ( TicketMessageType::class, new TicketMessageType ( $ userManager )) ,
140+ TicketMessageType::class,
145141 $ message ,
146142 [
147143 'new_ticket ' => false ,
@@ -195,7 +191,7 @@ public function replyAction(Request $request, Ticket $ticket)
195191 $ message ->setPriority ($ ticket ->getPriority ());
196192
197193 $ form = $ this ->createForm (
198- $ this -> formType ( TicketMessageType::class, new TicketMessageType ( $ userManager )) ,
194+ TicketMessageType::class,
199195 $ message ,
200196 [
201197 'new_ticket ' => false ,
@@ -236,17 +232,20 @@ public function deleteAction(Request $request, Ticket $ticket)
236232 }
237233
238234 $ form = $ this ->createDeleteForm ($ ticket ->getId ());
239- $ form ->submit ($ request );
240235
241- if ($ form ->isValid ()) {
242- if (!$ ticket ) {
243- throw $ this ->createNotFoundException ($ this ->get ('translator ' )->trans ('ERROR_FIND_TICKET_ENTITY ' ));
244- }
236+ if ($ request ->isMethod ('DELETE ' )) {
237+ $ form ->submit ($ request ->request ->get ($ form ->getName ()));
245238
246- $ ticketManager = $ this ->get ('hackzilla_ticket.ticket_manager ' );
247- $ ticketManager ->deleteTicket ($ ticket );
248- $ event = new TicketEvent ($ ticket );
249- $ this ->get ('event_dispatcher ' )->dispatch (TicketEvents::TICKET_DELETE , $ event );
239+ if ($ form ->isValid ()) {
240+ if (!$ ticket ) {
241+ throw $ this ->createNotFoundException ($ this ->get ('translator ' )->trans ('ERROR_FIND_TICKET_ENTITY ' ));
242+ }
243+
244+ $ ticketManager = $ this ->get ('hackzilla_ticket.ticket_manager ' );
245+ $ ticketManager ->deleteTicket ($ ticket );
246+ $ event = new TicketEvent ($ ticket );
247+ $ this ->get ('event_dispatcher ' )->dispatch (TicketEvents::TICKET_DELETE , $ event );
248+ }
250249 }
251250
252251 return $ this ->redirect ($ this ->generateUrl ('hackzilla_ticket ' ));
@@ -262,13 +261,8 @@ public function deleteAction(Request $request, Ticket $ticket)
262261 private function createDeleteForm ($ id )
263262 {
264263 return $ this ->createFormBuilder (['id ' => $ id ])
265- ->add ('id ' , $ this -> formType ( HiddenType::class, ' hidden ' ) )
264+ ->add ('id ' , HiddenType::class)
266265 ->getForm ()
267266 ;
268267 }
269-
270- private function formType ($ class , $ type )
271- {
272- return method_exists (AbstractType::class, 'getBlockPrefix ' ) ? $ class : $ type ;
273- }
274268}
0 commit comments