dev/core#538 fix advanced search on activity subject, detail to use wildcards like...
authoreileen <emcnaughton@wikimedia.org>
Tue, 2 Jul 2019 07:24:12 +0000 (19:24 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 22 Jul 2019 00:22:53 +0000 (12:22 +1200)
CRM/Activity/BAO/Query.php
CRM/Activity/Form/Search.php
CRM/Contact/BAO/Query.php
CRM/Contact/Form/Search/Advanced.php
CRM/Contribute/Form/Search.php
CRM/Core/Form/Search.php

index 11c86f0d796864553c1d0de4963ace1064efbfdd..6cea3e0f908c3bb0eab14ba899e00c653345f135 100644 (file)
@@ -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;
   }
 
   /**
index 1c82959f2828326f167828c4bde58e402f6ec487..4ede56c436318739c2f5f3815e8ba32e937e8d97 100644 (file)
@@ -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',
index ab5e7f69d06f46bc270cd6638e7be3033216fabf..970922ec82d49ae4c2134dba34e79fb95b1f1447 100644 (file)
@@ -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;
index b0743b220311ace8ab34ff98ac80d8073ee0b794..572e447e65ced6d26c57692550dd3a52f851c65f 100644 (file)
@@ -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',
index 8b5e31044571519abcab2e9f10eaf708d06fa205..f3aa40248b8aa5e7f57ffef5e34c4153225b0154 100644 (file)
@@ -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
index 5a4c0db92746073e331ac703422ad11a2996edb5..26f7de8e4af93a5b30fdde9ca0bb55b452426741 100644 (file)
@@ -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])];
+          }
         }
       }
     }