Skip to content

Commit

Permalink
ENH Add 'Includes' condition option to EmailRecipientCondition (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder-somar authored Mar 17, 2024
1 parent 6191b49 commit 32d0158
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions code/Model/Recipient/EmailRecipientCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ class EmailRecipientCondition extends DataObject
'ValueLessThan' => 'Less than',
'ValueLessThanEqual' => 'Less than or equal',
'ValueGreaterThan' => 'Greater than',
'ValueGreaterThanEqual' => 'Greater than or equal'
'ValueGreaterThanEqual' => 'Greater than or equal',
'Includes' => 'Includes'
];

private static $db = [
'ConditionOption' => 'Enum("IsBlank,IsNotBlank,Equals,NotEquals,ValueLessThan,ValueLessThanEqual,ValueGreaterThan,ValueGreaterThanEqual")',
'ConditionOption' => 'Enum("IsBlank,IsNotBlank,Equals,NotEquals,ValueLessThan,ValueLessThanEqual,ValueGreaterThan,ValueGreaterThanEqual,Includes")',
'ConditionValue' => 'Varchar'
];

Expand Down Expand Up @@ -96,6 +97,11 @@ public function matches($data)
$result = !($result);
}
break;
case 'Includes':
$result = is_array($fieldValue)
? in_array($conditionValue, $fieldValue)
: stripos($fieldValue ?? '', $conditionValue) !== false;
break;
default:
throw new LogicException("Unhandled rule {$this->ConditionOption}");
break;
Expand Down

0 comments on commit 32d0158

Please sign in to comment.