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.

78 lines
2.2 KiB

5 years ago
  1. <?php
  2. namespace Zitec\RuleEngineBundle\Conditions;
  3. /**
  4. * Class SearchDay
  5. */
  6. class CurrentDay extends AbstractValueCondition
  7. {
  8. /**
  9. * @var string
  10. */
  11. protected $name = 'current_day';
  12. /**
  13. * @var string
  14. */
  15. protected $label = 'Current Day';
  16. /**
  17. * @var string
  18. */
  19. protected $description = 'Conditions for the current day of the week';
  20. /**
  21. * @return array
  22. */
  23. protected function getOperatorDefinitions(): array
  24. {
  25. $timestamp = strtotime('next Sunday');
  26. $days = [];
  27. for ($i = 0; $i < 7; $i++) {
  28. $days[] = ['key' => $i, 'label' => strftime('%A', $timestamp)];
  29. $timestamp = strtotime('+1 day', $timestamp);
  30. }
  31. return [
  32. [
  33. 'label' => 'weekday in',
  34. 'name' => $this::VALUE_IN,
  35. 'fieldType' => 'select',
  36. 'fieldOptions' => [
  37. 'multiple' => true,
  38. 'enableSelect2' => true,
  39. 'options' => $days,
  40. ],
  41. 'value_view_transform' => function ($val) {
  42. return array_map(
  43. function ($v) {
  44. $map = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
  45. return $map[$v];
  46. },
  47. $val
  48. );
  49. },
  50. ],
  51. [
  52. 'label' => 'weekday NOT in',
  53. 'name' => $this::VALUE_NOT_IN,
  54. 'fieldType' => 'select',
  55. 'fieldOptions' => [
  56. 'multiple' => true,
  57. 'enableSelect2' => true,
  58. 'options' => $days,
  59. ],
  60. 'value_view_transform' => function ($val) {
  61. return array_map(
  62. function ($v) {
  63. $map = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
  64. return $map[$v];
  65. },
  66. $val
  67. );
  68. },
  69. ],
  70. ];
  71. }
  72. }