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

CRM-19513: Saved search is incorrectly using IN rather than BETWEEN f… #9284

Merged
merged 1 commit into from
Oct 19, 2016
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
33 changes: 32 additions & 1 deletion CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ public static function getFormValues($id) {
$id = CRM_Utils_Array::value(0, $value);
$value = CRM_Utils_Array::value(2, $value);
if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
$value = CRM_Utils_Array::value(key($value), $value);
$op = key($value);
$value = CRM_Utils_Array::value($op, $value);
if (in_array($op, array('BETWEEN', '>=', '<='))) {
self::decodeRelativeFields($result, $id, $op, $value);
unset($result[$element]);
continue;
}
}
if (strpos($id, '_date_low') !== FALSE || strpos($id, '_date_high') !== FALSE) {
$entityName = strstr($id, '_date', TRUE);
Expand Down Expand Up @@ -409,4 +415,29 @@ public static function saveRelativeDates(&$queryParams, $formValues) {
}
}

/**
* Decode relative custom fields (converted by CRM_Contact_BAO_Query->convertCustomRelativeFields(...))
* into desired formValues
*
* @param array $formValues
* @param string $fieldName
* @param string $op
* @param array|string|int $value
*/
public static function decodeRelativeFields(&$formValues, $fieldName, $op, $value) {
switch ($op) {
case 'BETWEEN':
list($formValues[$fieldName . '_from'], $formValues[$fieldName . '_to']) = $value;
break;

case '>=':
$formValues[$fieldName . '_from'] = $value;
break;

case '<=':
$formValues[$fieldName . '_to'] = $value;
break;
}
}

}