WorkflowAdmin.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace WorkflowBundle\Admin;
  3. use Base\AdminBundle\Admin\BaseAdmin;
  4. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  5. use Sonata\AdminBundle\Datagrid\ListMapper;
  6. use Sonata\AdminBundle\Form\FormMapper;
  7. use Sonata\AdminBundle\Show\ShowMapper;
  8. use Symfony\Component\Yaml\Yaml;
  9. use WorkflowBundle\Utils\WorkFlowEntityClasses;
  10. class WorkflowAdmin extends BaseAdmin
  11. {
  12. public function getTemplate($name)
  13. {
  14. switch ($name) {
  15. case 'edit':
  16. return 'WorkflowBundle:Workflow:workflow_edit.html.twig';
  17. break;
  18. default:
  19. return parent::getTemplate($name);
  20. break;
  21. }
  22. }
  23. /**
  24. * @param DatagridMapper $datagridMapper
  25. */
  26. protected function configureDatagridFilters(DatagridMapper $datagridMapper)
  27. {
  28. $datagridMapper
  29. ->add('name')
  30. ->add('description')
  31. ->add('enable')
  32. ->add('template')
  33. ;
  34. }
  35. /**
  36. * @param ListMapper $listMapper
  37. */
  38. protected function configureListFields(ListMapper $listMapper)
  39. {
  40. $listMapper
  41. ->add('name')
  42. ->add('description')
  43. ->add('enable')
  44. ->add('_action', null, array(
  45. 'actions' => array(
  46. 'show' => array(),
  47. 'edit' => array(),
  48. 'delete' => array()
  49. )
  50. ))
  51. ;
  52. }
  53. /**
  54. * @param FormMapper $formMapper
  55. */
  56. protected function configureFormFields(FormMapper $formMapper)
  57. {
  58. $template_example =
  59. "
  60. initial_place: state_two
  61. places:
  62. - state_one
  63. - state_two
  64. - state_three
  65. transitions:
  66. one_to_two:
  67. from: state_one
  68. to: state_two
  69. two_to_three:
  70. from: state_two
  71. to: state_three
  72. two_to_one:
  73. from: state_two
  74. to: state_one
  75. three_to_one:
  76. from: state_three
  77. to: state_one
  78. ";
  79. // Create => template_example
  80. $tempate_options = array("attr" => array('style' => 'height:500px;'));
  81. if(is_null($this->getSubject()->getId())) {
  82. $tempate_options['data'] = $template_example;
  83. } else {
  84. $this->parameters = array('workflow_name' => $this->getSubject()->getName());
  85. }
  86. $_supports = WorkFlowEntityClasses::getClass();
  87. $supports = array();
  88. foreach($_supports as $key => $class) {
  89. if(class_exists($key)) {
  90. $supports[$key] = $key;
  91. }
  92. }
  93. $formMapper
  94. ->add('name')
  95. ->add('description')
  96. ->add('enable')
  97. ->add('type', 'choice', array('choices' => array('state_machine' => 'state_machine', 'workflow' => 'workflow')))
  98. ->add('markingType', 'choice', array('choices' => array('single_state' => 'single_state', 'multiple_state' => 'multiple_state')))
  99. ->add('markingName', 'choice', array('choices' => array('currentState' => 'currentState')))
  100. ->add('support', 'choice', array('choices' => $supports,'multiple' => true, 'required' => true))
  101. ->add('template', null, $tempate_options)
  102. ->setHelps(array(
  103. 'name' => $this->trans("helps.workflow_label_name"),
  104. 'type' => $this->trans("helps.workflow_label_type"),
  105. 'markingType' => $this->trans("helps.workflow_label_marking_type"),
  106. 'markingName' => $this->trans("helps.workflow_label_marking_name"),
  107. 'template' => $this->trans("helps.workflow_label_template"),
  108. ))
  109. ;
  110. }
  111. /**
  112. * @param ShowMapper $showMapper
  113. */
  114. protected function configureShowFields(ShowMapper $showMapper)
  115. {
  116. $showMapper
  117. ->add('id')
  118. ->add('name')
  119. ->add('description')
  120. ->add('enable')
  121. ->add('created')
  122. ->add('updated')
  123. ->add('type')
  124. ->add('markingType')
  125. ->add('markingName')
  126. ->add('support')
  127. ->add('template','string', array('template' => 'WorkflowBundle:Workflow:show_template.html.twig'))
  128. ;
  129. }
  130. }