Skip to content

Commit

Permalink
Added Some methods in ticketManager (createticket/createcomment/close…
Browse files Browse the repository at this point in the history
…ticket)
  • Loading branch information
simodima committed Jul 25, 2012
1 parent 4c853ec commit 452c531
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Form/CommentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('ticket', 'hidden', array(
'data' => $this->ticket_id,
'mapped' => false
'data' => $this->ticket_id,
'mapped' => false
))
->add('createdBy', 'hidden')
->add('body', 'textarea', array(
'label' => 'comment_textarea_label'
'label' => 'comment_textarea_label'
));
}

Expand Down
23 changes: 21 additions & 2 deletions Manager/TicketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,31 @@ public function createTicketWithUserAndCategory(Category $category, $language, $
$aclManager = $this->getAclManager();
$aclManager->insertAce($ticket, $user);



return $ticket;
}

public function createCommentForTicket($ticket, $user, $commentBody)
{
$commentClass = $this->ticketCommentClass;
$comment = new $commentClass;

$comment->setBody($commentBody);
$comment->setCreatedBy($user);
$comment->setTicket($ticket);

$this->objectManager->persist($comment);
$this->objectManager->flush();

return $comment;
}

public function closeTicket($ticket)
{
$state = $this->objectManager->getRepository('LiuggioHelpDeskBundle:TicketState')->findOneByCode(TicketState::STATE_CLOSED);
$ticket->setState($state);

$this->objectManager->persist($ticket);
$this->objectManager->flush();
}

}
31 changes: 30 additions & 1 deletion Model/TicketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ abstract class TicketManager implements TicketManagerInterface
protected $ticketClass;
protected $ticketRepository;
protected $aclManager;
protected $ticketCommentClass;
protected $categoryClass;

function __construct($objectManager, $ticketClass, $aclManager)
function __construct($objectManager, $ticketClass, $aclManager, $ticketCommentClass, $categoryClass)
{
$this->objectManager = $objectManager;
$this->ticketClass = $ticketClass;
$this->aclManager = $aclManager;
$this->ticketCommentClass = $ticketCommentClass;
$this->categoryClass = $categoryClass;
}

public function setTicketClass($ticketClass)
Expand Down Expand Up @@ -53,6 +57,11 @@ public function getTicketRepository()
return $this->ticketRepository;
}

public function getCategoryRepository()
{
return $this->objectManager->getRepository($this->getCategoryClass());
}

