Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH - Add 'Includes' condition option to EmailRecipientCondition #1275

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading