LoadWorkflowEffect.class.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. Effet de workflow
  4. Execute un autre workflow, nb: le workflow executé doit être du même type que le workflow executant
  5. */
  6. class LoadWorkflowEffect{
  7. //Descriptif du type d'effet
  8. public static function manifest($key = null){
  9. $manifest = array(
  10. 'slug' => 'workflow',
  11. 'label' => 'Lancer un workflow',
  12. 'class' => get_called_class(),
  13. 'path' => __FILE__,
  14. 'icon' => 'fas fa-network-wired',
  15. 'color' => '#ff9f43',
  16. );
  17. if(!isset($key)) return $manifest;
  18. return isset($manifest[$key]) ? $manifest[$key] : '' ;
  19. }
  20. //méthode d'affichage de l'effet
  21. public static function form($item){
  22. $html = '';
  23. $class = get_called_class();
  24. //$class::manifest('icon')
  25. ob_start();
  26. ?>
  27. <div class="input-group">
  28. <div class="input-group-text input-group-prepend">
  29. Workflow :
  30. </div>
  31. <input type="text" data-id="workflow-id" class="form-control" value="<?php echo isset($item['workflow-id']) ? $item['workflow-id'] : '' ?>" placeholder="Id du workflow">
  32. </div>
  33. <?php
  34. $html = ob_get_clean();
  35. return $html;
  36. }
  37. public static function run($effect,$parameters = array()){
  38. global $conf;
  39. $logs = '';
  40. if( in_array($parameters['workflow']['type'] , array( Workflow::TYPE_ENTITY, Workflow::TYPE_LIST)) ){
  41. if(isset($parameters['current'])) $parameters['current'] = $parameters['current']->toArray();
  42. if(isset($parameters['old'])) $parameters['old'] = $parameters['old']->toArray();
  43. }
  44. $effect->values['workflow-id'] = template($effect->values['workflow-id'],$parameters,true);
  45. $toLoad = Workflow::getById($effect->values['workflow-id']);
  46. if(!$toLoad){
  47. $logs.=' Workflow inexistant';
  48. return $logs;
  49. }
  50. if( $parameters['workflow']['type'] != $toLoad->type ){
  51. $logs.=" Workflow d'origine d'un type différent du workflow de destination";
  52. return $logs;
  53. }
  54. $logs .= '<i class="'.self::manifest('icon').'"></i> Lancement de '.$toLoad->label;
  55. $logs .= implode('<br>',$toLoad->run(null,$parameters));
  56. return $logs;
  57. }
  58. }
  59. ?>