Unverified Commit b0231f5a authored by Seamus Lee's avatar Seamus Lee Committed by GitHub

Merge pull request #16578 from seamuslee001/dev_core_1602

#1602 Fix join date filtering in search builder by standardis…
parents 5c31ed8f c12606e5
......@@ -153,6 +153,32 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
list($name, $op, $value, $grouping) = $values;
$fields = self::getFields();
$quoteValue = NULL;
if (!empty($value) && !is_array($value)) {
$quoteValue = "\"$value\"";
}
$fieldAliases = self::getLegacySupportedFields();
$fieldName = $name = self::getFieldName($values);
$qillName = $name;
if (in_array($name, $fieldAliases)) {
$qillName = array_search($name, $fieldAliases);
}
$pseudoExtraParam = [];
$fieldSpec = CRM_Utils_Array::value($fieldName, $fields, []);
$tableName = CRM_Utils_Array::value('table_name', $fieldSpec, 'civicrm_membership');
$dataType = CRM_Utils_Type::typeToString(CRM_Utils_Array::value('type', $fieldSpec));
if ($dataType === 'Timestamp' || $dataType === 'Date') {
$title = empty($fieldSpec['unique_title']) ? $fieldSpec['title'] : $fieldSpec['unique_title'];
$query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
$query->dateQueryBuilder($values,
$tableName, $fieldName, $fieldSpec['name'], $title
);
return;
}
switch ($name) {
case 'member_join_date_low':
case 'member_join_date_high':
......@@ -167,7 +193,6 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
);
return;
case 'membership_start_date':
case 'member_start_date_low':
case 'member_start_date_high':
Civi::log()->warning(
......@@ -181,7 +206,6 @@ class CRM_Member_BAO_Query extends CRM_Core_BAO_Query {
);
return;
case 'membership_end_date':
case 'member_end_date_low':
case 'member_end_date_high':
Civi::log()->warning(
......
......@@ -80,4 +80,47 @@ class CRM_Member_BAO_QueryTest extends CiviUnitTestCase {
$this->assertEquals(['civicrm_membership.membership_type_id IN ("1", "2")'], $obj->_where[0]);
}
/**
* Membership Date fields
* @return array
*/
public function membershipDateFields() {
$fields = [];
$fields[] = ['membership_join_date'];
$fields[] = ['membership_start_date'];
$fields[] = ['membership_end_date'];
return $fields;
}
/**
* Test generating a correct where clause for date fields as generated by search builder
* @dataProvider membershipDateFields
*/
public function testMembershipDateWhereSearchBuilder($dateField) {
$dbDateField = str_replace('membership_', '', $dateField);
$formValues = [
'mapper' => [
1 => [['Membership', $dateField], [''], [''], [''], ['']],
2 => [[''], [''], [''], [''], ['']],
3 => [[''], [''], [''], [''], ['']],
],
'operator' => [
1 => ['<=', '', '', '', ''],
2 => ['', '', '', '', ''],
3 => ['', '', '', '', ''],
],
'value' => [
1 => ['20200201', '', '', '', ''],
2 => ['', '', '', '', '', ''],
3 => ['', '', '', '', '', ''],
],
'radio_ts' => '',
];
$searchBuilderForm = new CRM_Contact_Form_Search_Builder();
$params = [[$dateField, "<=", "20200201", 1, 0]];
$this->assertEquals($params, $searchBuilderForm->convertFormValues($formValues));
$obj = new CRM_Contact_BAO_Query($params);
$this->assertEquals(['civicrm_membership.' . $dbDateField . ' <= \'20200201000000\''], $obj->_where[1]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment