Condition.php 1.88 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<?php

namespace Dotdigitalgroup\Email\Model\Adminhtml\Source\Rules;

class Condition
{
    /**
     * Options array.
     *
     * @return array
     */
    public function toOptionArray()
    {
        $options = [
            ['value' => 'eq', 'label' => __('is')],
            ['value' => 'neq', 'label' => __('is not')],
            ['value' => 'null', 'label' => __('is empty')],
        ];

        return $options;
    }

    /**
     * Get condition options according to type.
     *
     * @param string $type
     *
     * @return array
     */
    public function getInputTypeOptions($type)
    {
        switch ($type) {
            case 'numeric':
                return $this->optionsForNumericType();

            case 'select':
                return $this->toOptionArray();

            case 'string':
                return $this->optionsForStringType();
        }

        return $this->optionsForStringType();
    }

    /**
     * Condition options for numeric type.
     *
     * @return array
     */
    private function optionsForNumericType()
    {
        $options = $this->toOptionArray();
        $options[] = [
            'value' => 'gteq',
            'label' => __('equals or greater than'),
        ];
        $options[] = [
            'value' => 'lteq',
            'label' => __('equals or less then'),
        ];
        $options[] = ['value' => 'gt', 'label' => __('greater than')];
        $options[] = ['value' => 'lt', 'label' => __('less than')];

        return $options;
    }

    /**
     * Condition options for string type.
     *
     * @return array
     */
    private function optionsForStringType()
    {
        $options = $this->toOptionArray();
        $options[] = ['value' => 'like', 'label' => __('contains')];
        $options[] = [
            'value' => 'nlike',
            'label' => __('does not contains'),
        ];

        return $options;
    }
}