Merge pull request #4961 from pratikshad/core-bugs
[civicrm-core.git] / CRM / Contact / Form / Search / Advanced.php
index d3d298332fcdfea30f3b8e6a7bcb376e13b6ab2d..32cae3ba637e666010c12a962c9ca27d2e93d608 100644 (file)
@@ -154,7 +154,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
           $c->buildAdvancedSearchPaneForm($this);
           $this->_paneTemplatePath[$type] = $c->getAdvancedSearchPaneTemplatePath();
         }
-        else if (in_array($type, $hookPanes)) {
+        elseif (in_array($type, $hookPanes)) {
           CRM_Contact_BAO_Query_Hook::singleton()->buildAdvancedSearchPaneForm($this, $type);
           CRM_Contact_BAO_Query_Hook::singleton()->setAdvancedSearchPaneTemplatePath($this->_paneTemplatePath, $type);
         }
@@ -202,7 +202,8 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
    * Set the default form values
    *
    *
-   * @return array the default array reference
+   * @return array
+   *   the default array reference
    */
   public function setDefaultValues() {
     $defaults = $this->_formValues;
@@ -245,7 +246,9 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
       // FIXME: so leaving this as a dependency for now
       if (array_key_exists('contribution_amount_low', $this->_formValues)) {
         foreach (array(
-          'contribution_amount_low', 'contribution_amount_high') as $f) {
+                   'contribution_amount_low',
+                   'contribution_amount_high'
+                 ) as $f) {
           $this->_formValues[$f] = CRM_Utils_Rule::cleanMoney($this->_formValues[$f]);
         }
       }
@@ -277,7 +280,11 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
         !$this->_force
       ) {
         foreach (array(
-          'case_type_id', 'case_status_id', 'case_deleted', 'case_tags') as $caseCriteria) {
+                   'case_type_id',
+                   'case_status_id',
+                   'case_deleted',
+                   'case_tags'
+                 ) as $caseCriteria) {
           if (!empty($this->_formValues[$caseCriteria])) {
             $allCases = TRUE;
             $this->_formValues['case_owner'] = 1;
@@ -357,12 +364,31 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
       }
     }
 
-    // CRM-13848
-    $financialType = CRM_Utils_Array::value('financial_type_id', $this->_formValues);
-    if ($financialType && is_array($financialType)) {
-      unset($this->_formValues['financial_type_id']);
-      foreach($financialType as $notImportant => $typeID) {
-        $this->_formValues['financial_type_id'][$typeID] = 1;
+    $specialParams = array(
+      'financial_type_id',
+      'contribution_soft_credit_type_id',
+      'contribution_status',
+      'contribution_source',
+      'contribution_trxn_id',
+      'activity_type_id',
+      'status_id',
+      'activity_subject',
+      'participant_status_id',
+      'participant_role_id'
+    );
+    foreach ($specialParams as $element) {
+      $value = CRM_Utils_Array::value($element, $this->_formValues);
+      if ($value) {
+        if (is_array($value)) {
+          if ($element == 'status_id') {
+            unset($this->_formValues[$element]);
+            $element = 'activity_' . $element;
+          }
+          $this->_formValues[$element] = array('IN' => $value);
+        }
+        else {
+          $this->_formValues[$element] = array('LIKE' => "%$value%");
+        }
       }
     }
 
@@ -388,8 +414,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
   /**
    * Normalize default values for multiselect plugins
    *
-   * @param $defaults
-   *   Array.
+   * @param array $defaults
    * @return array
    */
   public function normalizeDefaultValues(&$defaults) {