}
$qillValue = CRM_Core_BAO_CustomField::getDisplayValue($value, $id, $this->_options);
+ $qillOp = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op);
switch ($field['data_type']) {
case 'String':
else {
$val = CRM_Utils_Type::escape($strtolower(trim($value)), 'String');
+ // CRM-14563,CRM-16575 : Special handling of multi-select custom fields
$specialHTMLType = array(
'CheckBox',
'Multi-Select',
'Multi-Select State/Province',
'Multi-Select Country',
);
-
- if (in_array($field['html_type'], $specialHTMLType)) {
- $val = "[[:cntrl:]]" . $val . "[[:cntrl:]]";
- $op = 'RLIKE';
-
- }
- elseif ($wildcard) {
- $val = "[[:cntrl:]]%$val%[[:cntrl:]]";
- $op = 'LIKE';
+ if (!empty($val)) {
+ if (in_array($field['html_type'], $specialHTMLType)) {
+ if (strstr($op, 'IN')) {
+ $val = str_replace(array('(', ')'), '', str_replace(",", "[[:cntrl:]]|[[:cntrl:]]", $val));
+ }
+ $op = (strstr($op, '!') || strstr($op, 'NOT')) ? 'NOT RLIKE' : 'RLIKE';
+ $val = "[[:cntrl:]]" . $val . "[[:cntrl:]]";
+ }
+ elseif ($wildcard) {
+ $val = "[[:cntrl:]]%$val%[[:cntrl:]]";
+ $op = 'LIKE';
+ }
}
//FIX for custom data query fired against no value(NULL/NOT NULL)
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($sql, $op, $val, $field['data_type']);
- $this->_qill[$grouping][] = "$field[label] $op $qillValue";
+ $this->_qill[$grouping][] = "$field[label] $qillOp $qillValue";
}
break;
case 'ContactReference':
$label = $value ? CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'sort_name') : '';
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'String');
- $this->_qill[$grouping][] = $field['label'] . " $op $label";
+ $this->_qill[$grouping][] = $field['label'] . " $qillOp $label";
break;
case 'Int':
}
else {
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'Integer');
- $this->_qill[$grouping][] = $field['label'] . " $op $value";
+ $this->_qill[$grouping][] = $field['label'] . " $qillOp $value";
}
break;
$value = ($value == 1) ? 1 : 0;
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'Integer');
$value = $value ? ts('Yes') : ts('No');
- $this->_qill[$grouping][] = $field['label'] . " {$op} {$value}";
+ $this->_qill[$grouping][] = $field['label'] . " $qillOp {$value}";
break;
case 'Link':
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'String');
- $this->_qill[$grouping][] = $field['label'] . " $op $value";
+ $this->_qill[$grouping][] = $field['label'] . " $qillOp $value";
break;
case 'Float':
}
else {
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'Float');
- $this->_qill[$grouping][] = $field['label'] . " {$op} {$value}";
+ $this->_qill[$grouping][] = $field['label'] . " $qillOp {$value}";
}
break;
$moneyFormat = CRM_Utils_Rule::cleanMoney($value);
$value = $moneyFormat;
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'Float');
- $this->_qill[$grouping][] = $field['label'] . " {$op} {$value}";
+ $this->_qill[$grouping][] = $field['label'] . " {$qillOp} {$value}";
}
break;
case 'Memo':
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $value, 'String');
- $this->_qill[$grouping][] = "$field[label] $op $value";
+ $this->_qill[$grouping][] = "$field[label] $qillOp $value";
break;
case 'Date':
$date = CRM_Utils_Date::processDate($value);
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op, $date, 'String');
- $this->_qill[$grouping][] = $field['label'] . " {$op} " . CRM_Utils_Date::customFormat($date);
+ $this->_qill[$grouping][] = $field['label'] . " {$qillOp} " . CRM_Utils_Date::customFormat($date);
}
else {
if (is_numeric($fromValue) && strlen($fromValue) == 4) {
case 'StateProvince':
case 'Country':
$this->_where[$grouping][] = "$fieldName {$op} " . CRM_Utils_Type::escape($value, 'Int');
- $this->_qill[$grouping][] = $field['label'] . " {$op} {$qillValue}";
+ $this->_qill[$grouping][] = $field['label'] . " {$qillOp} {$qillValue}";
break;
case 'File':
break;
}
$this->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($fieldName, $op);
- $this->_qill[$grouping][] = $field['label'] . " {$op} ";
+ $this->_qill[$grouping][] = $field['label'] . " {$qillOp} ";
}
break;
}
}
}
- // CRM-14563: we store checkbox, multi-select and adv-multi select custom field using separator, hence it
- // needs special handling.
- if ($cfID = CRM_Core_BAO_CustomField::getKeyID(CRM_Utils_Array::value(1, $v))) {
- $isCustomField = TRUE;
- $customFieldType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $cfID, 'html_type');
- $specialHTMLType = array(
- 'CheckBox',
- 'Multi-Select',
- 'AdvMulti-Select',
- 'Multi-Select State/Province',
- 'Multi-Select Country',
- );
-
- // override the operator to handle separator ( note: this might have some performance issues )
- if (in_array($customFieldType, $specialHTMLType)) {
- // FIX ME: != and few other operators are not handled
- $specialOperators = array('=', 'IN', 'LIKE');
-
- if (in_array($params['operator'][$key][$k], $specialOperators)) {
- $params['operator'][$key][$k] = 'RLIKE';
- }
- }
- }
-
// CRM-14983: verify if values are comma separated convert to array
- if (!is_array($value) && (strpos($value, ',') !== FALSE || strstr($value, '(')) && empty($isCustomField) && $params['operator'][$key][$k] == 'IN') {
+ if (!is_array($value) && (strpos($value, ',') !== FALSE || strstr($value, '(')) && substr($fldName, 0, 7) != 'custom_' && $params['operator'][$key][$k] == 'IN') {
preg_match('#\((.*?)\)#', $value, $match);
$tmpArray = explode(',', $match[1]);
$value = array_combine(array_values($tmpArray), array_values($tmpArray));