Added code to filter in quick search

This commit is contained in:
CiviWare Solutions 2018-08-30 17:27:46 +01:00
parent 213833f322
commit 6ac1eaf067
2 changed files with 5 additions and 69 deletions

View File

@ -1,63 +0,0 @@
<?php
require_once 'api/Wrapper.php';
/**
* Class CRM_Utils_API_ConstituentsOnlyAPIWrapper
*/
class CRM_Utils_API_ConstituentsOnlyAPIWrapper implements API_Wrapper {
/**
* @var CRM_Utils_API_ReloadOption
*/
private static $_singleton = NULL;
/**
* @return CRM_Utils_API_ReloadOption
*/
public static function singleton() {
if (self::$_singleton === NULL) {
self::$_singleton = new CRM_Utils_API_ConstituentsOnlyAPIWrapper();
}
return self::$_singleton;
}
/**
* @inheritDoc
*/
public function fromApiInput($apiRequest) {
return $apiRequest;
}
/**
* @inheritDoc
*/
public function toApiOutput($apiRequest, $result) {
$search_term = @$apiRequest['params']['name'];
if (strlen($search_term) > 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;
}
}

View File

@ -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);
}
/**