|
@@ -23,7 +23,8 @@ class WorkflowExtension extends \Twig_Extension
|
|
|
new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')),
|
|
|
new \Twig_SimpleFunction('workflow_correct_state', array($this, 'isCorrectState')),
|
|
|
new \Twig_SimpleFunction('get_class', array($this, 'getClass')),
|
|
|
- new \Twig_SimpleFunction('workflow_translate_label', array($this, 'getLabelTranslate'))
|
|
|
+ new \Twig_SimpleFunction('workflow_translate_label', array($this, 'getLabelTranslate')),
|
|
|
+ new \Twig_SimpleFunction('workflow_go_json', array($this, 'getGoJson')),
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -82,4 +83,52 @@ class WorkflowExtension extends \Twig_Extension
|
|
|
|
|
|
return $trans;
|
|
|
}
|
|
|
+
|
|
|
+ public function getGoJson($object, $name = null)
|
|
|
+ {
|
|
|
+ $data = array();
|
|
|
+ $nodes = array();
|
|
|
+ $links = array();
|
|
|
+
|
|
|
+ $c = "FTTHBundle\Entity\ONU";
|
|
|
+ $class = "\\$c";
|
|
|
+ $object = new $class();
|
|
|
+ //print_r(get_class($object));
|
|
|
+ //die;
|
|
|
+
|
|
|
+ $definition = $this->workflowRegistry->get($object, $name)->getDefinition();
|
|
|
+ $places = $definition->getPlaces();
|
|
|
+ $initial = $definition->getInitialPlace();
|
|
|
+ $transitions = $definition->getTransitions();
|
|
|
+
|
|
|
+ foreach($places as $p => $place) {
|
|
|
+
|
|
|
+ $label = $p;
|
|
|
+
|
|
|
+ $color = "white";
|
|
|
+ if($p == $initial) $color = "lightblue";
|
|
|
+ $nodes[] = array('key' => $label, 'color' => $color);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($transitions as $transition) {
|
|
|
+
|
|
|
+ $label = $transition->getName();
|
|
|
+ $from = $transition->getFroms()[0];
|
|
|
+ $to = $transition->getTos()[0];
|
|
|
+
|
|
|
+ $links[] = array('from' => $from, 'to' => $to, 'text' => $label);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data[] = $nodes;
|
|
|
+ $data[] = $links;
|
|
|
+
|
|
|
+ //return $data;
|
|
|
+
|
|
|
+ $return = json_encode($nodes).",".json_encode($links);
|
|
|
+
|
|
|
+
|
|
|
+ return $return;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|