WorkflowTrait.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. * @return string
  58. */
  59. public function getTransitionWorkflow()
  60. {
  61. return "transition_state";
  62. }
  63. /**
  64. * @return null|string
  65. */
  66. public function getWorkflowType()
  67. {
  68. $workflow = $this->getWorkflow();
  69. if ($workflow) {
  70. return $workflow->getType();
  71. }
  72. return null;
  73. }
  74. /**
  75. * @return null|string
  76. */
  77. public function getWorkflowName()
  78. {
  79. $workflow = $this->getWorkflow();
  80. if ($workflow) {
  81. return $workflow->getName();
  82. }
  83. return null;
  84. }
  85. /**
  86. * Para coincider entre estos workflow servidos por servicio y aquellos levantados por ABM
  87. *
  88. * @global AppKernel $kernel
  89. *
  90. * @return Workflow
  91. */
  92. public function getServiceWorkflow()
  93. {
  94. global $kernel;
  95. $registry = $kernel->getContainer()->get('workflow.registry');
  96. $workflow_name = null;
  97. $workflow = $this->getWorkflow();
  98. if ($workflow) {
  99. $workflow_name = $workflow->getName();
  100. }
  101. try {
  102. $workflow = $registry->get($this, $workflow_name);
  103. } catch (ExceptionInterface $e) {
  104. $kernel->getContainer()->get('session')->getFlashBag()->add('danger', $kernel->getContainer()->get('translator')->trans('Incorrect Workflow', array(), 'FTTHBundle'));
  105. return null;
  106. }
  107. return $workflow;
  108. }
  109. }