HourCause.class.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. Cause de workflow
  4. Compare l'heure courante à la valeur définie dans la cause
  5. */
  6. class HourCause{
  7. //Descriptif de la cause
  8. public static function manifest($key = null){
  9. $manifest = array(
  10. 'slug' => 'hour',
  11. 'label' => 'Heure',
  12. 'type' => array(Workflow::TYPE_GLOBAL,Workflow::TYPE_ALL),
  13. 'class' => get_called_class(),
  14. 'path' => __FILE__,
  15. 'icon' => 'far fa-clock',
  16. 'attributes' => ' data-filter-type="hour" ',
  17. 'color' => '#ff9f43',
  18. );
  19. if(!isset($key)) return $manifest;
  20. return isset($manifest[$key]) ? $manifest[$key] : '' ;
  21. }
  22. //Méthode de vérification de la cause
  23. public static function check($filter,$parameters = array()){
  24. $hour = date('H');
  25. $minuts = date('i');
  26. if(isset($filter['value'][0])){
  27. $compareTo = explode(':',$filter['value'][0]);
  28. $compareHourTo = $compareTo[0];
  29. $compareMinutTo = $compareTo[1];
  30. }
  31. switch($filter['operator']){
  32. case 'between':
  33. $compareTo2 = explode(':',$filter['value'][1]);
  34. $compareHourTo2 = $compareTo2[0];
  35. $compareMinutTo2 = $compareTo2[1];
  36. if($compareHourTo > $hour ) return false;
  37. if($compareHourTo == $hour && $compareMinutTo > $minuts ) return false;
  38. if($compareHourTo2 < $hour ) return false;
  39. if($compareHourTo2 == $hour && $compareMinutTo2 < $minuts ) return false;
  40. break;
  41. case '<':
  42. if($compareHourTo < $hour ) return false;
  43. if($compareHourTo == $hour && $compareMinutTo < $minuts ) return false;
  44. break;
  45. case '>':
  46. if($compareHourTo > $hour ) return false;
  47. if($compareHourTo == $hour && $compareMinutTo > $minuts ) return false;
  48. break;
  49. case '=':
  50. if($compareHourTo != $hour || $compareMinutTo != $minuts) return false;
  51. break;
  52. case 'is null':
  53. return false;
  54. break;
  55. }
  56. return true;
  57. }
  58. }
  59. ?>