Merge pull request #2006 from civicrm/4.3
[civicrm-core.git] / CRM / Contact / Form / Search / Advanced.php
index e6fcc3f7754af0fd3ae93862f43c8544aac60396..0b6cc47d6147f7c7acec9560932c9e6a1d7fa8d7 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -126,10 +126,13 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
       $paneNames[$pane['title']] = $pane['name'];
     }
 
-    $this->_paneTemplatePath = array();
+    $hookPanes = array();
+    CRM_Contact_BAO_Query_Hook::singleton()->registerAdvancedSearchPane($hookPanes);
+    $paneNames = array_merge($paneNames, $hookPanes);
 
+    $this->_paneTemplatePath = array();
     foreach ($paneNames as $name => $type) {
-      if (!$this->_searchOptions[$type]) {
+      if (!array_key_exists($type, $this->_searchOptions) && !in_array($type, $hookPanes)) {
         continue;
       }
 
@@ -148,15 +151,18 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
       ) {
         $allPanes[$name]['open'] = 'true';
 
-
         if (CRM_Utils_Array::value($type, $components)) {
           $c = $components[$type];
           $this->add('hidden', "hidden_$type", 1);
           $c->buildAdvancedSearchPaneForm($this);
           $this->_paneTemplatePath[$type] = $c->getAdvancedSearchPaneTemplatePath();
         }
+        else if (in_array($type, $hookPanes)) {
+          CRM_Contact_BAO_Query_Hook::singleton()->buildAdvancedSearchPaneForm($this, $type);
+          CRM_Contact_BAO_Query_Hook::singleton()->setAdvancedSearchPaneTemplatePath($this->_paneTemplatePath, $type);
+        }
         else {
-          eval('CRM_Contact_Form_Search_Criteria::' . $type . '( $this );');
+          CRM_Contact_Form_Search_Criteria::$type($this);
           $template = ucfirst($type);
           $this->_paneTemplatePath[$type] = "CRM/Contact/Form/Search/Criteria/{$template}.tpl";
         }
@@ -295,9 +301,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
     // we dont want to store the sortByCharacter in the formValue, it is more like
     // a filter on the result set
     // this filter is reset if we click on the search button
-    if ($this->_sortByCharacter !== NULL
-      && empty($_POST)
-    ) {
+    if ($this->_sortByCharacter !== NULL && empty($_POST)) {
       if (strtolower($this->_sortByCharacter) == 'all') {
         $this->_formValues['sortByCharacter'] = NULL;
       }
@@ -305,6 +309,9 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
         $this->_formValues['sortByCharacter'] = $this->_sortByCharacter;
       }
     }
+    else {
+      $this->_sortByCharacter = NULL;
+    }
 
     CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
 
@@ -370,7 +377,8 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
   /**
    * normalize default values for multiselect plugins
    *
-   * @return void
+   * @param $defaults array
+   * @return array
    * @access private
    */
   function normalizeDefaultValues(&$defaults) {