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 $containerEntityManagerInterface $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.         
  31.         if (!empty($preparedResponse)) {
  32.             $this->applyPreparedResponseActions($preparedResponse $event->getArgument('entity'));
  33.         }
  34.     }
  35.     private function applyPreparedResponseActions(PreparedResponses $preparedResponse$entity)
  36.     {
  37.         foreach ($preparedResponse->getActions() as $attributes) {
  38.             if (empty($attributes['type'])) {
  39.                 continue;
  40.             }
  41.             
  42.             foreach ($this->getRegisteredPreparedResponseActions() as $preparedResponseAction) {
  43.                 if ($preparedResponseAction->getId() == $attributes['type']) {
  44.                     $preparedResponseAction->applyAction($this->container$entity, isset($attributes['value']) ? $attributes['value']: '');
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }