From 32d0158954b048b963405475140c40aa5c035d95 Mon Sep 17 00:00:00 2001 From: Sukhwinder Singh <107516681+sukhwinder-somar@users.noreply.github.com> Date: Mon, 18 Mar 2024 04:04:26 +0530 Subject: [PATCH] ENH Add 'Includes' condition option to EmailRecipientCondition (#1275) --- code/Model/Recipient/EmailRecipientCondition.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code/Model/Recipient/EmailRecipientCondition.php b/code/Model/Recipient/EmailRecipientCondition.php index 8a67247..760baf4 100644 --- a/code/Model/Recipient/EmailRecipientCondition.php +++ b/code/Model/Recipient/EmailRecipientCondition.php @@ -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' ]; @@ -96,6 +97,11 @@ class EmailRecipientCondition extends DataObject $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;