License: MIT
- Designed to work with SugarCRM 7 and the v10 REST API
ConveySugar is available via Composer
$ composer require warent/convey-sugar
<?php
namespace App;
use ConveySugar\Sugar;
use ConveySugar\Utilities\Search;
class ContactSearchingApp {
private $sugar;
public function __construct() {
// Creating our Sugar connection instance.
// Connection opens when newed up,
// so be sure accepting functions accept sugar by reference.
$this->sugar = new Sugar([
'SUGAR_URL' => 'https://sugar/rest/v10/',
'SUGAR_USERNAME' => 'admin',
'SUGAR_PASSWORD' => 'password'
]);
}
public function searchContacts() {
// Instantiating a new Sugar Utility
// This one cycles through all records within a Sugar module
$serchUtil = new Search(['resultsFn' => function($params) {
$resultCount = count($params['results']);
echo "$resultCount results from offset {$params['offset']}";
foreach ($params['results'] as $result) {
print_r($Result);
}
});
// We execute our Search Utility on the module 'Contacts'
$this->sugar->execute('Contacts', $searchUtil);
}
}
?>
Return the number of records within a sugar module
- None
Delete a record by ID
- recordID (Sugar ID [string]) Required
Insert a new record
- values (Assoc Array) Required
Cycle related records of one sugar record to another module
- recordID (Sugar ID [string]) Required
- relation (Sugar Module [string]) Required
- type (Related::Type [static int])
- Related::TYPE_NORMAL
- Related::TYPE_NAKED
- Related::TYPE_BACK
- number (Integer)
- transform (Related::Transform [static int])
- Related::TRANSFORM_JSON
- Related::TRANSFORM_BOOL
- resultsFn (Function)
- Parameters (Assoc Array)
- results (Array)
- offset (Integer)
- Parameters (Assoc Array)
- offset (Integer)
- limit (Integer)
Cycle records of a sugar module
- resultsFn (Function) Required
- Parameters (Assoc Array)
- results (Array)
- offset (Integer)
- Parameters (Assoc Array)
- offset (Integer)
- limit (Integer)
- Returning
false
in a resultsFn will stop/break the lookup
transform
will return JSON (Assoc Array) by default.TYPE_BOOL
willreturn true
if any results are found, otherwisereturn false
type
refers to theSugarCRM
formatting of relational queries. There are three (unofficial) known ways for this to happen in the Sugar API,NORMAL
,BACK
, andNAKED
: in aNORMAL
type the query is$module_$relation_$number
; in aBACK
type the query is$relation_$module_$number
; in aNAKED
type the query is simply$relation
.NORMAL
is the defaulttype
and1
is the defaultnumber
as these are the most common configurations.