Skip to content

Instantly share code, notes, and snippets.

@elchele
Created February 2, 2018 19:37
Show Gist options
  • Save elchele/9a644dfa4ed2aaffba5089f971c5ad72 to your computer and use it in GitHub Desktop.
Save elchele/9a644dfa4ed2aaffba5089f971c5ad72 to your computer and use it in GitHub Desktop.
Custom FilterAPI that hard codes an additional condition to the default "My Accounts" filter
<?php
/* File: ./custom/modules/Accounts/clients/base/api/CustomFilterApi.php */
require_once 'clients/base/api/FilterApi.php';
class CustomFilterApi extends FilterApi
{
public function registerApiRest()
{
return array(
'filterModuleGet' => array(
'reqType' => 'GET',
'path' => array('<module>', 'filter'),
'pathVars' => array('module', ''),
'method' => 'filterList',
'jsonParams' => array('filter'),
'shortHelp' => 'Lists filtered records.',
'longHelp' => 'include/api/help/module_filter_get_help.html',
'exceptions' => array(
// Thrown in filterList
'SugarApiExceptionInvalidParameter',
// Thrown in filterListSetup and parseArguments
'SugarApiExceptionNotAuthorized',
),
),
);
}
public function __construct()
{
global $current_user;
self::$current_user = $current_user;
}
protected static function addOwnerFilter(
SugarQuery $q,
SugarQuery_Builder_Where $where,
$link
) {
parent::addOwnerFilter($q, $where, $link);
//Force a specific AND condition on the My Accounts default filter
$where->equals('billing_address_city', 'Santa Fe');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment