WorkflowTrait.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace WorkflowBundle\Entity\Traits;
  3. trait WorkflowTrait
  4. {
  5. /**
  6. * @return Workflow
  7. */
  8. public function getWorkflow()
  9. {
  10. return $this->workflow;
  11. }
  12. /**
  13. * @param Workflow $workflow
  14. *
  15. * @return $this
  16. */
  17. public function setWorkflow($workflow)
  18. {
  19. $this->workflow = $workflow;
  20. return $this;
  21. }
  22. /**
  23. * @return string
  24. */
  25. public function getCurrentState()
  26. {
  27. return $this->currentState;
  28. }
  29. /**
  30. * @param string $currentState
  31. *
  32. * @return WorkflowInterface
  33. */
  34. public function setCurrentState($currentState)
  35. {
  36. $this->currentState = $currentState;
  37. return $this;
  38. }
  39. /**
  40. * @return string
  41. */
  42. public function getTransitionState()
  43. {
  44. return $this->transitionState;
  45. }
  46. /**
  47. * @param string $transitionState
  48. *
  49. * @return WorkflowInterface
  50. */
  51. public function setTransitionState($transitionState)
  52. {
  53. $this->transitionState = $transitionState;
  54. return $this;
  55. }
  56. /**
  57. * Retorna el administrativeState en caso que exista en la entidad
  58. *
  59. * @return string
  60. */
  61. public function getAdministrativeState()
  62. {
  63. return property_exists(self::class, 'administrativeState') ? $this->administrativeState : null;
  64. }
  65. /**
  66. * Setea el administrativeState en caso que exista en la entidad
  67. *
  68. * @param string $transitionState
  69. *
  70. * @return WorkflowInterface
  71. */
  72. public function setAdministrativeState($administrativeState)
  73. {
  74. if (property_exists(self::class, 'administrativeState')) {
  75. $this->administrativeState = $administrativeState;
  76. }
  77. return $this;
  78. }
  79. /**
  80. * @return string
  81. */
  82. public function getTransitionWorkflow()
  83. {
  84. return "transition_state";
  85. }
  86. /**
  87. * @return null|string
  88. */
  89. public function getWorkflowType()
  90. {
  91. $workflow = $this->getWorkflow();
  92. if ($workflow) {
  93. return $workflow->getType();
  94. }
  95. return null;
  96. }
  97. /**
  98. * @return null|string
  99. */
  100. public function getWorkflowName()
  101. {
  102. $workflow = $this->getWorkflow();
  103. if ($workflow) {
  104. return $workflow->getName();
  105. }
  106. return null;
  107. }
  108. /**
  109. * Para coincider entre estos workflow servidos por servicio y aquellos levantados por ABM
  110. *
  111. * @global AppKernel $kernel
  112. *
  113. * @return Workflow
  114. */
  115. public function getServiceWorkflow()
  116. {
  117. global $kernel;
  118. $registry = $kernel->getContainer()->get('workflow.registry');
  119. $workflow_name = null;
  120. $workflow = $this->getWorkflow();
  121. if ($workflow) {
  122. $workflow_name = $workflow->getName();
  123. }
  124. try {
  125. $workflow = $registry->get($this, $workflow_name);
  126. } catch (ExceptionInterface $e) {
  127. $kernel->getContainer()->get('session')->getFlashBag()->add('danger', $kernel->getContainer()->get('translator')->trans('Incorrect Workflow', array(), 'FTTHBundle'));
  128. return null;
  129. }
  130. return $workflow;
  131. }
  132. }