3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
33 class CRM_Contact_BAO_SearchCustom
{
45 public static function details($csID, $ssID = NULL, $gID = NULL) {
46 $error = array(NULL, NULL, NULL);
55 $customSearchID = $csID;
56 $formValues = array();
59 $ssID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id');
62 $formValues = CRM_Contact_BAO_SavedSearch
::getFormValues($ssID);
63 $customSearchID = CRM_Utils_Array
::value('customSearchID',
68 if (!$customSearchID) {
72 // check that the csid exists in the db along with the right file
73 // and implements the right interface
74 $customSearchClass = civicrm_api3('OptionValue', 'getvalue', array(
75 'option_group_id' => 'custom_search',
77 'value' => $customSearchID,
80 $ext = CRM_Extension_System
::singleton()->getMapper();
82 if (!$ext->isExtensionKey($customSearchClass)) {
83 $customSearchFile = str_replace('_',
89 $customSearchFile = $ext->keyToPath($customSearchClass);
90 $customSearchClass = $ext->keyToClass($customSearchClass);
93 $error = include_once $customSearchFile;
94 if ($error == FALSE) {
95 CRM_Core_Error
::fatal('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.');
98 return array($customSearchID, $customSearchClass, $formValues);
108 public static function customClass($csID, $ssID) {
109 list($customSearchID, $customSearchClass, $formValues) = self
::details($csID, $ssID);
111 if (!$customSearchID) {
112 CRM_Core_Error
::fatal('Could not resolve custom search ID');
115 // instantiate the new class
116 $customClass = new $customSearchClass($formValues);
127 public static function contactIDSQL($csID, $ssID) {
128 $customClass = self
::customClass($csID, $ssID);
129 return $customClass->contactIDs();
137 public static function &buildFormValues($args) {
140 $values = explode("\n", $args);
141 $formValues = array();
142 foreach ($values as $value) {
143 list($n, $v) = CRM_Utils_System
::explode('=', $value, 2);
145 $formValues[$n] = $v;
157 public static function fromWhereEmail($csID, $ssID) {
158 $customClass = self
::customClass($csID, $ssID);
160 $from = $customClass->from();
161 $where = $customClass->where();
163 return array($from, $where);