Browse Source

Se agrego una Interface y un Trait para las entidades asociadas a Workflow

Guillermo Espinoza 7 năm trước cách đây
mục cha
commit
4de74f50d7
2 tập tin đã thay đổi với 175 bổ sung0 xóa
  1. 43 0
      Entity/Interfaces/WorkflowInterface.php
  2. 132 0
      Entity/Traits/WorkflowTrait.php

+ 43 - 0
Entity/Interfaces/WorkflowInterface.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace WorkflowBundle\Entity\Interfaces;
+
+interface WorkflowInterface
+{
+
+    /**
+     * @return Workflow
+     */
+    public function getWorkflow();
+
+    /**
+     * @param Workflow $workflow
+     * 
+     * @return $this
+     */
+    public function setWorkflow($workflow);
+
+    /**
+     * @return string
+     */
+    public function getCurrentState();
+
+    /**
+     * @param string $currentState
+     * 
+     * @return WorkflowInterface
+     */
+    public function setCurrentState($currentState);
+
+    /**
+     * @return string
+     */
+    public function getTransitionState();
+
+    /**
+     * @param string $transitionState
+     * 
+     * @return WorkflowInterface
+     */
+    public function setTransitionState($transitionState);
+}

+ 132 - 0
Entity/Traits/WorkflowTrait.php

@@ -0,0 +1,132 @@
+<?php
+
+namespace WorkflowBundle\Entity\Traits;
+
+trait WorkflowTrait
+{
+
+    /**
+     * @return Workflow
+     */
+    public function getWorkflow()
+    {
+        return $this->workflow;
+    }
+
+    /**
+     * @param Workflow $workflow
+     * 
+     * @return $this
+     */
+    public function setWorkflow($workflow)
+    {
+        $this->workflow = $workflow;
+
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function getCurrentState()
+    {
+        return $this->currentState;
+    }
+
+    /**
+     * @param string $currentState
+     * 
+     * @return WorkflowInterface
+     */
+    public function setCurrentState($currentState)
+    {
+        $this->currentState = $currentState;
+
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function getTransitionState()
+    {
+        return $this->transitionState;
+    }
+
+    /**
+     * @param string $transitionState
+     * 
+     * @return WorkflowInterface
+     */
+    public function setTransitionState($transitionState)
+    {
+        $this->transitionState = $transitionState;
+
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function getTransitionWorkflow()
+    {
+        return "transition_state";
+    }
+
+    /**
+     * @return null|string
+     */
+    public function getWorkflowType()
+    {
+        $workflow = $this->getWorkflow();
+
+        if ($workflow) {
+            return $workflow->getType();
+        }
+
+        return null;
+    }
+
+    /**
+     * @return null|string
+     */
+    public function getWorkflowName()
+    {
+        $workflow = $this->getWorkflow();
+
+        if ($workflow) {
+            return $workflow->getName();
+        }
+
+        return null;
+    }
+
+    /**
+     * Para coincider entre estos workflow servidos por servicio y aquellos levantados por ABM
+     * 
+     * @global AppKernel $kernel
+     * 
+     * @return Workflow
+     */
+    public function getServiceWorkflow()
+    {
+        global $kernel;
+        $registry = $kernel->getContainer()->get('workflow.registry');
+
+        $workflow_name = null;
+        $workflow = $this->getWorkflow();
+        if ($workflow) {
+            $workflow_name = $workflow->getName();
+        }
+
+        try {
+            $workflow = $registry->get($this, $workflow_name);
+        } catch (ExceptionInterface $e) {
+            $kernel->getContainer()->get('session')->getFlashBag()->add('danger', $kernel->getContainer()->get('translator')->trans('Incorrect Workflow', array(), 'FTTHBundle'));
+            return null;
+        }
+
+        return $workflow;
+    }
+
+}