Skip to content

Commit

Permalink
Update README.md to match latests API changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Sauvat committed Aug 28, 2015
1 parent e76355b commit da7779d
Showing 1 changed file with 43 additions and 34 deletions.
77 changes: 43 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
# inetprocess/sugarcrm
That library allows anybody to interact with a SugarCRM application, outside that application. Suppose you need to do a importation script, running every night, with a very specific set of transformations or check. Then you need that kind of tools to be able to "Login" to SugarCRM, create or update beans, do SQL queries, etc ...
That library allows anybody to interact with a SugarCRM application, outside that application.
Suppose you need to do a importation script, running every night, with a very specific set of
transformations or check. Then you need that kind of tools to be able to "Login" to SugarCRM,
create or update beans, do SQL queries, etc ...

# Warning
* Be very careful that Sugar doesn't do a very "clean" job so it's better to deactivate the strict standards erorr reporting in PHP to be able to use it. When I launch my script, I usualy do something like:
* Be very careful that Sugar doesn't do a very "clean" job so it's better to deactivate
the strict standards erorr reporting in PHP to be able to use it. When I launch my script, I usualy do something like:
```bash
php -d 'error_reporting=E_ALL & ~E_STRICT' test.php
```

* If you are not using my classes in another class (if you do like in examples below, directly calling the library), be more careful: **don't name your variables like sugar does, else you'll overwrite it** (example: _$db_ or _$log_).
* If you are not using my classes in another class (if you do like in examples below, directly calling the library),
be more careful: **don't name your variables like sugar does, else you'll overwrite it** (example: _$db_ or _$log_).

* Last but not the least: you'll be able to instanciate the EntryPoint for only one instance of Sugar ! It uses GLOBALS variable such as $GLOBALS['db'] and I let you imagine what will happen if it's overwritten by another Instance of SugarCRM ;)
* Last but not the least: you'll be able to instanciate the EntryPoint for only one instance of Sugar !
It uses GLOBALS variable such as $GLOBALS['db'] and I let you imagine what will happen
if it's overwritten by another Instance of SugarCRM ;)

# Classes
## Inet\SugarCRM\EntryPoint
That's the class all other classes need. It says where is Sugar and does the basic steps to "login" into SugarCRM. EntryPoint needs a logger because other classes log a lot of stuff.
## Inet\SugarCRM\Application
Gives general information about SugarCRM Installation.
Others classes depends on this one.

Usage Example:
```php
<?php
require_once 'vendor/autoload.php';
use Psr\Log\NullLogger;
use Inet\SugarCRM\EntryPoint;
use Inet\SugarCRM\Application;

$nullLogger = new NullLogger;
// enter sugar
$sugarInetEP = new EntryPoint($nullLogger, '/home/sugarcrm/www', '1');
$sugarApp = new Application('/home/sugarcrm/www');
echo $sugarApp->getSugarPath();
if ($sugarApp->isValid()) {
echo $sugarApp->getVersion();
}
```

## Inet\SugarCRM\Application
Gives general information about SugarCRM Installation. For now, it only gives the same path we set on $entryPoint.
## Inet\SugarCRM\EntryPoint
It says where is Sugar and does the basic steps to "login" into SugarCRM.
EntryPoint needs a logger because other classes log a lot of stuff.
The EntryPoint can only be loaded once for the entire program.

Usage Example:
```php
<?php
require_once 'vendor/autoload.php';
use Psr\Log\NullLogger;
use Inet\SugarCRM\EntryPoint;
use Inet\SugarCRM\Application;
use Inet\SugarCRM\EntryPoint;

$nullLogger = new NullLogger;
// enter sugar
$sugarInetEP = new EntryPoint($nullLogger, '/home/sugarcrm/www', '1');
$sugarApp = new Application($sugarInetEP);
echo $sugarApp->getSugarPath();
if (!EntryPoint::isCreated()) {
$nullLogger = new NullLogger;
$sugarApp = new Application('/home/sugarcrm/www');
// enter sugar
EntryPoint::createInstance($nullLogger, $sugarApp, '1');
}
$sugarEP = EntryPoint::getInstance();
```

## Inet\SugarCRM\Bean
Expand All @@ -62,14 +75,18 @@ use Inet\SugarCRM\EntryPoint;
use Inet\SugarCRM\DB;
use Inet\SugarCRM\Bean;

$nullLogger = new NullLogger;
// enter sugar
$sugarInetEP = new EntryPoint($logger, '/home/sugarcrm/www', '1');
if (!EntryPoint::isCreated()) {
$nullLogger = new NullLogger;
$sugarApp = new Application('/home/sugarcrm/www');
// enter sugar
EntryPoint::createInstance($nullLogger, $sugarApp, '1');
}
$sugarEP = EntryPoint::getInstance();
// get the DB Class
$inetSugarDB = new DB($sugarInetEP);
$inetSugarDB = new DB($sugarEP);

// instanciate the Bean class to retrieve User with id 1
$inetSugarBean = new Bean($sugarInetEP, $inetSugarDB);
$inetSugarBean = new Bean($sugarEP, $inetSugarDB);
$adminUser = $inetSugarBean->getBean('Users', 1);
echo $adminUser->name;
```
Expand All @@ -84,15 +101,11 @@ Usage Example:
```php
<?php
require_once 'vendor/autoload.php';
use Psr\Log\NullLogger;
use Inet\SugarCRM\EntryPoint;
use Inet\SugarCRM\DB;

$nullLogger = new NullLogger;
// enter sugar
$sugarInetEP = new EntryPoint($logger, '/home/sugarcrm/www', '1');
// get the DB Class
$inetSugarDB = new DB($sugarInetEP);
$inetSugarDB = new DB(EntryPoint::getInstance());
$users = $inetSugarDB->doQuery('SELECT * FROM users');
echo count($users);
```
Expand All @@ -104,15 +117,11 @@ Usage Example:
```php
<?php
require_once 'vendor/autoload.php';
use Psr\Log\NullLogger;
use Inet\SugarCRM\EntryPoint;
use Inet\SugarCRM\Utils;

$nullLogger = new NullLogger;
// enter sugar
$sugarInetEP = new EntryPoint($logger, '/home/sugarcrm/www', '1');
// get the Utils Class
$inetSugarUtils = new Utils($sugarInetEP);
$inetSugarUtils = new Utils(EntryPoint::getInstance());
// Convert an array to a multiselect
$convertedArray = $inetSugarUtils->arrayToMultiselect(array('test' => 'inet'));
echo $convertedArray;
Expand Down

0 comments on commit da7779d

Please sign in to comment.