WorkflowAdmin.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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(), 'workflow_subject' => $this->getSubject()->getSubject());
  85. }
  86. $formMapper
  87. ->add('name')
  88. ->add('description')
  89. ->add('enable')
  90. ->add('type', 'choice', array('choices' => array('state_machine' => 'state_machine', 'workflow' => 'workflow')))
  91. ->add('markingType', 'choice', array('choices' => array('single_state' => 'single_state', 'multiple_state' => 'multiple_state')))
  92. ->add('markingName', 'choice', array('choices' => array('currentState' => 'currentState')))
  93. ->add('support', 'choice', array(
  94. 'choices' => array_filter(WorkFlowEntityClasses::getChoices(), 'class_exists'),
  95. 'multiple' => true,
  96. 'required' => true
  97. ))
  98. ->add('template', null, $tempate_options)
  99. ->setHelps(array(
  100. 'name' => $this->trans("helps.workflow_label_name"),
  101. 'type' => $this->trans("helps.workflow_label_type"),
  102. 'markingType' => $this->trans("helps.workflow_label_marking_type"),
  103. 'markingName' => $this->trans("helps.workflow_label_marking_name"),
  104. 'template' => $this->trans("helps.workflow_label_template"),
  105. ))
  106. ;
  107. /*
  108. if(is_null($this->getSubject()->getId())) {
  109. $formMapper
  110. ->add('subject', null, array('template' => 'WorkflowBundle:Workflow:'));
  111. }
  112. */
  113. }
  114. /**
  115. * @param ShowMapper $showMapper
  116. */
  117. protected function configureShowFields(ShowMapper $showMapper)
  118. {
  119. $showMapper
  120. ->add('id')
  121. ->add('name')
  122. ->add('description')
  123. ->add('enable')
  124. ->add('created')
  125. ->add('updated')
  126. ->add('type')
  127. ->add('markingType')
  128. ->add('markingName')
  129. ->add('support')
  130. ->add('template','string', array('template' => 'WorkflowBundle:Workflow:show_template.html.twig'))
  131. ;
  132. }
  133. }