Skip to content

Instantly share code, notes, and snippets.

@SugarCRMExamples
Created March 20, 2014 02:37
Show Gist options
  • Save SugarCRMExamples/9656131 to your computer and use it in GitHub Desktop.
Save SugarCRMExamples/9656131 to your computer and use it in GitHub Desktop.
<?php
require_once('clients/base/api/ModuleApi.php');
class FavoriteBurgerApi extends ModuleApi
{
static public $favoriteBurgers = array(
"Poutine on the Ritz Burger",
"Mesclun Around Burger",
"The Don't Get Creme Fraiche With Me Burger",
"Onion-tended Consequences Burger",
"Bruschetta Bout It Burger",
"MediterrAin't Misbehavin' Burger",
"I'm Gonna Get You Succotash Burger",
"Every Breath You Tikka Masala Burger",
);
public function registerApiRest()
{
return array(
'retrieve' => array(
'reqType' => 'GET',
'path' => array('Contacts','?'),
'pathVars' => array('module','record'),
'method' => 'retrieveRecord',
'shortHelp' => 'Returns a single record, with their favorite burger attached',
'longHelp' => 'include/api/help/module_record_get_help.html',
),
);
}
public function retrieveRecord($api, $args)
{
// Have the moduleApi do the hard work
$data = parent::retrieveRecord($api, $args);
// People don't remember what burger they tried so just give them a random favorite
$burgerNum = rand(1,count(self::$favoriteBurgers)) - 1;
$data['favorite_burger'] = self::$favoriteBurgers[$burgerNum];
// Return the modified data
return $data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment