vendor\uvdesk\automation-bundle\EventListener\PreparedResponseListener.php line 33

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\AutomationBundle\PreparedResponse\Action as PreparedResponseAction;
  8. class PreparedResponseListener
  9. {
  10.     private $container;
  11.     private $entityManager;
  12.     private $registeredPreparedResponseActions = [];
  13.     public function __construct(ContainerInterface $containerEntityManagerInterface $entityManager)
  14.     {
  15.         $this->container $container;
  16.         $this->entityManager $entityManager;
  17.     }
  18.     public function registerPreparedResponseAction(PreparedResponseAction $serviceTag)
  19.     {
  20.         $this->registeredPreparedResponseActions[] = $serviceTag;
  21.     }
  22.     public function getRegisteredPreparedResponseActions()
  23.     {
  24.         return $this->registeredPreparedResponseActions;
  25.     }
  26.     public function executePreparedResponse(GenericEvent $event)
  27.     {
  28.         $preparedResponse $this->entityManager->getRepository(PreparedResponses::class)->getPreparedResponse($event->getSubject());
  29.         
  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. }