diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 6b981e6f419b787e6ce59cc58c3d9c8a46af49fe..22297656bc0f85b84a89d7786a22ccc9efa2122f 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -3744,7 +3744,10 @@ WHERE id IN ( $groupIDs ) list($name, $op, $value, $grouping, $wildcard) = $values; $pref = array(); - if (!is_array($value)) { + if (in_array($op, array( 'IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'))) { + $value = NULL; + } + elseif (!is_array($value)) { $v = array(); $value = trim($value, ' ()'); if (strpos($value, CRM_Core_DAO::VALUE_SEPARATOR) !== FALSE) { @@ -3771,10 +3774,16 @@ WHERE id IN ( $groupIDs ) $commPref = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); $sqlValue = array(); + $showValue = array(); $sql = "contact_a.preferred_communication_method"; - foreach ($pref as $val) { - $sqlValue[] = "( $sql like '%" . CRM_Core_DAO::VALUE_SEPARATOR . $val . CRM_Core_DAO::VALUE_SEPARATOR . "%' ) "; - $showValue[] = $commPref[$val]; + if (in_array($op, array('IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY'))) { + $sqlValue[] = "{$sql} {$op}"; + } + else { + foreach ($pref as $val) { + $sqlValue[] = "( $sql like '%" . CRM_Core_DAO::VALUE_SEPARATOR . $val . CRM_Core_DAO::VALUE_SEPARATOR . "%' ) "; + $showValue[] = $commPref[$val]; + } } $this->_where[$grouping][] = "( " . implode(' OR ', $sqlValue) . " )"; $this->_qill[$grouping][] = ts('Preferred Communication Method') . " $op " . implode(' ' . ts('or') . ' ', $showValue);