Skip to content

Commit

Permalink
started notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
liuggio committed Jun 7, 2012
1 parent dda54ca commit 84018fb
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 63 deletions.
8 changes: 5 additions & 3 deletions Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Liuggio\HelpDeskTicketSystemBundle\Entity\Comment;
use Liuggio\HelpDeskTicketSystemBundle\Form\CommentType;

use Liuggio\HelpDeskTicketSystemBundle\Exception;
/**
* Comment controller.
*
Expand Down Expand Up @@ -40,9 +40,11 @@ public function createAction()
$state_pending = $em->getRepository('\Liuggio\HelpDeskTicketSystemBundle\Entity\TicketState')
->findOneByCode(\Liuggio\HelpDeskTicketSystemBundle\Entity\TicketState::STATE_PENDING);

if ($state_pending) {
$ticket->setState($state_pending);
if (!$state_pending) {
throw new Exception('Ticket State Not Found');
}

$ticket->setState($state_pending);
//Set the createdBy user
$entity->setCreatedBy($user);
$em->persist($ticket);
Expand Down
7 changes: 7 additions & 0 deletions Entity/TicketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@ public function isOperatorGrantedForThisTicket($ticket, $operator)
return true;
}

/**
* thi function notifies the user
* @param $user
*/
public function sendEmailToUser($user, $isOperator=false)
{

}
}
34 changes: 0 additions & 34 deletions Entity/TicketRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,39 +70,5 @@ public function findTicketsByStatesAndOperator($operator, $states, $filter = '')
return $qb->getQuery()->getResult();
}

