3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_BAO_SearchCustom
{
29 public static function details($csID, $ssID = NULL, $gID = NULL) {
30 $error = [NULL, NULL, NULL];
39 $customSearchID = $csID;
43 $ssID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id');
46 $formValues = CRM_Contact_BAO_SavedSearch
::getFormValues($ssID);
47 $customSearchID = CRM_Utils_Array
::value('customSearchID',
52 if (!$customSearchID) {
56 // check that the csid exists in the db along with the right file
57 // and implements the right interface
58 $customSearchClass = civicrm_api3('OptionValue', 'getvalue', [
59 'option_group_id' => 'custom_search',
61 'value' => $customSearchID,
64 $ext = CRM_Extension_System
::singleton()->getMapper();
66 if (!$ext->isExtensionKey($customSearchClass)) {
67 $customSearchFile = str_replace('_',
73 $customSearchFile = $ext->keyToPath($customSearchClass);
74 $customSearchClass = $ext->keyToClass($customSearchClass);
77 $error = include_once $customSearchFile;
78 if ($error == FALSE) {
79 throw new CRM_Core_Exception('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.');
82 return [$customSearchID, $customSearchClass, $formValues];
89 * @return CRM_Contact_Form_Search_Custom_Base
92 public static function customClass($csID, $ssID) {
93 list($customSearchID, $customSearchClass, $formValues) = self
::details($csID, $ssID);
95 if (!$customSearchID) {
96 throw new CRM_Core_Exception('Could not resolve custom search ID');
99 // instantiate the new class
100 $customClass = new $customSearchClass($formValues);
111 public static function contactIDSQL($csID, $ssID) {
112 $customClass = self
::customClass($csID, $ssID);
113 return $customClass->contactIDs();
121 public static function &buildFormValues($args) {
124 $values = explode("\n", $args);
126 foreach ($values as $value) {
127 list($n, $v) = CRM_Utils_System
::explode('=', $value, 2);
129 $formValues[$n] = $v;
141 public static function fromWhereEmail($csID, $ssID) {
142 $customClass = self
::customClass($csID, $ssID);
144 $from = $customClass->from();
145 $where = $customClass->where();
147 return [$from, $where];