X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FQuery.php;h=0c7df5514f0a27a21a0cdf7e8595a49f052c1488;hb=27ccf2971fbceea387c5ad9e120636cef2e87696;hp=9dc6990f5e167e928ba935a91cb3fcc534bd2829;hpb=1789c269b1c68178c1f3de38d751a4e37f94db4c;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 9dc6990f5e..0c7df5514f 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -563,6 +563,13 @@ class CRM_Contact_BAO_Query { if (!array_key_exists($cfID, $this->_cfIDs)) { $this->_cfIDs[$cfID] = array(); } + // Set wildcard value based on "and/or" selection + foreach ($this->_params as $key => $param) { + if ($param[0] == $value[0] . '_operator') { + $value[4] = $param[2] == 'or'; + break; + } + } $this->_cfIDs[$cfID][] = $value; } @@ -1819,7 +1826,7 @@ class CRM_Contact_BAO_Query { $this->_where[0][] = "contact_a.id IN ({$idList})"; } else { - $this->_where[0][] = "contact_a.id {$this->_params[$id][1]} {$this->_params[$id][2]}"; + $this->_where[0][] = self::buildClause("contact_a.id", "{$this->_params[$id][1]}", "{$this->_params[$id][2]}"); } } else { @@ -2012,7 +2019,9 @@ class CRM_Contact_BAO_Query { $name, $op, $value, $grouping, CRM_Core_PseudoConstant::worldRegion(), $field, - ts('World Region') + ts('World Region'), + 'Positive', + TRUE ); } elseif ($name === 'birth_date') { @@ -2659,7 +2668,7 @@ class CRM_Contact_BAO_Query { } else { $type = array_pop($clause); - $this->_where[$grouping][] = "contact_a.contact_type $op $type"; + $this->_where[$grouping][] = self::buildClause("contact_a.contact_type", $op, $contactType); } $this->_qill[$grouping][] = ts('Contact Type') . ' - ' . implode(' ' . ts('or') . ' ', $quill); @@ -5151,11 +5160,11 @@ SELECT COUNT( conts.total_amount ) as cancel_count, return $clause; case 'IS EMPTY': - $clause = " ( $field IS NULL OR $field = '' ) "; + $clause = " (NULLIF($field, '') IS NULL) "; return $clause; case 'IS NOT EMPTY': - $clause = " ( $field IS NOT NULL AND $field <> '' ) "; + $clause = " (NULLIF($field, '') IS NOT NULL) "; return $clause; case 'IN': @@ -5376,7 +5385,7 @@ AND displayRelType.is_active = 1 $useIDsOnly = FALSE ) { - if (!empty($selectValues) && !empty($selectValues[$value])) { + if (!empty($selectValues) && !is_array($value) && !empty($selectValues[$value])) { $qill = $selectValues[$value]; } else { @@ -5389,13 +5398,12 @@ AND displayRelType.is_active = 1 $qill = $selectValues[(int ) $value]; } elseif ($op == 'IN' || $op == 'NOT IN') { - $values = self::parseSearchBuilderString($value); - if (is_array($values)) { + if (is_array($value)) { $intVals = array(); $newValues = array(); - foreach ($values as $v) { - $intVals[] = (int) $v; - $newValues[] = $selectValues[(int ) $v]; + foreach ($value as $k => $v) { + $intVals[$k] = (int) $k; + $newValues[] = $selectValues[(int) $k]; } $value = (in_array($name, $pseudoFields)) ? $intVals : $newValues; @@ -5411,6 +5419,9 @@ AND displayRelType.is_active = 1 if ($tableName == 'civicrm_contact') { $wc = "contact_a.$fieldName"; } + else { + $wc = "$tableName.id"; + } } else { $wc = self::caseImportant($op) ? "LOWER({$field['where']})" : "{$field['where']}";