warent/convey-sugar

There is no license information available for the latest version (dev-master) of this package.

Extensions for SugarCRM to more easily and flexibly manipulate data

dev-master 2016-07-16 23:12 UTC

This package is not auto-updated.

Last update: 2024-03-16 16:53:02 UTC


README

License: MIT

1. About

  • Designed to work with SugarCRM 7 and the v10 REST API

2. Installation

ConveySugar is available via Composer $ composer require warent/convey-sugar

3. Usage Examples

<?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);
		}
	}
?>

4. Utilities

Count

Description

Return the number of records within a sugar module

Parameters

  • None

Delete

Description

Delete a record by ID

Parameters

  • recordID (Sugar ID [string]) Required

Insert

Description

Insert a new record

Parameters

  • values (Assoc Array) Required

Related

Description

Cycle related records of one sugar record to another module

Parameters

  • 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)
  • offset (Integer)
  • limit (Integer)

Search

Description

Cycle records of a sugar module

Parameters

  • resultsFn (Function) Required
    • Parameters (Assoc Array)
      • results (Array)
      • offset (Integer)
  • offset (Integer)
  • limit (Integer)

5. Extra Features

resultsFn

  • Returning false in a resultsFn will stop/break the lookup

Related (Utility)

  • transform will return JSON (Assoc Array) by default. TYPE_BOOL will return true if any results are found, otherwise return 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, and NAKED: in a NORMAL type the query is $module_$relation_$number; in a BACK type the query is $relation_$module_$number; in a NAKED type the query is simply $relation. NORMAL is the default type and 1 is the default number as these are the most common configurations.

Thank you