Forked from betobaz/custom_clients_base_api_UserCustomApi.php
Last active
December 13, 2016 04:31
-
-
Save brakon/5e3b64099d0fe98894eccce4d570a660 to your computer and use it in GitHub Desktop.
User Custom Api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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