vendor/uvdesk/core-framework/Workflow/Actions/Ticket/UpdateAgent.php line 62

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Workflow\Actions\Ticket;
  3. use Webkul\UVDesk\AutomationBundle\Workflow\FunctionalGroup;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
  7. use Webkul\UVDesk\AutomationBundle\Workflow\Action as WorkflowAction;
  8. use Webkul\UVDesk\AutomationBundle\Workflow\Event;
  9. use Webkul\UVDesk\AutomationBundle\Workflow\Events\AgentActivity;
  10. use Webkul\UVDesk\AutomationBundle\Workflow\Events\TicketActivity;
  11. class UpdateAgent extends WorkflowAction
  12. {
  13.     public static function getId()
  14.     {
  15.         return 'uvdesk.ticket.assign_agent';
  16.     }
  17.     public static function getDescription()
  18.     {
  19.         return "Assign to agent";
  20.     }
  21.     public static function getFunctionalGroup()
  22.     {
  23.         return FunctionalGroup::TICKET;
  24.     }
  25.     public static function getOptions(ContainerInterface $container)
  26.     {
  27.         $agentCollection array_map(function ($agent) {
  28.             return [
  29.                 'id' => $agent['id'],
  30.                 'name' => $agent['name'],
  31.             ];
  32.         }, $container->get('user.service')->getAgentPartialDataCollection());
  33.         array_unshift($agentCollection, [
  34.             'id' => 'responsePerforming',
  35.             'name' => 'Response Performing Agent',
  36.         ]);
  37.         return $agentCollection;
  38.     }
  39.     public static function applyAction(ContainerInterface $containerEvent $event$value null)
  40.     {
  41.         $entityManager $container->get('doctrine.orm.entity_manager');
  42.         if (!$event instanceof TicketActivity) {
  43.             return;
  44.         } else {
  45.             $ticket $event->getTicket();
  46.             
  47.             if (empty($ticket)) {
  48.                 return;
  49.             }
  50.         }
  51.         
  52.         if ($value == 'responsePerforming' && is_object($currentUser $container->get('security.token_storage')->getToken()->getUser())) {
  53.             if (null != $currentUser->getAgentInstance()) {
  54.                 $agent $currentUser;
  55.             }
  56.         } else {
  57.             $agent $entityManager->getRepository(User::class)->find($value);
  58.             if ($agent) {
  59.                 $agent $entityManager->getRepository(User::class)->findOneBy(array('email' => $agent->getEmail()));
  60.             }
  61.         }
  62.         if (!empty($agent)) {
  63.             if ($entityManager->getRepository(User::class)->findOneById($agent->getId())) {
  64.                 $ticket
  65.                     ->setAgent($agent)
  66.                 ;
  67.                 $entityManager->persist($ticket);
  68.                 $entityManager->flush();
  69.             }
  70.         } else {
  71.             // Agent Not Found. Disable Workflow/Prepared Response
  72.         }
  73.     }
  74. }