123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace WorkflowBundle\Admin;
- use Base\AdminBundle\Admin\BaseAdmin;
- class WorkflowBaseAdmin extends BaseAdmin
- {
- /**
- * @return array
- */
- public function getBatchActions()
- {
- $actions = parent::getBatchActions();
- $workflows = array();
- $registry = $this->get('workflow.registry');
- $class = $this->getClass();
- $tmpEntity = new $class();
- try {
- $workflows = $this->getRepository('WorkflowBundle:Workflow')->findAllByClass($this->getClass());
- // No hay workflows en db, pruebo traer desde el workflow registry
- if (count($workflows) == 0) {
- $workflows[] = $registry->get($tmpEntity);
- }
- } catch (\Exception $ex) {
- // No hay workflows en db, pruebo traer desde el workflow registry
- // con los names definidos en el admin $batchWorkflows
- if (isset($this->batchWorkflows)) {
- foreach ($this->batchWorkflows as $name) {
- $workflows[] = $registry->get($tmpEntity, $name);
- }
- }
- }
-
- foreach ($workflows as $workflow) {
- $definition = method_exists($workflow, 'getSubject')
- ? $workflow->getDefinition($workflow->getSubject())
- : $workflow->getDefinition();
- $transitions = $definition ? $definition->getTransitions() : array();
- foreach ($transitions as $transition) {
- $label = $this->trans('workflow.' . $workflow->getName() . '.transitions.' . $transition->getName(), array(), 'WorkflowLabel');
- $label .= " ( {$transition->getName()} )";
- $actions[$transition->getName()] = array(
- 'label' => $label,
- 'ask_confirmation' => true,
- 'workflow' => array(
- 'name' => $workflow->getName(),
- 'transition' => $transition->getName(),
- ),
- );
- }
- }
- asort($actions);
-
- return $actions;
- }
- }
|