From 7c1d587ae03e0e2301b51b8a5c607a3232c8a997 Mon Sep 17 00:00:00 2001 From: yuri Date: Thu, 30 Aug 2018 11:30:33 +0300 Subject: [PATCH] search by opted out and bool where redefinition in ORM --- .../Core/Utils/Database/Orm/Fields/Email.php | 11 +++++++- application/Espo/ORM/DB/Query/Base.php | 28 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/Utils/Database/Orm/Fields/Email.php b/application/Espo/Core/Utils/Database/Orm/Fields/Email.php index a307598440..e60f1e9097 100644 --- a/application/Espo/Core/Utils/Database/Orm/Fields/Email.php +++ b/application/Espo/Core/Utils/Database/Orm/Fields/Email.php @@ -88,7 +88,16 @@ class Email extends Base $fieldName .'IsOptedOut' => array( 'type' => 'bool', 'notStorable' => true, - 'select' => 'emailAddresses.opt_out' + 'select' => 'emailAddresses.opt_out', + 'where' => [ + '= TRUE' => [ + 'sql' => 'emailAddresses.opt_out = true AND emailAddresses.opt_out IS NOT NULL' + ], + '= FALSE' => [ + 'sql' => 'emailAddresses.opt_out = false OR emailAddresses.opt_out IS NULL' + ] + ], + 'orderBy' => 'emailAddresses.opt_out {direction}' ) ), 'relations' => array( diff --git a/application/Espo/ORM/DB/Query/Base.php b/application/Espo/ORM/DB/Query/Base.php index b331958957..515a7094e4 100644 --- a/application/Espo/ORM/DB/Query/Base.php +++ b/application/Espo/ORM/DB/Query/Base.php @@ -856,7 +856,33 @@ abstract class Base $fieldDefs = $entity->fields[$field]; $operatorModified = $operator; - if (is_array($value)) { + + $attributeType = null; + if (!empty($fieldDefs['type'])) { + $attributeType = $fieldDefs['type']; + } + + if ( + is_bool($value) + && + in_array($operator, ['=', '<>']) + && + $attributeType == IEntity::BOOL + ) { + if ($value) { + if ($operator === '=') { + $operatorModified = '= TRUE'; + } else { + $operatorModified = '= FALSE'; + } + } else { + if ($operator === '=') { + $operatorModified = '= FALSE'; + } else { + $operatorModified = '= TRUE'; + } + } + } else if (is_array($value)) { if ($operator == '=') { $operatorModified = 'IN'; } else if ($operator == '<>') {