diff --git a/CRM/Utils/API/ConstituentsOnlyAPIWrapper.php b/CRM/Utils/API/ConstituentsOnlyAPIWrapper.php deleted file mode 100755 index d408e9f..0000000 --- a/CRM/Utils/API/ConstituentsOnlyAPIWrapper.php +++ /dev/null @@ -1,63 +0,0 @@ - 0) { - foreach ($result['values'] as $key => $api_result) { - try { - $additional_result = civicrm_api3('Contact', 'get', array( - 'debug' => 1, - 'sequential' => 1, - 'contact_id' => array('=' => $api_result['id']), - )); - } - catch (CiviCRM_API3_Exception $e) { - $error = $e->getMessage(); - } - - // If contact is not a constituent, they are already filtered. - // Remove that contact from the Quick Search results. - if ($additional_result['count'] == 0) { - unset($result['values'][$key]); - // Decrement count - $result['count'] -= 1; - } - } - } - return $result; - } - -} diff --git a/constituentsonly.php b/constituentsonly.php index d77cd31..cf3d251 100644 --- a/constituentsonly.php +++ b/constituentsonly.php @@ -135,14 +135,13 @@ function constituentsonly_civicrm_queryObjects(&$queryObjects, $type) { } /** - * Implements hook_civicrm_apiWrappers(). + * Implements hook_civicrm_contactListQuery(). * - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_contactListQuery */ -function constituentsonly_civicrm_apiWrappers(&$wrappers, $apiRequest) { - if ($apiRequest['entity'] == 'Contact' && $apiRequest['action'] == 'getquick') { - $wrappers[] = new CRM_Utils_API_ConstituentsOnlyAPIWrapper(); - } +function constituentsonly_civicrm_contactListQuery(&$query, $queryText, $context, $id) { + $replace = 'WHERE (cc.do_not_trade IS NULL OR cc.do_not_trade = 0) AND '; + $query = str_replace('WHERE ', $replace, $query); } /**