vendor/uvdesk/automation-bundle/Services/AutomationService.php line 24

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\AutomationBundle\Services;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Webkul\UVDesk\AutomationBundle\Workflow\FunctionalGroup;
  8. use Symfony\Component\DependencyInjection\ContainerInterface;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. class AutomationService
  11. {
  12.     private $container;
  13.     private $requestStack;
  14.     private $entityManager;
  15.     public function __construct(ContainerInterface $containerRequestStack $requestStackEntityManagerInterface $entityManagerTranslatorInterface $translator)
  16.     {
  17.         $this->container $container;
  18.         $this->requestStack $requestStack;
  19.         $this->entityManager $entityManager;
  20.         $this->translator $translator;
  21.     }
  22.     public function getWorkflowEvents()
  23.     {
  24.         return [
  25.             FunctionalGroup::USER => $this->translator->trans('User'),
  26.             FunctionalGroup::AGENT => $this->translator->trans('Agent'),
  27.             FunctionalGroup::CUSTOMER => $this->translator->trans('Customer'),
  28.             FunctionalGroup::TICKET => $this->translator->trans('Ticket'),
  29.             FunctionalGroup::EMAIL => $this->translator->trans('Email'),
  30.         ];
  31.     }
  32.     public function getWorkflowEventValues()
  33.     {
  34.         $ticketEventCollection = [];
  35.         foreach ($this->container->get('uvdesk.automations.workflows')->getRegisteredWorkflowEvents() as $workflowDefinition) {
  36.             $functionalGroup $workflowDefinition->getFunctionalGroup();
  37.             if (!isset($ticketEventCollection[$functionalGroup])) {
  38.                 $ticketEventCollection[$functionalGroup] = [];
  39.             }
  40.             $ticketEventCollection[$functionalGroup][$workflowDefinition->getId()] = $this->translator->trans($workflowDefinition->getDescription());
  41.         }
  42.         return $ticketEventCollection;
  43.     }
  44.     public function getWorkflowConditions()
  45.     {
  46.         $conditions = [
  47.             'ticket' => [
  48.                 'mail' => [
  49.                     [
  50.                         'lable' => $this->translator->trans('From Email'),
  51.                         'value' => 'from_mail',
  52.                         'match' => 'email'
  53.                     ],
  54.                     [
  55.                         'lable' => $this->translator->trans('To Email'),
  56.                         'value' => 'to_mail',
  57.                         'match' => 'email'
  58.                     ],
  59.                 ],
  60.                 'ticket' => [
  61.                     [
  62.                         'lable' => $this->translator->trans('Subject'),
  63.                         'value' => 'subject',
  64.                         'match' => 'string'
  65.                     ],
  66.                     [
  67.                         'lable' => $this->translator->trans('Description'),
  68.                         'value' => 'description',
  69.                         'match' => 'string'
  70.                     ],
  71.                     [
  72.                         'lable' => $this->translator->trans('Subject or Description'),
  73.                         'value' => 'subject_or_description',
  74.                         'match' => 'string'
  75.                     ],
  76.                     [
  77.                         'lable' => $this->translator->trans('Priority'),
  78.                         'value' => 'TicketPriority',
  79.                         'match' => 'select'
  80.                     ],
  81.                     [
  82.                         'lable' => $this->translator->trans('Type'),
  83.                         'value' => 'TicketType',
  84.                         'match' => 'select'
  85.                     ],
  86.                     [
  87.                         'lable' => $this->translator->trans('Status'),
  88.                         'value' => 'TicketStatus',
  89.                         'match' => 'select'
  90.                     ],
  91.                     [
  92.                         'lable' => $this->translator->trans('Source'),
  93.                         'value' => 'source',
  94.                         'match' => 'select'
  95.                     ],
  96.                     [
  97.                         'lable' => $this->translator->trans('Created'),
  98.                         'value' => 'created',
  99.                         'match' => 'date'
  100.                     ],
  101.                     [
  102.                         'lable' => $this->translator->trans('Agent'),
  103.                         'value' => 'agent',
  104.                         'match' => 'select'
  105.                     ],
  106.                     [
  107.                         'lable' => $this->translator->trans('Group'),
  108.                         'value' => 'group',
  109.                         'match' => 'select'
  110.                     ],
  111.                     [
  112.                         'lable' => $this->translator->trans('Team'),
  113.                         'value' => 'team',
  114.                         'match' => 'select'
  115.                     ],
  116.                 ],
  117.                 'customer' => [
  118.                     [
  119.                         'lable' => $this->translator->trans('Customer Name'),
  120.                         'value' => 'customer_name',
  121.                         'match' => 'string'
  122.                     ],
  123.                     [
  124.                         'lable' => $this->translator->trans('Customer Email'),
  125.                         'value' => 'customer_email',
  126.                         'match' => 'email'
  127.                     ],
  128.                 ],
  129.             ], 
  130.             'email' => [
  131.                 'mail' => [
  132.                     [
  133.                         'lable' => $this->translator->trans('From Email'),
  134.                         'value' => 'from_mail',
  135.                         'match' => 'email'
  136.                     ],
  137.                 ],
  138.             ],
  139.         ];
  140.         
  141.         return $conditions;
  142.     }
  143.     public function getWorkflowMatchConditions()
  144.     {
  145.         return [
  146.             'email' => [
  147.                 [
  148.                     'lable' => $this->translator->trans('Is Equal To'),
  149.                     'value' => 'is'
  150.                 ],
  151.                 [
  152.                     'lable' => $this->translator->trans('Is Not Equal To'),
  153.                     'value' => 'isNot'
  154.                 ],
  155.                 [
  156.                     'lable' => $this->translator->trans('Contains'),
  157.                     'value' => 'contains'
  158.                 ],
  159.                 [
  160.                     'lable' => $this->translator->trans('Does Not Contain'),
  161.                     'value' => 'notContains'
  162.                 ],
  163.             ],
  164.             'string' => [
  165.                 [
  166.                     'lable' => $this->translator->trans('Is Equal To'),
  167.                     'value' => 'is'
  168.                 ],
  169.                 [
  170.                     'lable' => $this->translator->trans('Is Not Equal To'),
  171.                     'value' => 'isNot'
  172.                 ],
  173.                 [
  174.                     'lable' => $this->translator->trans('Contains'),
  175.                     'value' => 'contains'
  176.                 ],
  177.                 [
  178.                     'lable' => $this->translator->trans('Does Not Contain'),
  179.                     'value' => 'notContains'
  180.                 ],
  181.                 [
  182.                     'lable' => $this->translator->trans('Starts With'),
  183.                     'value' => 'startWith'
  184.                 ],
  185.                 [
  186.                     'lable' => $this->translator->trans('Ends With'),
  187.                     'value' => 'endWith'
  188.                 ],
  189.             ],
  190.             'select' => [
  191.                 [
  192.                     'lable' => $this->translator->trans('Is Equal To'),
  193.                     'value' => 'is'
  194.                 ],
  195.                 [
  196.                     'lable' => $this->translator->trans('Is Not Equal To'),
  197.                     'value' => 'isNot'
  198.                 ],
  199.             ],
  200.             'date' => [
  201.                 [
  202.                     'lable' => $this->translator->trans('Before'),
  203.                     'value' => 'before'
  204.                 ],
  205.                 [
  206.                     'lable' => $this->translator->trans('Before On'),
  207.                     'value' => 'beforeOn'
  208.                 ],
  209.                 [
  210.                     'lable' => $this->translator->trans('After'),
  211.                     'value' => 'after'
  212.                 ],
  213.                 [
  214.                     'lable' => $this->translator->trans('After On'),
  215.                     'value' => 'afterOn'
  216.                 ],
  217.             ],
  218.             'datetime' => [
  219.                 [
  220.                     'lable' => $this->translator->trans('Before'),
  221.                     'value' => 'beforeDateTime'
  222.                 ],
  223.                 [
  224.                     'lable' => $this->translator->trans('Before On'),
  225.                     'value' => 'beforeDateTimeOn'
  226.                 ],
  227.                 [
  228.                     'lable' => $this->translator->trans('After'),
  229.                     'value' => 'afterDateTime'
  230.                 ],
  231.                 [
  232.                     'lable' => $this->translator->trans('After On'),
  233.                     'value' => 'afterDateTimeOn'
  234.                 ],
  235.             ],
  236.             'time' => [
  237.                 [
  238.                     'lable' => $this->translator->trans('Before'),
  239.                     'value' => 'beforeTime'
  240.                 ],
  241.                 [
  242.                     'lable' => $this->translator->trans('Before On'),
  243.                     'value' => 'beforeTimeOn'
  244.                 ],
  245.                 [
  246.                     'lable' => $this->translator->trans('After'),
  247.                     'value' => 'afterTime'
  248.                 ],
  249.                 [
  250.                     'lable' => $this->translator->trans('After On'),
  251.                     'value' => 'afterTimeOn'
  252.                 ],
  253.             ],
  254.             'number' => [
  255.                 [
  256.                     'lable' => $this->translator->trans('Is Equal To'),
  257.                     'value' => 'is'
  258.                 ],
  259.                 [
  260.                     'lable' => $this->translator->trans('Is Not Equal To'),
  261.                     'value' => 'isNot'
  262.                 ],
  263.                 [
  264.                     'lable' => $this->translator->trans('Contains'),
  265.                     'value' => 'contains'
  266.                 ],
  267.                 [
  268.                     'lable' => $this->translator->trans('Greater Than'),
  269.                     'value' => 'greaterThan'
  270.                 ],
  271.                 [
  272.                     'lable' => $this->translator->trans('Less Than'),
  273.                     'value' => 'lessThan'
  274.                 ],
  275.             ],
  276.         ];
  277.     }
  278.     public function getWorkflowActions($force false)
  279.     {
  280.         $workflowActions = [];
  281.         
  282.         // @TODO: Add minimum required access levels to workflow actions to restrict usage
  283.         foreach ($this->container->get('uvdesk.automations.workflows')->getRegisteredWorkflowActions() as $workflowDefinition) {
  284.             $functionalGroup $workflowDefinition->getFunctionalGroup();
  285.             if (!isset($workflowActions[$functionalGroup])) {
  286.                 $workflowActions[$functionalGroup] = [];
  287.             }
  288.             $workflowActions[$functionalGroup][$workflowDefinition->getId()] = $this->translator->trans($workflowDefinition->getDescription());
  289.         }
  290.         return $workflowActions;
  291.     }
  292.     public function getPreparedResponseActions($force false)
  293.     {
  294.         $preparedResponseActions = [];
  295.         // @TODO: Add minimum required access levels to prepared response actions to restrict usage
  296.         foreach ($this->container->get('uvdesk.automations.prepared_responses')->getRegisteredPreparedResponseActions() as $preparedResponseDefinition) {
  297.             $functionalGroup $preparedResponseDefinition->getFunctionalGroup();
  298.             if (!isset($preparedResponseActions[$functionalGroup])) {
  299.                 $preparedResponseActions[$functionalGroup] = [];
  300.             }
  301.             $preparedResponseActions[$functionalGroup][$preparedResponseDefinition->getId()] = $this->translator->trans($preparedResponseDefinition->getDescription());
  302.         }
  303.         return $preparedResponseActions;
  304.     }
  305. }