Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

5 years ago
  1. <?php
  2. namespace Zitec\RuleEngineBundle\Conditions;
  3. /**
  4. * Class CurrentDate
  5. */
  6. class CurrentDate extends AbstractValueCondition
  7. {
  8. /**
  9. * @var string
  10. */
  11. protected $name = 'current_date';
  12. /**
  13. * @var string
  14. */
  15. protected $label = 'Current Date';
  16. /**
  17. * @var string
  18. */
  19. protected $description = 'Conditions for the current date/time';
  20. /**
  21. * @return array
  22. */
  23. protected function getOperatorDefinitions(): array
  24. {
  25. return [
  26. [
  27. 'label' => 'date is after',
  28. 'name' => $this::GREATER,
  29. 'fieldType' => 'datetime',
  30. 'value_transform' => function ($val) {
  31. return strtotime($val . ' + 1 day');
  32. },
  33. ],
  34. [
  35. 'label' => 'date is before',
  36. 'name' => $this::SMALLER,
  37. 'fieldType' => 'datetime',
  38. 'value_transform' => function ($val) {
  39. return strtotime($val);
  40. },
  41. ],
  42. [
  43. 'label' => 'Date between',
  44. 'name' => $this::INTERVAL,
  45. 'fieldType' => 'datetime_interval',
  46. 'value_transform' => function ($val) {
  47. return isset($val['from']) && isset($val['to']) ?
  48. ['from' => strtotime($val['from']), 'to' => strtotime($val['to'] . ' 23:59:59')] : null;
  49. },
  50. ],
  51. ];
  52. }
  53. }