vendor/uvdesk/automation-bundle/EventListener/PreparedResponseListener.php line 34

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\AutomationBundle\EventListener;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\EventDispatcher\GenericEvent;
  5. use Webkul\UVDesk\AutomationBundle\Entity\PreparedResponses;
  6. use Symfony\Component\DependencyInjection\ContainerInterface;
  7. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
  8. use Webkul\UVDesk\AutomationBundle\PreparedResponse\Action as PreparedResponseAction;
  9. class PreparedResponseListener
  10. {
  11. private $container;
  12. private $entityManager;
  13. private $registeredPreparedResponseActions = [];
  14. public function __construct(ContainerInterface $container, EntityManagerInterface $entityManager)
  15. {
  16. $this->container = $container;
  17. $this->entityManager = $entityManager;
  18. }
  19. public function registerPreparedResponseAction(PreparedResponseAction $serviceTag)
  20. {
  21. $this->registeredPreparedResponseActions[] = $serviceTag;
  22. }
  23. public function getRegisteredPreparedResponseActions()
  24. {
  25. return $this->registeredPreparedResponseActions;
  26. }
  27. public function executePreparedResponse(GenericEvent $event)
  28. {
  29. $preparedResponse = $this->entityManager->getRepository(PreparedResponses::class)->getPreparedResponse($event->getSubject());
  30. if (!empty($preparedResponse)) {
  31. $this->applyPreparedResponseActions($preparedResponse , $event->getArgument('entity'));
  32. }
  33. }
  34. private function applyPreparedResponseActions(PreparedResponses $preparedResponse, $entity)
  35. {
  36. foreach ($preparedResponse->getActions() as $attributes) {
  37. if (empty($attributes['type'])) {
  38. continue;
  39. }
  40. foreach ($this->getRegisteredPreparedResponseActions() as $preparedResponseAction) {
  41. if ($preparedResponseAction->getId() == $attributes['type']) {
  42. $preparedResponseAction->applyAction($this->container, $entity, isset($attributes['value']) ? $attributes['value']: '');
  43. }
  44. }
  45. }
  46. }
  47. }