From efa3a56617ddfc11709c90bfa763a557314a4773 Mon Sep 17 00:00:00 2001 From: Deepak Srivastava Date: Mon, 15 Jul 2013 19:18:29 +0530 Subject: [PATCH] CRM-12924, CRM-12940 pluging advanced search panes via queryObjects hook ---------------------------------------- * 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 | 8 +++++++ CRM/Contact/BAO/Query/Hook.php | 24 +++++++++++++++++++++ CRM/Contact/BAO/Query/Interface.php | 31 ++++++++++++++++++++++------ CRM/Contact/Form/Search/Advanced.php | 12 ++++++++--- 4 files changed, 66 insertions(+), 9 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 573c6b8c67..c155fd3dcc 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -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(); diff --git a/CRM/Contact/BAO/Query/Hook.php b/CRM/Contact/BAO/Query/Hook.php index 6f3ecefc75..0776de2f8b 100644 --- a/CRM/Contact/BAO/Query/Hook.php +++ b/CRM/Contact/BAO/Query/Hook.php @@ -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 diff --git a/CRM/Contact/BAO/Query/Interface.php b/CRM/Contact/BAO/Query/Interface.php index 18f0077c04..38bc944de8 100644 --- a/CRM/Contact/BAO/Query/Interface.php +++ b/CRM/Contact/BAO/Query/Interface.php @@ -34,15 +34,34 @@ */ /** - * 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 diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index ed1193f143..6ad1e97d0c 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -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); -- 2.25.1