Condition.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\Adminhtml\Source\Rules;
  3. class Condition
  4. {
  5. /**
  6. * Options array.
  7. *
  8. * @return array
  9. */
  10. public function toOptionArray()
  11. {
  12. $options = [
  13. ['value' => 'eq', 'label' => __('is')],
  14. ['value' => 'neq', 'label' => __('is not')],
  15. ['value' => 'null', 'label' => __('is empty')],
  16. ];
  17. return $options;
  18. }
  19. /**
  20. * Get condition options according to type.
  21. *
  22. * @param string $type
  23. *
  24. * @return array
  25. */
  26. public function getInputTypeOptions($type)
  27. {
  28. switch ($type) {
  29. case 'numeric':
  30. return $this->optionsForNumericType();
  31. case 'select':
  32. return $this->toOptionArray();
  33. case 'string':
  34. return $this->optionsForStringType();
  35. }
  36. return $this->optionsForStringType();
  37. }
  38. /**
  39. * Condition options for numeric type.
  40. *
  41. * @return array
  42. */
  43. private function optionsForNumericType()
  44. {
  45. $options = $this->toOptionArray();
  46. $options[] = [
  47. 'value' => 'gteq',
  48. 'label' => __('equals or greater than'),
  49. ];
  50. $options[] = [
  51. 'value' => 'lteq',
  52. 'label' => __('equals or less then'),
  53. ];
  54. $options[] = ['value' => 'gt', 'label' => __('greater than')];
  55. $options[] = ['value' => 'lt', 'label' => __('less than')];
  56. return $options;
  57. }
  58. /**
  59. * Condition options for string type.
  60. *
  61. * @return array
  62. */
  63. private function optionsForStringType()
  64. {
  65. $options = $this->toOptionArray();
  66. $options[] = ['value' => 'like', 'label' => __('contains')];
  67. $options[] = [
  68. 'value' => 'nlike',
  69. 'label' => __('does not contains'),
  70. ];
  71. return $options;
  72. }
  73. }