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

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