PHP code example of inetprocess / libsugarcrm

1. Go to this page and download the library: Download inetprocess/libsugarcrm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inetprocess / libsugarcrm example snippets



sr\Log\NullLogger;
use Inet\SugarCRM\Application;

$sugarApp = new Application(new NullLogger(), '/home/sugarcrm/www');
echo $sugarApp->getPath();
if ($sugarApp->isValid()) {
    echo $sugarApp->getVersion();
}


sr\Log\NullLogger;
use Inet\SugarCRM\Application;
use Inet\SugarCRM\EntryPoint;

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


sr\Log\NullLogger;
use Inet\SugarCRM\EntryPoint;
use Inet\SugarCRM\Bean;

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

// instanciate the Bean class to retrieve User with id 1
$inetSugarBean = new Bean($sugarEP);
$adminUser = $inetSugarBean->getBean('Users', 1);
echo $adminUser->name;


net\SugarCRM\EntryPoint;
use Inet\SugarCRM\DB;

// get the DB Class
$inetSugarDB = new DB(EntryPoint::getInstance());
$users = $inetSugarDB->query('SELECT * FROM users');
echo count($users);


net\SugarCRM\EntryPoint;
use Inet\SugarCRM\Utils;

// get the Utils Class
$inetSugarUtils = new Utils(EntryPoint::getInstance());
// Convert an array to a multiselect
$convertedArray = $inetSugarUtils->arrayToMultiselect(array('test' => 'inet'));
echo $convertedArray;


$query = new \SugarQuery();
// setup $query

$iter = new SugarQueryIterator($query);
$iter->setStartOffset(100);
foreach ($iter as $id => $bean) {
   // Do something with $bean
   if ($iter->getIterationCounter() >= 200) {
       break;
   }
}
bash
php -d 'error_reporting=E_ALL & ~E_STRICT'  test.php