Example #1
0
 public function metadata()
 {
     return MetadataCollection::instance($this->client)->{$this->entityLogicalName};
 }
Example #2
0
use AlexaCRM\CRMToolkit\Entity\MetadataCollection;
use AlexaCRM\CRMToolkit\Settings;
/*
 * Enable autoloading for the toolkit.
 *
 * CRM Toolkit for PHP is a PSR-4 compliant package.
 * If you installed the package via Composer, please use
 * its own autoloader which is generally placed in vendor/autoload.php
 *
 * See: https://getcomposer.org/doc/01-basic-usage.md#autoloading
 */
require_once '../init.php';
$clientOptions = (include 'config.php');
$clientSettings = new Settings($clientOptions);
$client = new Client($clientSettings);
$metadata = MetadataCollection::instance($client);
/*
 * When Client is instantiated, it connects to the CRM and retrieves
 * additional organization data. It is then stored in $clientSettings.
 */
if ($clientSettings->hasOrganizationData()) {
    echo "You have connected to the organization '{$clientSettings->organizationName}' [{$clientSettings->organizationUniqueName}]" . PHP_EOL;
} else {
    die('There was an error retrieving organization data for the CRM. Please check connection settings.');
}
// retrieve "WhoAmI" information
$whoAmIResponse = $client->executeAction('WhoAmI');
echo PHP_EOL . 'WhoAmI request response' . PHP_EOL;
echo '--------------------------' . PHP_EOL;
echo 'UserId: ' . $whoAmIResponse->UserId . PHP_EOL;
echo 'BusinessUnitId: ' . $whoAmIResponse->BusinessUnitId . PHP_EOL;
Example #3
0
 /**
  * Send a RetrieveMultipleEntities request to the Dynamics CRM server
  * and return the results as a structured Object
  * Each Entity returned is processed into an appropriate AlexaCRM\CRMToolkit\AlexaSDK_Entity object
  *
  * @param string $entityType logical name of entities to retrieve
  * @param boolean $allPages indicates if the query should be resent until all possible data is retrieved
  * @param string $pagingCookie if multiple pages are returned, send the paging cookie to get pages 2 and onwards.  Use NULL to get the first page.  Ignored if $allPages is specified.
  * @param integer $limitCount maximum number of records to be returned per page
  * @param boolean $simpleMode indicates if we should just use stdClass, instead of creating Entities
  *
  * @return stdClass a PHP Object containing all the data retrieved.
  */
 public function retrieveMultipleEntities($entityType, $allPages = true, $pagingCookie = null, $limitCount = null, $pageNumber = null, $simpleMode = false)
 {
     $queryXML = new DOMDocument();
     $fetch = $queryXML->appendChild($queryXML->createElement('fetch'));
     $fetch->setAttribute('version', '1.0');
     $fetch->setAttribute('output-format', 'xml-platform');
     $fetch->setAttribute('mapping', 'logical');
     $fetch->setAttribute('distinct', 'false');
     $entity = $fetch->appendChild($queryXML->createElement('entity'));
     $entity->setAttribute('name', $entityType);
     $entity->appendChild($queryXML->createElement('all-attributes'));
     $order = $entity->appendChild($queryXML->createElement('order'));
     $order->setAttribute('attribute', MetadataCollection::instance($this, $this->cache)->getEntityDefinition($entityType)->primaryNameAttribute);
     $order->setAttribute('descending', 'false');
     $queryXML->saveXML($fetch);
     return $this->retrieveMultiple($queryXML->C14N(), $allPages, $pagingCookie, $limitCount, $pageNumber, $simpleMode);
 }