VariableCause.class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. Cause de workflow
  4. Compare une variable (scopée sur le workflow) en configuration avec la valeur définie dans la cause
  5. */
  6. class VariableCause{
  7. //Descriptif de la cause
  8. public static function manifest($key = null){
  9. $manifest = array(
  10. 'slug' => 'var',
  11. 'label' => 'Variable',
  12. 'type' => array(Workflow::TYPE_ALL),
  13. 'class' => get_called_class(),
  14. 'path' => __FILE__,
  15. 'icon' => 'fas fa-dollar-sign',
  16. 'attributes' => ' data-filter-type="configuration-var" ',
  17. 'color' => '#ff9f43',
  18. );
  19. if(!isset($key)) return $manifest;
  20. return isset($manifest[$key]) ? $manifest[$key] : '' ;
  21. }
  22. //Type de filtre de cause custom pour cette cause (champs additionnels)
  23. public static function filter($entity = array()){
  24. $stream = '<div class="filter-value-block" data-value-type="configuration-var" data-value-selector=".filter-value:last-child">
  25. <div class="filter-subfield d-inline-block">
  26. <i class="fas fa-dollar-sign"></i> <input type="text" data-id="var-slug" class="d-inline-block mt-2 border-0 font-weight-bold text-primary" placeholder="Nom de la variable">';
  27. $stream .='
  28. </div>
  29. <select class="form-control filter-operator border-0 text-primary">
  30. <option value="=">Égal</option>
  31. <option value="!=">Différent</option>
  32. <option value=">">Inférieur</option>
  33. <option value="<">Supérieur</option>
  34. <option value="like">Contient</option>
  35. </select>
  36. <input type="text" class="form-control filter-value" >
  37. </div>';
  38. return $stream;;
  39. }
  40. //Méthode de vérification de la cause
  41. public static function check($filter,$parameters = array()){
  42. global $conf;
  43. //On récupere sans passer par le $conf->get dont le cache session n'ets aps compatible avec les workflows
  44. $theConf = Configuration::load(array('key'=>'workflow-var'));
  45. $confValue = !$theConf ? '{}' : decrypt($theConf->value);
  46. $workflowVars = json_decode($confValue,true);
  47. $varValue = isset($workflowVars[$filter['subcolumn']['var-slug']]) ? $workflowVars[$filter['subcolumn']['var-slug']] :'';
  48. global $conf;
  49. switch($filter['operator']){
  50. case '=':
  51. if($varValue != $filter['value'][0]) return false;
  52. break;
  53. case '!=':
  54. if($varValue == $filter['value'][0]) return false;
  55. break;
  56. case '<':
  57. if($varValue > $filter['value'][0]) return false;
  58. break;
  59. case '>':
  60. if($varValue < $filter['value'][0]) return false;
  61. break;
  62. case 'like':
  63. if( strpos( mb_strtolower($varValue), mb_strtolower($filter['value'][0]) ) === false ) return false;
  64. break;
  65. }
  66. return true;
  67. }
  68. }
  69. ?>