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 $container, RequestStack $requestStack, EntityManagerInterface $entityManager, TranslatorInterface $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. return $conditions;
  141. }
  142. public function getWorkflowMatchConditions()
  143. {
  144. return [
  145. 'email' => [
  146. [
  147. 'lable' => $this->translator->trans('Is Equal To'),
  148. 'value' => 'is'
  149. ],
  150. [
  151. 'lable' => $this->translator->trans('Is Not Equal To'),
  152. 'value' => 'isNot'
  153. ],
  154. [
  155. 'lable' => $this->translator->trans('Contains'),
  156. 'value' => 'contains'
  157. ],
  158. [
  159. 'lable' => $this->translator->trans('Does Not Contain'),
  160. 'value' => 'notContains'
  161. ],
  162. ],
  163. 'string' => [
  164. [
  165. 'lable' => $this->translator->trans('Is Equal To'),
  166. 'value' => 'is'
  167. ],
  168. [
  169. 'lable' => $this->translator->trans('Is Not Equal To'),
  170. 'value' => 'isNot'
  171. ],
  172. [
  173. 'lable' => $this->translator->trans('Contains'),
  174. 'value' => 'contains'
  175. ],
  176. [
  177. 'lable' => $this->translator->trans('Does Not Contain'),
  178. 'value' => 'notContains'
  179. ],
  180. [
  181. 'lable' => $this->translator->trans('Starts With'),
  182. 'value' => 'startWith'
  183. ],
  184. [
  185. 'lable' => $this->translator->trans('Ends With'),
  186. 'value' => 'endWith'
  187. ],
  188. ],
  189. 'select' => [
  190. [
  191. 'lable' => $this->translator->trans('Is Equal To'),
  192. 'value' => 'is'
  193. ],
  194. [
  195. 'lable' => $this->translator->trans('Is Not Equal To'),
  196. 'value' => 'isNot'
  197. ],
  198. ],
  199. 'date' => [
  200. [
  201. 'lable' => $this->translator->trans('Before'),
  202. 'value' => 'before'
  203. ],
  204. [
  205. 'lable' => $this->translator->trans('Before On'),
  206. 'value' => 'beforeOn'
  207. ],
  208. [
  209. 'lable' => $this->translator->trans('After'),
  210. 'value' => 'after'
  211. ],
  212. [
  213. 'lable' => $this->translator->trans('After On'),
  214. 'value' => 'afterOn'
  215. ],
  216. ],
  217. 'datetime' => [
  218. [
  219. 'lable' => $this->translator->trans('Before'),
  220. 'value' => 'beforeDateTime'
  221. ],
  222. [
  223. 'lable' => $this->translator->trans('Before On'),
  224. 'value' => 'beforeDateTimeOn'
  225. ],
  226. [
  227. 'lable' => $this->translator->trans('After'),
  228. 'value' => 'afterDateTime'
  229. ],
  230. [
  231. 'lable' => $this->translator->trans('After On'),
  232. 'value' => 'afterDateTimeOn'
  233. ],
  234. ],
  235. 'time' => [
  236. [
  237. 'lable' => $this->translator->trans('Before'),
  238. 'value' => 'beforeTime'
  239. ],
  240. [
  241. 'lable' => $this->translator->trans('Before On'),
  242. 'value' => 'beforeTimeOn'
  243. ],
  244. [
  245. 'lable' => $this->translator->trans('After'),
  246. 'value' => 'afterTime'
  247. ],
  248. [
  249. 'lable' => $this->translator->trans('After On'),
  250. 'value' => 'afterTimeOn'
  251. ],
  252. ],
  253. 'number' => [
  254. [
  255. 'lable' => $this->translator->trans('Is Equal To'),
  256. 'value' => 'is'
  257. ],
  258. [
  259. 'lable' => $this->translator->trans('Is Not Equal To'),
  260. 'value' => 'isNot'
  261. ],
  262. [
  263. 'lable' => $this->translator->trans('Contains'),
  264. 'value' => 'contains'
  265. ],
  266. [
  267. 'lable' => $this->translator->trans('Greater Than'),
  268. 'value' => 'greaterThan'
  269. ],
  270. [
  271. 'lable' => $this->translator->trans('Less Than'),
  272. 'value' => 'lessThan'
  273. ],
  274. ],
  275. ];
  276. }
  277. public function getWorkflowActions($force = false)
  278. {
  279. $workflowActions = [];
  280. // @TODO: Add minimum required access levels to workflow actions to restrict usage
  281. foreach ($this->container->get('uvdesk.automations.workflows')->getRegisteredWorkflowActions() as $workflowDefinition) {
  282. $functionalGroup = $workflowDefinition->getFunctionalGroup();
  283. if (!isset($workflowActions[$functionalGroup])) {
  284. $workflowActions[$functionalGroup] = [];
  285. }
  286. $workflowActions[$functionalGroup][$workflowDefinition->getId()] = $this->translator->trans($workflowDefinition->getDescription());
  287. }
  288. return $workflowActions;
  289. }
  290. public function getPreparedResponseActions($force = false)
  291. {
  292. $preparedResponseActions = [];
  293. // @TODO: Add minimum required access levels to prepared response actions to restrict usage
  294. foreach ($this->container->get('uvdesk.automations.prepared_responses')->getRegisteredPreparedResponseActions() as $preparedResponseDefinition) {
  295. $functionalGroup = $preparedResponseDefinition->getFunctionalGroup();
  296. if (!isset($preparedResponseActions[$functionalGroup])) {
  297. $preparedResponseActions[$functionalGroup] = [];
  298. }
  299. $preparedResponseActions[$functionalGroup][$preparedResponseDefinition->getId()] = $this->translator->trans($preparedResponseDefinition->getDescription());
  300. }
  301. return $preparedResponseActions;
  302. }
  303. }