Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
User Custom Api
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* By installing or using this file, you are confirming on behalf of the entity
* subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
* the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
* http://www.sugarcrm.com/master-subscription-agreement
*
* If Company is not bound by the MSA, then by installing or using this file
* you are agreeing unconditionally that Company will be bound by the MSA and
* certifying that you have authority to bind Company accordingly.
*
* Copyright (C) 2004-2014 SugarCRM Inc. All rights reserved.
********************************************************************************/
require_once 'include/api/SugarApi.php';
class CustomUserApi extends SugarApi
{
public function registerApiRest()
{
return array(
'retrive_by_emails' => array(
'reqType' => 'GET',
'path' => array('Users','filter','email',),
'pathVars' => array(),
'method' => 'retriveUsersByEmailAddress',
'shortHelp' => 'Retrieve Users by email addresses',
'longHelp' => '',
),
);
}
public function retriveUsersByEmailAddress($api, $args)
{
$users = array();
//$users['args'] = $args;
$emailAddresses = explode(",",preg_replace('/[\[\]\"]/', '', $args['email_addresses']));
$email = BeanFactory::getBean('EmailAddresses');
$q = $email->getEmailsQuery('Users');
$q->joinRaw("JOIN users ON users.deleted = 0 and users.id = ear.bean_id", array('alias' => 'users'));
$q->where()
->in("email_addresses.email_address", $emailAddresses)
->equals("ear.primary_address", "1");
$q->select->field("ear.bean_id");
$q->select->fieldRaw("users.user_name");
$email_rows = $q->execute();
$users['users'] = $email_rows;
return $users;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment