DateCause.class.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. Cause de workflow
  4. Compare la date courante à la valeur définie dans la cause
  5. */
  6. class DateCause{
  7. //Descriptif de la cause
  8. public static function manifest($key = null){
  9. $manifest = array(
  10. 'slug' => 'date',
  11. 'label' => 'Date',
  12. 'type' => array(Workflow::TYPE_GLOBAL,Workflow::TYPE_ALL),
  13. 'class' => get_called_class(),
  14. 'path' => __FILE__,
  15. 'icon' => 'far fa-calendar-alt',
  16. 'attributes' => ' data-filter-type="date" ',
  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. $compareIn = mktime(0,0,0);
  25. switch($filter['operator']){
  26. case 'between':
  27. $compareTo = timestamp_date($filter['value'][0]);
  28. $compareTo2 = timestamp_date($filter['value'][1]);
  29. if( $compareIn < $compareTo || $compareIn > $compareTo2 ) return false;
  30. break;
  31. case '<':
  32. $compareTo = timestamp_date($filter['value'][0]);
  33. if($compareIn >= $compareTo) return false;
  34. break;
  35. case '>':
  36. $compareTo = timestamp_date($filter['value'][0]);
  37. if($compareIn <= $compareTo) return false;
  38. break;
  39. case '=':
  40. $compareTo = timestamp_date($filter['value'][0]);
  41. if($compareIn != $compareTo) return false;
  42. break;
  43. case 'is null':
  44. if(!empty($compareIn)) return false;
  45. break;
  46. case 'is not null':
  47. if(empty($compareIn)) return false;
  48. break;
  49. }
  50. return true;
  51. }
  52. }
  53. ?>