forked from CiviWare/com.dpci.constituentsonly
added extension
This commit is contained in:
46
CRM/ConstituentsOnly/BAO/Query.php
Normal file
46
CRM/ConstituentsOnly/BAO/Query.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
class CRM_ConstituentsOnly_BAO_Query extends CRM_Contact_BAO_Query_Interface {
|
||||
|
||||
static $_networkFields = array();
|
||||
|
||||
public function &getFields() {
|
||||
return self::$_networkFields;
|
||||
}
|
||||
|
||||
public function select(&$query) { }
|
||||
|
||||
/**
|
||||
* Build where clause for ConstituentsOnly
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function where(&$query) {
|
||||
$grouping = 0;
|
||||
$statement = "NOT (contact_a.do_not_trade <=> 1)";
|
||||
$query->_where[$grouping][] = $statement;
|
||||
}
|
||||
|
||||
public function from($name, $mode, $side) {
|
||||
$from = NULL;
|
||||
return $from;
|
||||
}
|
||||
|
||||
public function setTableDependency(&$tables) {
|
||||
}
|
||||
|
||||
public function getPanesMapper(&$panes) {
|
||||
}
|
||||
|
||||
public function registerAdvancedSearchPane(&$panes) {
|
||||
}
|
||||
|
||||
public function buildAdvancedSearchPaneForm(&$form, $type) {
|
||||
}
|
||||
|
||||
public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) {
|
||||
}
|
||||
|
||||
}
|
||||
|
61
CRM/Utils/API/ConstituentsOnlyAPIWrapper.php
Executable file
61
CRM/Utils/API/ConstituentsOnlyAPIWrapper.php
Executable file
@ -0,0 +1,61 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user