From 6a5f199ec635d154fe8d0b63d5cec6decaff4405 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 22 Aug 2013 18:17:05 -0700 Subject: [PATCH] CRM-12925 - Search Builder - Allow query-classes to influence the options displayed for each field ---------------------------------------- * CRM-12925: Implement "Job" search (for "Search Builder") http://issues.civicrm.org/jira/browse/CRM-12925 --- CRM/Contact/BAO/Query/Hook.php | 6 ++++++ CRM/Contact/BAO/Query/Interface.php | 12 +++++++++++- CRM/Contact/Form/Search/Builder.php | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/Query/Hook.php b/CRM/Contact/BAO/Query/Hook.php index f66b4c101f..fa3e47372a 100644 --- a/CRM/Contact/BAO/Query/Hook.php +++ b/CRM/Contact/BAO/Query/Hook.php @@ -80,6 +80,12 @@ class CRM_Contact_BAO_Query_Hook { return $extFields; } + public function alterSearchBuilderOptions(&$apiEntities, &$fieldOptions) { + foreach (self::getSearchQueryObjects() as $obj) { + $obj->alterSearchBuilderOptions($apiEntities, $fieldOptions); + } + } + public function alterSearchQuery(&$query, $fnName) { foreach (self::getSearchQueryObjects() as $obj) { $obj->$fnName($query); diff --git a/CRM/Contact/BAO/Query/Interface.php b/CRM/Contact/BAO/Query/Interface.php index c713317ded..ea6f6c3a36 100644 --- a/CRM/Contact/BAO/Query/Interface.php +++ b/CRM/Contact/BAO/Query/Interface.php @@ -64,4 +64,14 @@ abstract class CRM_Contact_BAO_Query_Interface { public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) { return NULL; } -} + + /** + * Describe options for available for use in the search-builder. + * + * @param array $apiEntities list of entities whose options should be automatically scanned using API metadata + * @param array $fieldOptions keys are field unique-names; values describe how to lookup the options + * @void + */ + public function alterSearchBuilderOptions(&$apiEntities, &$fieldOptions) { + } +} \ No newline at end of file diff --git a/CRM/Contact/Form/Search/Builder.php b/CRM/Contact/Form/Search/Builder.php index 1967c357b9..0699dfb1d8 100644 --- a/CRM/Contact/Form/Search/Builder.php +++ b/CRM/Contact/Form/Search/Builder.php @@ -433,10 +433,11 @@ class CRM_Contact_Form_Search_Builder extends CRM_Contact_Form_Search { 'membership_type' => 'membership', ); $entities = array('contact', 'activity', 'participant', 'pledge', 'member', 'contribution'); + CRM_Contact_BAO_Query_Hook::singleton()->alterSearchBuilderOptions($entities, $options); foreach ($entities as $entity) { $fields = civicrm_api($entity, 'getfields', array('version' => 3)); foreach ($fields['values'] as $field => $info) { - if (!empty($info['options']) || !empty($info['pseudoconstant']) || !empty($info['option_group_id'])) { + if (!empty($info['options']) || !empty($info['pseudoconstant']) || !empty($info['option_group_id']) || !empty($info['enumValues'])) { $options[$field] = $entity; if (substr($field, -3) == '_id') { $options[substr($field, 0, -3)] = $entity; -- 2.25.1