From 359fdb6f3817d43e4eef1c6fae7f769870aabc4a Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 2 Jul 2019 19:24:12 +1200 Subject: [PATCH] dev/core#538 fix advanced search on activity subject, detail to use wildcards like activity search does --- CRM/Activity/BAO/Query.php | 8 +++++++- CRM/Activity/Form/Search.php | 4 +--- CRM/Contact/BAO/Query.php | 2 +- CRM/Contact/Form/Search/Advanced.php | 4 +--- CRM/Contribute/Form/Search.php | 5 +---- CRM/Core/Form/Search.php | 24 +++++++++++++++++++----- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index 11c86f0d79..6cea3e0f90 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -465,7 +465,13 @@ class CRM_Activity_BAO_Query { public static function getSearchFieldMetadata() { $fields = ['activity_type_id', 'activity_date_time', 'priority_id', 'activity_location']; $metadata = civicrm_api3('Activity', 'getfields', [])['values']; - return array_intersect_key($metadata, array_flip($fields)); + $metadata = array_intersect_key($metadata, array_flip($fields)); + $metadata['activity_text'] = [ + 'title' => ts('Activity Text'), + 'type' => CRM_Utils_Type::T_STRING, + 'is_pseudofield' => TRUE, + ]; + return $metadata; } /** diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index 1c82959f28..4ede56c436 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -196,14 +196,12 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search { } $this->_done = TRUE; - + $this->setFormValues(); if (!empty($_POST)) { - $this->_formValues = $this->controller->exportValues($this->_name); $specialParams = [ 'activity_type_id', 'status_id', 'priority_id', - 'activity_text', ]; $changeNames = [ 'status_id' => 'activity_status_id', diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index ab5e7f69d0..970922ec82 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -3452,7 +3452,7 @@ WHERE $smartGroupClause return; } - $input = $value = trim($value); + $input = $value = is_array($value) ? trim($value['LIKE']) : trim($value); if (!strlen($value)) { return; diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index b0743b2203..572e447e65 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -228,10 +228,10 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { public function postProcess() { $this->set('isAdvanced', '1'); + $this->setFormValues(); // get user submitted values // get it from controller only if form has been submitted, else preProcess has set this if (!empty($_POST)) { - $this->_formValues = $this->controller->exportValues($this->_name); $this->normalizeFormValues(); // FIXME: couldn't figure out a good place to do this, // FIXME: so leaving this as a dependency for now @@ -349,8 +349,6 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { 'activity_type_id', 'status_id', 'priority_id', - 'activity_subject', - 'activity_details', 'contribution_page_id', 'contribution_product_id', 'payment_instrument_id', diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 8b5e310445..f3aa40248b 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -288,10 +288,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { $this->_done = TRUE; - if (!empty($_POST) && !$this->_force) { - $this->_formValues = $this->controller->exportValues($this->_name); - } - $this->convertTextStringsToUseLikeOperator(); + $this->setFormValues(); $this->fixFormValues(); // We don't show test records in summaries or dashboards diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 5a4c0db927..26f7de8e4a 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -139,6 +139,16 @@ class CRM_Core_Form_Search extends CRM_Core_Form { return $defaults; } + /** + * Set the form values based on input and preliminary processing. + */ + protected function setFormValues() { + if (!empty($_POST) && !$this->_force) { + $this->_formValues = $this->controller->exportValues($this->_name); + } + $this->convertTextStringsToUseLikeOperator(); + } + /** * Common buildForm tasks required by all searches. */ @@ -184,7 +194,9 @@ class CRM_Core_Form_Search extends CRM_Core_Form { elseif (isset($fields[$fieldName]['title'])) { $props['label'] = $fields[$fieldName]['title']; } - $this->addField($fieldName, $props); + if (empty($fieldSpec['is_pseudofield'])) { + $this->addField($fieldName, $props); + } } } } @@ -287,10 +299,12 @@ class CRM_Core_Form_Search extends CRM_Core_Form { * Note this will only pick up fields declared via metadata. */ protected function convertTextStringsToUseLikeOperator() { - foreach (CRM_Utils_Array::value($this->getDefaultEntity(), $this->getSearchFieldMetadata(), []) as $fieldName => $field) { - if (!empty($this->_formValues[$fieldName]) && empty($field['options']) && empty($field['pseudoconstant'])) { - if (in_array($field['type'], [CRM_Utils_Type::T_STRING, CRM_Utils_Type::T_TEXT])) { - $this->_formValues[$fieldName] = ['LIKE' => CRM_Contact_BAO_Query::getWildCardedValue(TRUE, 'LIKE', $this->_formValues[$fieldName])]; + foreach ($this->getSearchFieldMetadata() as $entity => $fields) { + foreach ($fields as $fieldName => $field) { + if (!empty($this->_formValues[$fieldName]) && empty($field['options']) && empty($field['pseudoconstant'])) { + if (in_array($field['type'], [CRM_Utils_Type::T_STRING, CRM_Utils_Type::T_TEXT])) { + $this->_formValues[$fieldName] = ['LIKE' => CRM_Contact_BAO_Query::getWildCardedValue(TRUE, 'LIKE', $this->_formValues[$fieldName])]; + } } } } -- 2.25.1