CRM-12924, CRM-12940 pluging advanced search panes via queryObjects hook
authorDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Mon, 15 Jul 2013 13:48:29 +0000 (19:18 +0530)
committerDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Mon, 15 Jul 2013 13:48:29 +0000 (19:18 +0530)
----------------------------------------
* CRM-12924: Implement "Job" search (for "Advanced Search")
  http://issues.civicrm.org/jira/browse/CRM-12924
* CRM-12940: Allow extensions to participate in CRM_*_BAO_Query
  http://issues.civicrm.org/jira/browse/CRM-12940

CRM/Contact/BAO/Query.php
CRM/Contact/BAO/Query/Hook.php
CRM/Contact/BAO/Query/Interface.php
CRM/Contact/Form/Search/Advanced.php

index 573c6b8c67b11626c3f3f208464c51a74f11c122..c155fd3dcc6514712192d11d3c10c229a07f25c6 100644 (file)
@@ -1389,6 +1389,12 @@ class CRM_Contact_BAO_Query {
       return;
     }
 
+    // skip for hook injected fields / params
+    $extFields = CRM_Contact_BAO_Query_Hook::singleton()->getFields();
+    if (array_key_exists($values[0], $extFields)) {
+      return;
+    }
+
     switch ($values[0]) {
       case 'deleted_contacts':
         $this->deletedContacts($values);
@@ -2165,6 +2171,8 @@ class CRM_Contact_BAO_Query {
 
     // to handle table dependencies of components
     CRM_Core_Component::tableNames($tables);
+    // to handle table dependencies of hook injected tables
+    CRM_Contact_BAO_Query_Hook::singleton()->setTableDependency($tables);
 
     //format the table list according to the weight
     $info = CRM_Core_TableHierarchy::info();
index 6f3ecefc754ba7ab4dd49d98336409cdeac06fed..0776de2f8baf31bb89bae54714292016b64952f8 100644 (file)
@@ -93,4 +93,28 @@ class CRM_Contact_BAO_Query_Hook {
     }
     return $from;
   }
+
+  public function setTableDependency(&$tables) {
+    foreach (self::getSearchQueryObjects() as $obj) {
+      $obj->setTableDependency($tables);
+    }
+  }
+
+  public function registerAdvancedSearchPane(&$panes) {
+    foreach (self::getSearchQueryObjects() as $obj) {
+      $obj->registerAdvancedSearchPane($panes);
+    }
+  }
+
+  public function buildAdvancedSearchPaneForm(&$form, $type) {
+    foreach (self::getSearchQueryObjects() as $obj) {
+      $obj->buildAdvancedSearchPaneForm($form, $type);
+    }
+  }
+
+  public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) {
+    foreach (self::getSearchQueryObjects() as $obj) {
+      $obj->setAdvancedSearchPaneTemplatePath($paneTemplatePathArray, $type);
+    }
+  }
 }
\ No newline at end of file
index 18f0077c04b5244379d02b7fe98f168db855cb81..38bc944de8d3dc1c764765d68ddec7b1c800a36e 100644 (file)
  */
 
 /**
- * Interface for search BAO query objects
+ * Abstract class for search BAO query objects
  */
-interface CRM_Contact_BAO_Query_Interface {
+abstract class CRM_Contact_BAO_Query_Interface {
 
-  public function &getFields();
+  abstract public function &getFields();
+  abstract public function from($fieldName, $mode, $side);
 
-  public function select(&$query);
+  public function select(&$query) {
+    return NULL;
+  }
 
-  public function where(&$query);
+  public function where(&$query) {
+    return NULL;
+  }
 
-  public function from($fieldName, $mode, $side);
+  public function setTableDependency(&$tables) {
+    return NULL;
+  }
+
+  public function registerAdvancedSearchPane(&$panes) {
+    return NULL;
+  }
+
+  public function buildAdvancedSearchPaneForm(&$form, $type) {
+    return NULL;
+  }
+
+  public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) {
+    return NULL;
+  }
 }
\ No newline at end of file
index ed1193f1433f5276049eda05232f3ee4a5686423..6ad1e97d0cb236950a912ffbca1db1a31d5023e7 100644 (file)
@@ -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,13 +151,16 @@ 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 {
           CRM_Contact_Form_Search_Criteria::$type($this);
           $template = ucfirst($type);