VariableEffect.class.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. Effet de workflow
  4. Définit une variable (scopée workflow) à la valeur indiquée
  5. */
  6. class VariableEffect{
  7. //Descriptif du type d'effet
  8. public static function manifest($key = null){
  9. $manifest = array(
  10. 'slug' => 'var',
  11. 'label' => 'Définir une variable',
  12. 'class' => get_called_class(),
  13. 'path' => __FILE__,
  14. 'icon' => 'fas fa-dollar-sign',
  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. Variable :
  30. </div>
  31. <input type="text" data-id="variable-slug" class="form-control" value="<?php echo isset($item['variable-slug']) ? $item['variable-slug'] : '' ?>" placeholder="Ma variable" required>
  32. </div>
  33. <div class="input-group mt-1">
  34. <div class="input-group-text input-group-prepend">
  35. Valeur :
  36. </div>
  37. <input type="text" data-id="variable-value" class="form-control" value="<?php echo isset($item['variable-value']) ? $item['variable-value'] : '' ?>" placeholder="Valeur de la variable">
  38. </div>
  39. <?php
  40. $html = ob_get_clean();
  41. return $html;
  42. }
  43. public static function run($effect,$parameters = array()){
  44. global $conf;
  45. $logs = '';
  46. if( in_array($parameters['workflow']['type'] , array( Workflow::TYPE_ENTITY, Workflow::TYPE_LIST)) ){
  47. if(isset($parameters['current'])) $parameters['current'] = $parameters['current']->toArray();
  48. if(isset($parameters['old'])) $parameters['old'] = $parameters['old']->toArray();
  49. }
  50. if(!isset($effect->values['variable-slug'])) throw new Exception("Nom de la variable non défini");
  51. $effect->values['variable-slug'] = template($effect->values['variable-slug'],$parameters,true);
  52. $effect->values['variable-value'] = isset($effect->values['variable-value']) ? template($effect->values['variable-value'],$parameters,true) : '';
  53. $workflowVars = json_decode($conf->get('workflow-var'),true);
  54. $workflowVars[$effect->values['variable-slug']] = $effect->values['variable-value'];
  55. $conf->put('workflow-var', json_encode($workflowVars));
  56. $logs .= '<i class="fas fa-dollar-sign"></i> '.$effect->values['variable-slug'].' passée à '.$effect->values['variable-value'];
  57. return $logs;
  58. }
  59. }
  60. ?>