/**
* Returns an empty ticket instance
*
Expand All @@ -76,5 +85,25 @@ public function getAclManager()
return $this->aclManager;
}

public function setCategoryClass($categoryClass)
{
$this->categoryClass = $categoryClass;
}

public function getCategoryClass()
{
return $this->categoryClass;
}

public function setTicketCommentClass($ticketCommentClass)
{
$this->ticketCommentClass = $ticketCommentClass;
}

public function getTicketCommentClass()
{
return $this->ticketCommentClass;
}


}
5 changes: 3 additions & 2 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parameters:
liuggio_help_desk.comment.manager.class: Liuggio\HelpDeskBundle\Manager\CommentManager
liuggio_help_desk.category.manager.class: Liuggio\HelpDeskBundle\Manager\CategoryManager
liuggio_help_desk.ticket.listener.class: Liuggio\HelpDeskBundle\Listener\TicketNotifier
liuggio_help_desk.comment.class: Liuggio\HelpDeskBundle\Entity\Comment

services:
#acl manager
Expand All @@ -12,7 +13,7 @@ services:
#manager
liuggio_help_desk.ticket.manager:
class: %liuggio_help_desk.ticket.manager.class%
arguments: [@doctrine.orm.default_entity_manager, %liuggio_help_desk.ticket.class%, @liuggio_help_desk.acl.manager]
arguments: [@doctrine.orm.default_entity_manager, %liuggio_help_desk.ticket.class%, @liuggio_help_desk.acl.manager, %liuggio_help_desk.comment.class%, %liuggio_help_desk.category.class%]

liuggio_help_desk_category.manager:
class: %liuggio_help_desk.category.manager.class%
Expand All @@ -24,7 +25,7 @@ services:

liuggio_help_desk.ticket.manager_no_doctrine:
class: %liuggio_help_desk.ticket.manager.class%
arguments: [null, %liuggio_help_desk.ticket.class%, %liuggio_help_desk.comment.class%, null]
arguments: [null, %liuggio_help_desk.ticket.class%, @liuggio_help_desk.acl.manager, %liuggio_help_desk.comment.class%, %liuggio_help_desk.category.class%]

liuggio_help_desk.ticket.listener:
class: %liuggio_help_desk.ticket.listener.class%
Expand Down
65 changes: 64 additions & 1 deletion Tests/Unit/TicketManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function setUp()
->setMethods(array('insertAce'))
->getMock();

$this->ticketManager = new \Liuggio\HelpDeskBundle\Manager\TicketManager($this->em, 'Liuggio\HelpDeskBundle\Entity\Ticket', $this->aclManager);
$this->ticketManager = new \Liuggio\HelpDeskBundle\Manager\TicketManager($this->em, 'Liuggio\HelpDeskBundle\Entity\Ticket', $this->aclManager, 'Liuggio\HelpDeskBundle\Entity\Comment', '');

}

Expand Down Expand Up @@ -70,4 +70,67 @@ public function test_createTicketWithUserAndCategory()
$this->assertEquals($user, $newTicket->getCreatedBy());
}

public function test_createCommentForTicket()
{
$that = $this;

$user = $this->getMock('User');
$ticket = new \Liuggio\HelpDeskBundle\Entity\Ticket();
$commentBody = 'TestBody';

$this->em->expects($this->once())
->method('persist')
->will($this->returnCallback(function ($comment) use ($that, $user, $ticket, $commentBody){
$that->assertNotNull($ticket);
$that->assertNotNull($commentBody);
$that->assertEquals($user, $comment->getCreatedBy());
$that->assertEquals($ticket, $comment->getTicket());
$that->assertEquals($commentBody, $comment->getBody());
}));

$comment = $this->ticketManager->createCommentForTicket($ticket, $user, $commentBody);

}


public function test_closeTicket()
{
$that = $this;

$repo = $this->getMockBuilder('\Tvision\Common\Repository')
->disableOriginalConstructor()
->setMethods(array('findOneByCode'))
->getMock();

$stateClosed = new \Liuggio\HelpDeskBundle\Entity\TicketState();
$stateClosed->setCode(\Liuggio\HelpDeskBundle\Entity\TicketState::STATE_CLOSED);

$repo->expects($this->once())
->method('findOneByCode')
->with(\Liuggio\HelpDeskBundle\Entity\TicketState::STATE_CLOSED)
->will($this->returnValue($stateClosed));

$this->em->expects($this->once())
->method('getRepository')
->with('LiuggioHelpDeskBundle:TicketState')
->will($this->returnValue($repo));

$state = new \Liuggio\HelpDeskBundle\Entity\TicketState();
$state->setCode(\Liuggio\HelpDeskBundle\Entity\TicketState::STATE_NEW);

$ticket = new \Liuggio\HelpDeskBundle\Entity\Ticket();
$ticket->setState(new \Liuggio\HelpDeskBundle\Entity\TicketState());

$this->em->expects($this->once())
->method('persist')
->will($this->returnCallback(function ($ticket) use ($that){
$that->assertNotNull($ticket);
$that->assertNotNull($ticket->getState());
$that->assertEquals(\Liuggio\HelpDeskBundle\Entity\TicketState::STATE_CLOSED, $ticket->getState()->getCode());
}));

$this->ticketManager->closeTicket($ticket);

}

}

0 comments on commit 452c531

Please sign in to comment.