/**
* @param $operator
* @param $states
* @param string $filter
* @return array
* @throws \Liuggio\HelpDeskTicketSystemBundle\Exception
*/
public function findAllOperatorsOfThisTicket($ticket)
{
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();

$qb->select('u')
->from('LiuggioHelpDeskTicketSystemBundle:Ticket', 't')
->leftjoin('t.state', 'st')
->leftjoin('t.category', 'ct')
->leftjoin('ct.operators', 'opr')
->where('opr = :user')
->setParameter('user', $operator);

if (!is_array($states) || count($states) <= 0) {
throw new \Liuggio\HelpDeskTicketSystemBundle\Exception('Impossible to read state');
}
//$qb->andWhereIn('st.code', $statesOr);
$qb->andWhere($qb->expr()->in('st.code', $states));

if (!empty($filter)) {
$qb->andWhere(
$qb->expr()->orx($qb->expr()->like('t.subject', ':pattern'), $qb->expr()->like('t.body', ':pattern'))
)
->setParameter('pattern', "%" . $filter . "%");
}

return $qb->getQuery()->getResult();
}
}
147 changes: 129 additions & 18 deletions Listener/TicketNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,144 @@
class TicketNotifier
{
private $ticketManager;
private $mailer;
private $translator;
private $logger;

public function __construct($ticketManager) {
CONST EVENT_IS_UPDATE = 0;
CONST EVENT_IS_PERSIST = 1;

/**
* @param $mailer
* @param $translator
*/
public function __construct($mailer, $translator, $logger, $ticketManager)
{
$this->setMailer($mailer);
$this->setTranslator($translator);
$this->setLogger($logger);
$this->ticketManager = $ticketManager;
}

public function onTicketPersistOrUpdate(LifecycleEventArgs $args)
/**
* @param LifecycleEventArgs $args
*/
public function postUpdate(LifecycleEventArgs $args)
{
return $this->postPersistUpdate($args, self::EVENT_IS_UPDATE);
}

/**
* @param LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{

return $this->postPersistUpdate($args, self::EVENT_IS_PERSIST);

}

/**
*
*
* @param LifecycleEventArgs $args
* @param int $isUpdate
*/
public function postPersistUpdate(LifecycleEventArgs $args, $isUpdate = self::EVENT_IS_UPDATE)
{

$entity = $args->getEntity();
$entityManager = $args->getEntityManager();

//always notify the owner
//notify the
if ($entity instanceof $this->getTicketManager()->getTicketClass()) {
//extract all the operators that belongs to this ticket
// // notify the customercares of the corresponding category
// $category = $entity->getCategory();
// $operators = $category->getOperators();

// $message = \Swift_Message::newInstance()
// ->setSubject('Hello Email')
// ->setFrom('send@example.com')
// ->setTo('recipient@example.com')
// ->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name)))
// ;
//
// $this->get('mailer')->send($message);
//extract the customer that
if ($entity instanceof TicketInterface) {
$this->getLogger()->info('+++++++++++++++++++++++++' . $isUpdate . 'ENTITY YEAH');

$this->getTicketManager()->setObjectManager($entityManager);

$operators = $entity->getCategory()->getOperators();
foreach ($operators as $operator) {
$this->getTicketManager()->sendEmailToUser($entity, $operator);
}

$owner = $entity->getCreatedBy();

// 1. notify all the operator of this ticket
// 2. notify the owner of this ticket
}


//
// if ($entity instanceof $this->getTicketManager()->getTicketClass()) {
//
// echo "wooow";
// //extract all the operators that belongs to this ticket
//// // notify the customercares of the corresponding category
//// $category = $entity->getCategory();
//// $operators = $category->getOperators();
//
//// $message = \Swift_Message::newInstance()
//// ->setSubject('Hello Email')
//// ->setFrom('send@example.com')
//// ->setTo('recipient@example.com')
//// ->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name)))
//// ;
////
//// $this->get('mailer')->send($message);
// //extract the customer that
//
////
//// $body = $event->getBody();
////
//// if (!is_null($event->getOrder()->getSeller())) {
//// $recipients = array($event->getOrder()->getSeller()->getEmail());
//// } else {
//// $recipients = array($event->getOrder()->getOwner()->getEmail());
//// }
//// $message = \Swift_Message::newInstance()
//// ->setFrom('tv.devs@gmail.com')
//// ->setTo($recipients)
//// ->setSubject($this->translator->trans('Terravision: Order Information'))
//// ->setBody($body, 'text/html')
//// ;
////
//// $this->mailer->send($message);
//
//


// }
}


public function setTranslator($translator)
{
$this->translator = $translator;
}

public function getTranslator()
{
return $this->translator;
}

public function setMailer($mailer)
{
$this->mailer = $mailer;
}

public function getMailer()
{
return $this->mailer;
}

public function setLogger($logger)
{
$this->logger = $logger;
}

public function getLogger()
{
return $this->logger;
}

public function setTicketManager($ticketManager)
Expand Down
11 changes: 7 additions & 4 deletions Model/TicketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ abstract class TicketManager implements TicketManagerInterface
protected $ticketRepository;
protected $commentRepository;

function __construct(ObjectManager $objectManager, $ticketClass, $commentClass, $securityContext)
function __construct($objectManager, $ticketClass, $commentClass)
{
$this->objectManager = $objectManager;
$this->ticketClass = $ticketClass;
$this->commentClass = $commentClass;
$this->securityContext = $securityContext;
$this->ticketRepository = $this->objectManager->getRepository($ticketClass);
$this->commentRepository = $this->objectManager->getRepository($commentClass);
}

public function setTicketClass($ticketClass)
Expand Down Expand Up @@ -61,6 +58,9 @@ public function setTicketRepository($ticketRepository)

public function getTicketRepository()
{
if (null == $this->ticketRepository) {
$this->setTicketRepository($this->objectManager->getRepository($this->getTicketClass()));
}
return $this->ticketRepository;
}

Expand All @@ -81,6 +81,9 @@ public function setCommentRepository($commentRepository)

public function getCommentRepository()
{
if (null == $this->commentRepository) {
$this->setCommentRepository($this->objectManager->getRepository($this->getCommentClass()));
}
return $this->commentRepository;
}

Expand Down
15 changes: 11 additions & 4 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ services:
liuggio_help_desk_ticket_system.acl.manager:
class: Liuggio\HelpDeskTicketSystemBundle\Service\AclManager
arguments: [@security.acl.provider, @security.context]
#listener
# liuggio_help_desk_ticket_system.ticket.listener:
# class: %liuggio_help_desk_ticket_system.ticket.listener.class%
# arguments: [@doctrine.orm.default_entity_manager, @mailer]
#manager
liuggio_help_desk_ticket_system.ticket.manager:
class: %liuggio_help_desk_ticket_system.ticket.manager.class%
arguments: [@doctrine.orm.default_entity_manager, %liuggio_help_desk_ticket_system.ticket.class%, %liuggio_help_desk_ticket_system.comment.class%, @security.context]

liuggio_help_desk_ticket_system.ticket.manager_no_doctrine:
class: %liuggio_help_desk_ticket_system.ticket.manager.class%
arguments: [null, %liuggio_help_desk_ticket_system.ticket.class%, %liuggio_help_desk_ticket_system.comment.class%, null]

liuggio_help_desk_ticket_system.ticket.listener:
class: %liuggio_help_desk_ticket_system.ticket.listener.class%
arguments: [@mailer, @translator, @logger, @liuggio_help_desk_ticket_system.ticket.manager_no_doctrine]
tags:
- { name: doctrine.event_listener, event:postUpdate}
- { name: doctrine.event_listener, event:postPersist}
#Sonata Admin
sonata.ticket.ticketstate.admin:
class: Liuggio\HelpDeskTicketSystemBundle\Admin\TicketStateAdmin
Expand Down

0 comments on commit 84018fb

Please sign in to comment.