forked from liuggio/HelpDeskBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommentController.php
63 lines (51 loc) · 2 KB
/
CommentController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Liuggio\HelpDeskTicketSystemBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Liuggio\HelpDeskTicketSystemBundle\Entity\Comment;
use Liuggio\HelpDeskTicketSystemBundle\Form\CommentType;
/**
* Comment controller.
*
*/
class CommentController extends Controller
{
/**
* Creates a new Comment entity.
*
*/
public function createAction()
{
//Retrive the User from the Session
$user = $this->get('security.context')->getToken()->getUser();
$entity = new Comment();
$request = $this->getRequest();
$form = $this->createForm(new CommentType(), $entity);
$form->bindRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$comment = $form->getData();
$form = $this->getRequest()->get('liuggio_helpdeskticketsystembundle_commenttype');
$ticket_id = $form['ticket'];
$ticket = $em->getRepository('LiuggioHelpDeskTicketSystemBundle:Ticket')->find($ticket_id);
if (!$ticket) {
throw $this->createNotFoundException('Unable to find Ticket entity.');
}
$state_pending = $em->getRepository('\Liuggio\HelpDeskTicketSystemBundle\Entity\TicketState')
->findOneByCode(\Liuggio\HelpDeskTicketSystemBundle\Entity\TicketState::STATE_PENDING);
if ($state_pending) {
$ticket->setState($state_pending);
}
//Set the createdBy user
$entity->setCreatedBy($user);
$em->persist($ticket);
$comment->setTicket($ticket);
$em->persist($comment);
$em->flush();
return $this->redirect($this->generateUrl('ticket_show', array('id' => $ticket_id)));
}
return $this->render('LiuggioHelpDeskTicketSystemBundle:Comment:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView()
));
}
}