Dynamics Crm Connector  v1.0
 All Data Structures Namespaces Files Functions Variables Pages
Public Member Functions | Data Fields | Private Member Functions | Private Attributes
DynamicsCrm Class Reference

Public Member Functions

 __construct ($serv_adress, $user, $password)
 
 getServAdress ()
 
 setServAdress ($serv_adress)
 
 getUser ()
 
 setUser ($user)
 
 getPassword ()
 
 setPassword ($password)
 
 Retrieve ($Table, $Id, $Columns)
 
 RetrieveMultiple ($Table, $Where, $Columns=false, $Join=false, $Order=false)
 
 Delete ($Table, $Id)
 
 Update ($Table, $Params, $Id)
 
 Create ($Table, $Params)
 
 SetState ($Id, $Table, $StateCode, $StatusCode)
 
 GetAllEntities ()
 
 Workflow ($EntityId, $WorkflowId)
 
 Associate ()
 
 Assign ($Table, $Id, $IdAssign, $TypeAssign='systemuser')
 
 GetCurrentUserInfo ()
 

Data Fields

 $serv_adress
 
 $user
 
 $password
 

Private Member Functions

 ExecuteBody ($Request)
 
 call ($operation, $soapBody)
 
 FormatFetchEntity ($EntityName)
 
 FormatFetchAttribute ($Columns)
 
 FormatAttributes ($Params)
 
 FormatAttribute ($Param)
 
 TestParameters ($Param, $Fields)
 
 TestParameter ($Param, $field)
 
 TestAgreggate ($Param)
 
 GetErrorObject ($message)
 
 FormatColumn ($Columns)
 
 FormatFetchOrder ($Orders)
 
 FormatFetchFilter ($Filters)
 
 FormatFetchJoin ($Joins)
 
 FormatCondition ($Filter)
 
 ParseRetrieveMultiple ($xml, $Return)
 
 ParseDatas ($Datas, $Return)
 
 ParseResultLine ($Data)
 
 ParseKeyPair ($data)
 
 ParseRetrieve ($xml, $Return)
 
 GenerateSoapHeader ($operation)
 
 array_key_exists_r ($needle, $haystack)
 

Private Attributes

 $StateCheck
 
 $Aggregate = array ('avg','max','min','sum','count','countcolumn','countdistinct')
 
 $Operator
 

Detailed Description

Definition at line 67 of file DynamicsCrm.php.

Constructor & Destructor Documentation

__construct (   $serv_adress,
  $user,
  $password 
)

Constructor

Parameters
string$serv_adressUrl to service
string$userDynamics CRM connection's User

(LDAP) Domain/user

Parameters
string$passwordDynamics CRM connection's password

Definition at line 128 of file DynamicsCrm.php.

References setPassword(), setServAdress(), and setUser().

128  {
129  $this->setServAdress ( $serv_adress );
130  $this->setUser ( $user );
131  $this->setPassword ( $password );
132  }
setUser($user)
setServAdress($serv_adress)
setPassword($password)

Member Function Documentation

array_key_exists_r (   $needle,
  $haystack 
)
private

Recursive array_key_exist

Parameters
$needlewhat you want to find
$haystackwhere you want to find it
Returns
boolean

Definition at line 1417 of file DynamicsCrm.php.

Referenced by RetrieveMultiple().

1417  {
1418  $result = array_key_exists ( $needle, $haystack );
1419  if ($result)
1420  return $result;
1421  foreach ( $haystack as $v ) {
1422  if (is_array ( $v ) || is_object ( $v ))
1423  $result = $this->array_key_exists_r ( $needle, $v );
1424  if ($result)
1425  return $result;
1426  }
1427  return $result;
1428  }
array_key_exists_r($needle, $haystack)
Assign (   $Table,
  $Id,
  $IdAssign,
  $TypeAssign = 'systemuser' 
)

Will assign a new owner to an Crm object

Parameters
string$Table

the Table of the entity you want to update

Parameters
string$Id

the GUID of the entity you want to update

Parameters
string$IdAssign

the GUID that will be used as new owner

Parameters
string$TypeAssign

Not required set by default as systemuser,
someday could be of some use to set anything else

Definition at line 574 of file DynamicsCrm.php.

References ExecuteBody().

574  {
575  $Request = '<request i:type="b:AssignRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
576  <a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
577  <a:KeyValuePairOfstringanyType>
578  <c:key>Target</c:key>
579  <c:value i:type="a:EntityReference">
580  <a:Id>'.$Id.'</a:Id>
581  <a:LogicalName>'.$Table.'</a:LogicalName>
582  <a:Name i:nil="true" />
583  </c:value>
584  </a:KeyValuePairOfstringanyType>
585  <a:KeyValuePairOfstringanyType>
586  <c:key>Assignee</c:key>
587  <c:value i:type="a:EntityReference">
588  <a:Id>'.$IdAssign.'</a:Id>
589  <a:LogicalName>'.$TypeAssign.'</a:LogicalName>
590  <a:Name i:nil="true" />
591  </c:value>
592  </a:KeyValuePairOfstringanyType>
593  </a:Parameters>
594  <a:RequestId i:nil="true" />
595  <a:RequestName>Assign</a:RequestName>
596  </request>';
597 
598  $Response= $this->ExecuteBody ( $Request );
599  if(isset( $Response->Error) && $Response->Error===true){
600  return $Response;
601  }else{
602  $Return = new CrmResponse ();
603  $Return->Error = false;
604  $Return->ErrorCode = false;
605  $Return->ErrorMessage = '';
606  $Return->NbResult =1 ;
607  $Return->Result=true;
608  return $Return;
609  }
610  }
Result object for DynamicCRM.
Definition: CrmResponse.php:36
ExecuteBody($Request)
Associate ( )
Todo:
Returns
result

Definition at line 539 of file DynamicsCrm.php.

References call().

539  {
540  $SoapEnvelope = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
541  <soap:Body>
542  <Associate xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
543  <subType>
544  </subType>
545  <objectType>
546  10069</objectType>
547  <parentObjectType>10095</parentObjectType>
548  <objectId>568B31F9-8AEE-E211-8830-005056B74E4F</objectId>
549  <parentId>A5DF8846-3BF0-E211-8830-005056B74E4F</parentId>
550  <associationName>classification_occupation</associationName>
551  </Associate></soap:Body>
552  </soap:Envelope>';
553  return $this->call ( 'Associate', $SoapEnvelope );
554  }
call($operation, $soapBody)
call (   $operation,
  $soapBody 
)
private

Format Entity Header

Parameters
string$operationName of the action to be done
string$soapBodySoap body request according to the Action
Returns
result parsed and in an CrmResponse Object according to action

Definition at line 655 of file DynamicsCrm.php.

References GenerateSoapHeader(), if(), ParseRetrieve(), and ParseRetrieveMultiple().

Referenced by Associate(), Create(), Delete(), ExecuteBody(), Retrieve(), RetrieveMultiple(), and Update().

655  {
656  $headers = $this->GenerateSoapHeader ( $operation );
657 
658  $ch = curl_init ();
659  curl_setopt ( $ch, CURLOPT_URL, $this->serv_adress );
660  curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
661  curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
662  curl_setopt ( $ch, CURLOPT_UNRESTRICTED_AUTH,true);
663  curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION,true);
664  curl_setopt ( $ch, CURLOPT_POST, true );
665  curl_setopt ( $ch, CURLOPT_POSTFIELDS, $soapBody );
666  curl_setopt ( $ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM );
667  curl_setopt ( $ch, CURLOPT_USERPWD, $this->user . ':' . $this->password );
668  $response = curl_exec ( $ch );
669  $Return = new CrmResponse ();
670  if ($response === false) {
671  $Return->Error = True;
672  $Return->ErrorCode = 0;
673  $Return->ErrorMessage = curl_error ( $ch );
674  $Return->Result = False;
675  } else {
676 
677  $response = str_replace ( '<a:', '<', $response );
678  $response = str_replace ( '<b:', '<', $response );
679  $response = str_replace ( '<c:', '<', $response );
680  $response = str_replace ( '<s:', '<', $response );
681  $response = str_replace ( '</a:', '</', $response );
682  $response = str_replace ( '</b:', '</', $response );
683  $response = str_replace ( '</c:', '</', $response );
684  $response = str_replace ( '</s:', '</', $response );
685  $xml = simplexml_load_string ( $response );
686  if (isset ( $xml->Body->Fault )) {
687  $Return->Error = True;
688  $Return->ErrorCode = ( string ) $xml->Body->Fault->faultcode;
689  $Return->ErrorMessage = ( string ) $xml->Body->Fault->faultstring;
690  $Return->Result = False;
691  } else {
692  switch ($operation) {
693  case 'RetrieveMultiple' :
694  $Return = $this->ParseRetrieveMultiple ( $xml, $Return );
695  Break;
696  case 'Retrieve' :
697  $Return = $this->ParseRetrieve ( $xml, $Return );
698  Break;
699  case 'Create' :
700  $Return->NbResult = 1;
701  $Return->Result = ( string ) $xml->Body->CreateResponse->CreateResult;
702  Break;
703  case 'Update' :
704  if (isset ( $xml->Body->UpdateResponse )) {
705  $Return->NbResult = 1;
706  $Return->Result = true;
707  } else {
708  $Return->Error = True;
709  $Return->ErrorCode = 'Unknown Error';
710  $Return->ErrorMessage = 'Unknown Error';
711  }
712  Break;
713  case 'Execute' :
714  $Return->NbResult = 1;
715  $Return->Result = $xml;
716  break;
717  case 'Associate' :
718  die ( print_r ( $xml ) );
719  break;
720  case 'Delete' :
721  if (isset ( $xml->Body->DeleteResponse )) {
722  $Return->NbResult = 1;
723  $Return->Result = true;
724  } else {
725  $Return->Error = True;
726  $Return->ErrorCode = 'Unknown Error';
727  $Return->ErrorMessage = 'Unknown Error';
728  }
729  Break;
730  }
731  }
732  }
733 
734  return $Return;
735  }
ParseRetrieve($xml, $Return)
if(!b.support.opacity)
Definition: jquery.js:28
ParseRetrieveMultiple($xml, $Return)
GenerateSoapHeader($operation)
Result object for DynamicCRM.
Definition: CrmResponse.php:36
Create (   $Table,
  $Params 
)

Create a new row

Parameters
string$Table

the table where you want to create a new row

Parameters
array$Params
  • array(
  • 1=>array(
  • 'field'=>'fieldname',
  • 'type'=>'Field type',
  • 'value'=>'value'
  • ) ,
  • 2=>array(
  • 'field'=>'fieldname',
  • 'type'=>'EntityReference',
  • 'id'=>'guidforentity',
  • 'name'=>'entityname(table)'
  • ) ,
    *)
Returns
objet CrmResponse.
  • Bool $Error,
  • String $ErrorCode,
  • String $ErrorMessage,
  • $Result => Guid or false depending if query worked or not,

Definition at line 406 of file DynamicsCrm.php.

References call(), FormatAttributes(), and GetErrorObject().

406  {
407  try {
408  $Param = $this->FormatAttributes ( $Params );
409  } catch ( Exception $e ) {
410  return $this->GetErrorObject ( $e->getMessage () );
411  }
412  $SoapEnvelope = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
413  <soap:Body>
414  <Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
415  <entity xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
416  <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
417  ' . $Param . '
418  </b:Attributes>
419  <b:EntityState i:nil="true"/>
420  <b:FormattedValues />
421  <b:Id>00000000-0000-0000-0000-000000000000</b:Id>
422  <b:LogicalName>' . $Table . '</b:LogicalName>
423  <b:RelatedEntities />
424  </entity></Create></soap:Body>
425  </soap:Envelope>';
426  return $this->call ( 'Create', $SoapEnvelope );
427  }
call($operation, $soapBody)
GetErrorObject($message)
FormatAttributes($Params)
Delete (   $Table,
  $Id 
)

Delete a row

Parameters
string$Table

the table where you want to delete a row

Parameters
string$Idmostly a GUID from the id column (key) ...
Returns
obj CrmResponse.
  • Bool $Error,
  • String $ErrorCode,
  • String $ErrorMessage,
  • $Result => Guid or false depending if query worked or not,

Definition at line 310 of file DynamicsCrm.php.

References call().

310  {
311  // build soap Enveloppe
312  $SoapEnvelope = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
313  <soap:Header/>
314  <soap:Body>
315  <ser:Delete>
316  <ser:entityName>' . $Table . '</ser:entityName>
317  <ser:id>' . $Id . '</ser:id>
318  </ser:Delete>
319  </soap:Body>
320  </soap:Envelope>';
321  // call
322  Return $this->call ( 'Delete', $SoapEnvelope );
323  }
call($operation, $soapBody)
ExecuteBody (   $Request)
private

Format Entity Header

Parameters
string$RequestRequest Body for Execute
Returns
result parsed and in an CrmResponse Object according to action

Definition at line 635 of file DynamicsCrm.php.

References call().

Referenced by Assign(), GetAllEntities(), GetCurrentUserInfo(), SetState(), and Workflow().

635  {
636  $SoapEnvelope = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
637  <s:Body>
638  <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
639  ' . $Request . '
640  </Execute>
641  </s:Body>
642  </s:Envelope>';
643  return $this->call ( 'Execute', $SoapEnvelope );
644  }
call($operation, $soapBody)
FormatAttribute (   $Param)
private

Format Attributes for insert updates and execute

Parameters
array$ParamAttribute parameter
  • array(
  • 'field'=>'fieldname',
  • 'type'=>'Field type',
  • 'value'=>'value'
  • )
  • array(
  • 'field'=>'fieldname',
  • 'type'=>'EntityReference',
  • 'id'=>'guidforentity',
  • 'name'=>'entityname(table)'
  • )
Returns
correct Attribute XML for insert/update/execute cases

Definition at line 889 of file DynamicsCrm.php.

References TestParameter(), and TestParameters().

Referenced by FormatAttributes().

889  {
890  $TxtAttribute = '';
891  $this->TestParameters ( $Param, array('field','type') );
892  if (isset ( $Param ['field'] ) && isset ( $Param ['type'] )) {
893  $TxtAttribute .= '<b:KeyValuePairOfstringanyType>
894  <c:key>' . $Param ['field'] . '</c:key>';
895  switch ($Param ['type']) {
896  case 'OptionSetValue' :
897  case 'optionsetvalue' :
898  case 'option' :
899  case 'Option' :
900  $this->TestParameter ( $Param, 'value' );
901  $TxtAttribute .= '<c:value i:type="b:OptionSetValue"><b:Value>' . $Param ['value'] . '</b:Value></c:value>';
902  break;
903  case 'Money' :
904  case 'money' :
905  $this->TestParameter ( $Param, 'value' );
906  $TxtAttribute .= '<c:value i:type="b:Money"><b:value>' . $Param ['value'] . '</b:value></c:value>';
907  break;
908  case 'Boolean' :
909  case 'boolean' :
910  case 'bool' :
911  case 'Bool' :
912  $this->TestParameter ( $Param, 'value' );
913  $TxtAttribute .= '<c:value i:type="d:boolean" xmlns:d="http://www.w3.org/2001/XMLSchema">' . $Param ['value'] . '</c:value>';
914  break;
915  case 'Integer' :
916  case 'integer' :
917  case 'Int' :
918  case 'int' :
919  $this->TestParameter ( $Param, 'value' );
920  $TxtAttribute .= '<c:value i:type="d:int" xmlns:d="http://www.w3.org/2001/XMLSchema">' . $Param ['value'] . '</c:value>';
921  break;
922  case 'DateTime' :
923  case 'datetime' :
924  $this->TestParameter ( $Param, 'value' );
925  $TxtAttribute .= '<c:value i:type="d:dateTime" xmlns:d="http://www.w3.org/2001/XMLSchema">' . $Param ['value'] . '</c:value>';
926  break;
927  case 'String' :
928  case 'string' :
929  default :
930  $this->TestParameter ( $Param, 'value' );
931  $TxtAttribute .= '<c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">' . $Param ['value'] . '</c:value>';
932  break;
933  case 'EntityReference' :
934  case 'entityreference' :
935  case 'Entity' :
936  case 'entity' :
937  $this->TestParameter ( $Param, 'id','name' );
938  $TxtAttribute .= '<c:value i:type="b:EntityReference">
939  <b:Id>' . $Param ['id'] . '</b:Id>
940  <b:LogicalName>' . $Param ['name'] . '</b:LogicalName>
941  <b:Name i:nil="true" />
942  </c:value>';
943  break;
944  case 'ActivityParty' :
945  case 'Activity' :
946  case 'activityparty' :
947  case 'activity' :
948  case 'ArrayOfEntity' :
949  case 'arrayofentity' :
950  case 'Array' :
951  case 'array' :
952  $TxtAttribute .= '<c:value i:type="b:ArrayOfEntity">';
953  $this->TestParameter ( $Param, 'value' );
954  foreach ( $Param ['value'] as $entity ) {
955  $TxtAttribute .= ' <b:Entity>
956  <b:Attributes>';
957  $TxtAttribute .= $this->FormatAttribute ( $entity );
958  $TxtAttribute .= '</b:Attributes><b:Entitystate i:nil="true" />
959  <b:FormattedValues />
960  <b:Id>00000000-0000-0000-0000-000000000000</b:Id>
961  <b:LogicalName>activityparty</b:LogicalName>
962  <b:RelatedEntities />
963  </b:Entity>';
964  }
965  $TxtAttribute .= '
966  </c:value>';
967 
968  break;
969  }
970  $TxtAttribute .= '</b:KeyValuePairOfstringanyType>';
971  }
972 
973  return $TxtAttribute;
974  }
FormatAttribute($Param)
TestParameter($Param, $field)
TestParameters($Param, $Fields)
FormatAttributes (   $Params)
private

Format Attributes for insert,updates and execute

Parameters
array$ParamsAttributes parameter
  • array(
  • 1=>array(
  • 'field'=>'fieldname',
  • 'type'=>'Field type',
  • 'value'=>'value'
  • ) ,
  • 2=>array(
  • 'field'=>'fieldname',
  • 'type'=>'EntityReference',
  • 'id'=>'guidforentity',
  • 'name'=>'entityname(table)'
  • ) 3=>array(
  • 'field'=>'fieldname',
  • 'type'=>'ActivityParty',
  • 'value'=>array(
    "entity1"=>array(
  • 1=>array(
  • 'field'=>'fieldname',
  • 'type'=>'Field type',
  • 'value'=>'value'
  • ) ,
  • 2=>array(
  • 'field'=>'fieldname',
  • 'type'=>'EntityReference',
  • 'id'=>'guidforentity',
  • 'name'=>'entityname(table)'
  • )
  • )
  • )
    ,
    *)
    Returns
    correct Attributes XML for insert/update/execute cases

Definition at line 856 of file DynamicsCrm.php.

References FormatAttribute().

Referenced by Create(), and Update().

856  {
857  $TxtAttribute = '';
858 
859  if (is_array ( $Params )) {
860  foreach ( $Params as $Param ) {
861  $TxtAttribute .= $this->FormatAttribute ( $Param );
862  }
863  }
864  return $TxtAttribute;
865  }
FormatAttribute($Param)
FormatColumn (   $Columns)
private

Format Columns for REtrieveMultiple

Parameters
array$Columnsarray with colnames or false for all col
  • array(
  • 'colname1',
  • 'colname2'...
  • )
    notice it will always return GUID Except with agregate function
Returns
correct Columns XML for REtrieveMultiple

Definition at line 1032 of file DynamicsCrm.php.

Referenced by Retrieve().

1032  {
1033  if ($Columns !== false && ! is_array ( $Columns )) {
1034  throw new \InvalidArgumentException ( sprintf ( "Column Parameter invalid : $Columns" ) );
1035  }
1036  $AllCol = ($Columns == false) ? 'true' : 'false';
1037  $TxtColumn = '<ser:columnSet><con:AllColumns>' . $AllCol . '</con:AllColumns><con:Columns>';
1038  if ($Columns != false) {
1039  foreach ( $Columns as $Column ) {
1040  $TxtColumn .= '<arr:string>' . $Column . '</arr:string>';
1041  }
1042  }
1043  $TxtColumn .= '</con:Columns></ser:columnSet>';
1044  return $TxtColumn;
1045  }
FormatCondition (   $Filter)
private

Format condition Depending on Operator

Parameters
array$Filter,<p>*array(
*'Column' => (String) $ColumnName
*'Op' => Operator link to all operator
*'Value' => $Value (if necessary depending on operator, data or could be an array)
*'Value2' => $Value2 (if necessary mostly in between case)
*)
Returns
correct XML for request this condition

Definition at line 1208 of file DynamicsCrm.php.

References TestParameters().

Referenced by FormatFetchFilter().

1208  {
1209 
1210  /*
1211  * The operators wich dont need a value
1212  * so no need for value here
1213  */
1214  if (in_array ( $Filter ['Op'], $this->Operator ['0'] )) {
1215  $Condition = "&lt;condition attribute='" . $Filter ['Column'] . "' operator='" . $Filter ['Op'] . "' /&gt;";
1216  /*
1217  * The basic operators
1218  * Value to be set, nothing much
1219  */
1220  } else if (in_array ( $Filter ['Op'], $this->Operator ['1'] )) {
1221  $this->TestParameters ( $Filter, array (
1222  'Column',
1223  'Value'
1224  ) );
1225  $Condition = "&lt;condition attribute='" . $Filter ['Column'] . "' operator='" . $Filter ['Op'] . "' value='" . $Filter ['Value'] . "' /&gt;";
1226  /*
1227  * The in operators
1228  * Value is now an array with data to be tested array('1','2',...)
1229  */
1230  } else if (in_array ( $Filter ['Op'], $this->Operator ['2'] )) {
1231  $this->TestParameters ( $Filter, array (
1232  'Column',
1233  'Value'
1234  ) );
1235  $Condition = "&lt;condition attribute='" . $Filter ['Column'] . "' operator='" . $Filter ['Op'] . "' &gt;";
1236  if (! is_array ( $Filter ['Value'] )) {
1237  $TxtFilter = print_r ( $Filter, true );
1238  throw new \InvalidArgumentException ( sprintf ( "Filter Incorrect [Value] for this kind of operator should be an array : $TxtFilter" ) );
1239  }
1240  foreach ( $Filter ['Value'] as $Value ) {
1241  $Condition .= '&lt;value&gt;' . $Value . '&lt;/value&gt;';
1242  }
1243  $Condition .= '&lt;/condition &gt;';
1244  /*
1245  * The 2 values operator
1246  * Value and Value2 in array
1247  */
1248  } else if (in_array ( $Filter ['Op'], $this->Operator ['3'] )) {
1249  $this->TestParameters ( $Filter, array (
1250  'Column',
1251  'Value','Value2'
1252  ) );
1253  $Condition = "&lt;condition attribute='" . $Filter ['Column'] . "' operator='" . $Filter ['Op'] . "' &gt;";
1254  $Condition .= '&lt;value&gt;' . $Filter ['Value'] . '&lt;/value&gt; &lt;value&gt;' . $Filter[
1255  'Value2'
1256  ] . '&lt;/value&gt;';
1257  $Condition .= '&lt;/condition &gt;';
1258  } else {
1259  $ListOperator = print_r ( $this->Operator, true );
1260  throw new \InvalidArgumentException ( sprintf ( "Condition '" . $Filter ['Op'] . "' Invalid should be in : $ListOperator" ) );
1261  }
1262 
1263  return $Condition;
1264  }
TestParameters($Param, $Fields)
FormatFetchAttribute (   $Columns)
private

Format Fetch Attributes

(Column being resolved by RetrieveMultiple)

Parameters
array$Columns
  • simple request
  • array(
  • 'Colname1',
  • 'Colname2'...
  • )

    *aggregate request
  • array(
  • '1'=>array(
  • 'name'=>'colname',
  • 'alias'=> 'alias',(false,notset => will keep colname as alias)
  • 'aggregate' =>'aggregate function name' ,if aggregate function needed else false or unset (avg , max, min, sum, count => SQL : (COUNT(*)) ,countcolumn => SQL : (COUNT(name)) ,countdistinct => SQL : (COUNT(DISTINCT name)) )
  • ),
  • '2'=> array(
  • 'name'=>'colname',
  • 'alias'=> 'alias',(false,notset => will keep colname as alias)
  • 'groupby' =>true or year,quarter,month,week,day for date grouping
  • )
  • )

    note that you cant mix simple column with agregates
    Returns
    correct XML for Columns

Definition at line 775 of file DynamicsCrm.php.

References TestAgreggate(), and TestParameter().

Referenced by FormatFetchJoin(), and RetrieveMultiple().

775  {
776  $Attributes = '';
777  if (is_array ( $Columns )) {
778  foreach ( $Columns as $column ) {
779  if (is_array ( $column )) {
780  $this->TestParameter ( $column, 'name' );
781  // aggregate cases
782  if (isset ( $column ['name'] )) {
783  if (empty ( $column ['alias'] )) {
784  $column ['alias'] = $column ['name'];
785  }
786  // basic aggregate function avg , max, min, sum, count (COUNT(*)) ,countcolumn (COUNT(name)) ,countdistinct (COUNT(DISTINCT name))
787  if (! empty ( $column ['aggregate'] )) {
788  $this->TestAgreggate ( $column ['aggregate'] );
789  if ($column ['aggregate'] == 'countdistinct') {
790  $Attributes .= "&lt;attribute name='" . $column ['name'] . "' alias='" . $column ['alias'] . "' aggregate='countcolumn' distinct='true' /&gt;";
791  } else {
792  $Attributes .= "&lt;attribute name='" . $column ['name'] . "' alias='" . $column ['alias'] . "' aggregate='" . $column ['aggregate'] . "' /&gt;";
793  }
794  // so is that a groupby?
795  } else if (isset ( $column ['groupby'] )) {
796  $this->TestParameter ( $column, 'alias' );
797  if (isset ( $column ['alias'] )) {
798  if ($column ['groupby'] !== true) {
799  $Attributes .= "&lt;attribute name='" . $column ['name'] . "' alias='" . $column ['alias'] . "' dategrouping='" . $column ['groupby'] . "' groupby='true' /&gt;";
800  } else {
801  $Attributes .= "&lt;attribute name='" . $column ['name'] . "' alias='" . $column ['alias'] . "' groupby='true' /&gt;";
802  }
803  }
804  }
805  // normal cases
806  }
807  } else
808  $Attributes .= "&lt;attribute name='" . $column . "' /&gt;";
809  }
810  }
811  return $Attributes;
812  }
TestParameter($Param, $field)
TestAgreggate($Param)
FormatFetchEntity (   $EntityName)
private

Format Entity Header

Parameters
$EntityNameString
Returns
correct XML for Entity header

Definition at line 743 of file DynamicsCrm.php.

Referenced by RetrieveMultiple().

743  {
744  return " &lt;entity name='" . $EntityName . "'&gt;";
745  }
FormatFetchFilter (   $Filters)
private

Format Filters for request will return a Filter is Type is set else will retun a condition

Parameters
array$Filter
  • basic and req where condition1 and condition2

    array(
  • Condition1=>array
  • Condition2=>array
    )
  • basic or req where condition1 or condition2

    array(
  • 'Type'=>'or'
  • Condition1=>array
  • Condition2=>array
    )
  • multiple occurence and/or can be tricky
    where ((condition1 and condition2) or ((condition5 and condition6)or condition4))

  • array (
  • Type=>'or'
  • 1=>array(
  • 'Type'=>'and'
  • Condition1=>array
  • Condition2=>array
  • )
  • 2=>array(
  • 'Type'=>'or'
  • Condition3=>array(
  • 'Type'=>'and'
  • Condition5=>array
  • Condition6=>array
  • )
  • Condition4=>array
  • )
  • )
    Check FormatCondition for more information about each operator
Returns
correct XML for thoose filters

Definition at line 1121 of file DynamicsCrm.php.

References FormatCondition().

1121  {
1122  $TxtFilter = '';
1123  if (is_array ( $Filters )) {
1124  if (isset ( $Filters ['Type'] )) {
1125  $TxtHead = "&lt;filter type='" . $Filters ['Type'] . "' &gt;";
1126  } else {
1127  $TxtHead = '&lt;filter &gt;';
1128  }
1129  foreach ( $Filters as $Filter ) {
1130  if (isset ( $Filter ['Type'] )) {
1131  $TxtFilter .= $this->FormatFetchFilter ( $Filter );
1132  } else {
1133  if (isset ( $Filter ['Op'] )) {
1134  $TxtFilter .= $this->FormatCondition ( $Filter );
1135  }
1136  }
1137  }
1138  if($TxtFilter!=''){
1139  $TxtFilter=$TxtHead.$TxtFilter.'&lt;/filter &gt;';
1140  return $TxtFilter;
1141  }else return '';
1142  } else return '';
1143 
1144 
1145  }
FormatCondition($Filter)
FormatFetchFilter($Filters)
FormatFetchJoin (   $Joins)
private

Format Join for RetriveMultiple

Parameters
array$Joins
  • array(
  • 1=>array(
  • 'name' => (String) tablename
  • 'from' => join name On 'from'=to
  • 'to' => join name On from='to'
  • 'alias' =>not necessary can be false but aliases will be used when you try to get back ur data meaning $result->alias.data
  • 'type' => Operator
  • 'colums' => array see FormatColumn for detail
  • 'where' => array see FormatFetchFilter for detail
  • 'nested'=> (reproduce the same pattern and will nest a join false or unset if not required)
  • ),
  • 2=>array('name'=>...)
  • )
    if only one join is required u can go directly with no nested array
    </p>
Returns
correct XML for request this condition

Definition at line 1171 of file DynamicsCrm.php.

References FormatFetchAttribute(), and TestParameters().

Referenced by RetrieveMultiple().

1171  {
1172  // so we dont have to make a special statement for only 1 join
1173  $TxtJoin = '';
1174  if (isset ( $Joins ['name'] )) {
1175  $Joins = array (
1176  '1' => $Joins
1177  );
1178  }
1179  foreach ( $Joins as $Join ) {
1180  $this->TestParameters($Join,array('name','from','to','type','columns','where'));
1181  $TxtJoin .= "&lt;link-entity name='" . $Join ['name'] . "' from='" . $Join ['from'] . "' to='" . $Join ['to'] . "' ";
1182  if (! empty ( $Join ['alias'] )){
1183  $TxtJoin .= " alias='" . $Join ['alias'] . "' ";
1184  }
1185  $TxtJoin .= " link-type='" . $Join ['type'] . "' &gt;";
1186  $TxtJoin .= $this->FormatFetchAttribute ( $Join ['columns'] );
1187  if (! empty ( $Join ['nested'] ))
1188  $TxtJoin .= FormatFetchJoin ( $Join );
1189  $TxtJoin .= $this->formatFetchFilter ( $Join ['where'] );
1190  $TxtJoin .= "&lt;/link-entity&gt;";
1191  }
1192  return $TxtJoin;
1193  }
FormatFetchAttribute($Columns)
FormatFetchJoin($Joins)
TestParameters($Param, $Fields)
FormatFetchOrder (   $Orders)
private

Format Order by for the request

Parameters
array$OrderClause order by
  • array(
  • 1=>array(
  • 'Column'=> 'ColumName',
  • 'Order'=>'Asc'
  • ),
  • 2=>array(
  • 'Column'=> 'ColumName2',
  • 'Order'=>'Desc'
  • )..
  • )
Returns
correct XML for this Order by

Definition at line 1064 of file DynamicsCrm.php.

References TestParameters().

Referenced by RetrieveMultiple().

1064  {
1065  $TxtOrder = '';
1066  if (is_array ( $Orders )) {
1067  foreach ( $Orders as $Order ) {
1068  $this->TestParameters ( $Order, array('Column','Order'));
1069  if (isset ( $Order ['Column'] ) && isset ( $Order ['Order'] )) {
1070  $TxtOrder .= "&lt;order attribute='" . $Order ['Column'] . "' descending='";
1071  $TxtOrder .= ($Order ['Order'] == 'Asc') ? 'false' : 'true';
1072  $TxtOrder .= "' /&gt;";
1073  }
1074  }
1075  }
1076  return $TxtOrder;
1077  }
TestParameters($Param, $Fields)
GenerateSoapHeader (   $operation)
private

Generate Header accordingly to the operation chosen

Parameters
string$operationOperation name (wdsl wise)
Returns
array formated Header

Definition at line 1395 of file DynamicsCrm.php.

Referenced by call().

1395  {
1396  $soap_action = 'http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/' . $operation;
1397 
1398  $headers = array (
1399  'Method: POST',
1400  'Connection: Keep-Alive',
1401  'User-Agent: PHP-SOAP-CURL',
1402  'Content-Type: text/xml; charset=utf-8',
1403  'SOAPAction: "' . $soap_action . '"'
1404  );
1405  return $headers;
1406  }
GetAllEntities ( )

This is more of a test function return EVERY SINGLE ENTITY OF CRM never ever run that in production...

Returns
result

Definition at line 484 of file DynamicsCrm.php.

References ExecuteBody().

484  {
485  $Request = '<request i:type="a:RetrieveAllEntitiesRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
486  <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
487  <a:KeyValuePairOfstringanyType>
488  <b:key>EntityFilters</b:key>
489  <b:value i:type="c:EntityFilters" xmlns:c="http://schemas.microsoft.com/xrm/2011/Metadata">Privileges</b:value>
490  </a:KeyValuePairOfstringanyType>
491  <a:KeyValuePairOfstringanyType>
492  <b:key>RetrieveAsIfPublished</b:key>
493  <b:value i:type="c:boolean" xmlns:c="http://www.w3.org/2001/XMLSchema">true</b:value>
494  </a:KeyValuePairOfstringanyType>
495  </a:Parameters>
496  <a:RequestId i:nil="true" />
497  <a:RequestName>RetrieveAllEntities</a:RequestName>
498  </request>
499  ';
500  $Return = $this->ExecuteBody ( $Request );
501  return $Return;
502  }
ExecuteBody($Request)
GetCurrentUserInfo ( )

As It sounds will return the Logged in CRM user (login pwd wise)

Returns
object

Definition at line 616 of file DynamicsCrm.php.

References ExecuteBody(), and ParseDatas().

616  {
617  $Request = '<request i:type="b:WhoAmIRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
618  <a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
619  <a:RequestId i:nil="true" />
620  <a:RequestName>WhoAmI</a:RequestName>
621  </request>';
622 
623  $Return = $this->ExecuteBody ( $Request );
624  $Return = $this->ParseDatas ( $Return->Result->Body->ExecuteResponse->ExecuteResult->Results, $Return );
625  return $Return;
626  }
ParseDatas($Datas, $Return)
ExecuteBody($Request)
GetErrorObject (   $message)
private
Parameters
unknown$message
Returns
CrmResponse

Definition at line 1012 of file DynamicsCrm.php.

Referenced by Create(), RetrieveMultiple(), SetState(), and Update().

1012  {
1013  $Return = new CrmResponse ();
1014  $Return->Error = True;
1015  $Return->ErrorCode = 0;
1016  $Return->ErrorMessage = $message;
1017  $Return->Result = False;
1018  return $Return;
1019  }
Result object for DynamicCRM.
Definition: CrmResponse.php:36
getPassword ( )
Returns
Dynamics CRM connection's password

Definition at line 175 of file DynamicsCrm.php.

References $password.

175  {
176  return $this->password;
177  }
getServAdress ( )
Returns
Dynamics CRM connection's Url to service

Definition at line 138 of file DynamicsCrm.php.

References $serv_adress.

138  {
139  return $this->serv_adress;
140  }
getUser ( )
Returns
Dynamics CRM connection's user

Definition at line 156 of file DynamicsCrm.php.

References $user.

156  {
157  return $this->user;
158  }
ParseDatas (   $Datas,
  $Return 
)
private

Parse the datas and update the object accordingly

Parameters
$xmlSimpleXml to be parsed
ObjectCrmResponse
Returns
Object CrmResponse

Definition at line 1290 of file DynamicsCrm.php.

References ParseResultLine().

Referenced by GetCurrentUserInfo(), ParseRetrieve(), ParseRetrieveMultiple(), and Workflow().

1290  {
1291  $NbResults = 0;
1292  $Results = array ();
1293  foreach ( $Datas as $Data ) {
1294  $ResultLine = $this->ParseResultLine ( $Data );
1295  $Results [$NbResults] = $ResultLine;
1296  $NbResults ++;
1297  }
1298  $Return->NbResult = $NbResults;
1299  $Return->Result = $Results;
1300  return $Return;
1301  }
ParseResultLine($Data)
ParseKeyPair (   $data)
private
Parameters
unknown$data
Returns
number|boolean|Ambigous <string, multitype:string , multitype:stdClass >|Ambigous <multitype:string , string, multitype:stdClass >

Definition at line 1336 of file DynamicsCrm.php.

References if(), and ParseResultLine().

Referenced by ParseResultLine().

1336  {
1337  // liason simple
1338  if (isset ( $data->value->Value )) {
1339  $value = ( string ) $data->value->Value;
1340  // entité logique
1341  } else if (isset ( $data->value->LogicalName )) {
1342  $value = array (
1343  'id' => ( string ) $data->value->Id,
1344  'logicalname' => ( string ) $data->value->LogicalName,
1345  'name' => ( string ) $data->value->Name
1346  );
1347  } else if (isset ( $data->value->Entities )) {
1348  $Entities = array ();
1349  foreach ( $data->value->Entities as $entity ) {
1350  if (isset ( $entity->Entity->Attributes )) {
1351  $Entities [] = $this->ParseResultLine ( $entity->Entity );
1352  }
1353  }
1354 
1355  $value = $Entities;
1356  } else
1357  $value = ( string ) $data->value;
1358 
1359  if (! is_array ( $value )) {
1360  if (ctype_digit ( $value )) {
1361  return ( int ) $value;
1362  } else if (is_float ( $value )) {
1363  return ( float ) $value;
1364  } else if (is_bool ( $value )) {
1365  return ( bool ) $value;
1366  } else
1367  return $value;
1368  } else
1369  return $value;
1370  }
if(!b.support.opacity)
Definition: jquery.js:28
ParseResultLine($Data)
ParseResultLine (   $Data)
private

Parse the result of a ResultLine (will be used for both Retrieve and RetrieveMultiple)

Parameters
$DataSimpleXml Entity to be parsed
Returns
stdClass with correct Key/value for the resul line

Definition at line 1311 of file DynamicsCrm.php.

References ParseKeyPair().

Referenced by ParseDatas(), and ParseKeyPair().

1311  {
1312  $ResultLine = new \stdClass ();
1313  if (isset ( $Data->Attributes )) {
1314  foreach ( $Data->Attributes as $keypair ) {
1315  foreach ( $keypair->KeyValuePairOfstringanyType as $data ) {
1316  $key = str_ireplace ( '.', '_', $data->key );
1317  $ResultLine->$key = $this->ParseKeyPair ( $data );
1318  }
1319  }
1320  } else {
1321 
1322  foreach ( $Data as $data ) {
1323  if (isset ( $data->key )) {
1324  $key = str_ireplace ( '.', '_', $data->key );
1325  $ResultLine->$key = $this->ParseKeyPair ( $data );
1326  }
1327  }
1328  }
1329  return $ResultLine;
1330  }
ParseKeyPair($data)
ParseRetrieve (   $xml,
  $Return 
)
private

Parse the result of a Retrieve Query

Parameters
$xmlSimpleXml to be parsed
ObjectCrmResponse
Returns
Object CrmResponse

Definition at line 1381 of file DynamicsCrm.php.

References ParseDatas().

Referenced by call().

1381  {
1382  $Datas = $xml->Body->RetrieveResponse->RetrieveResult;
1383  $Return = $this->ParseDatas ( $Datas, $Return );
1384  $Return->Result = $Return->Result [0];
1385  return $Return;
1386  }
ParseDatas($Datas, $Return)
ParseRetrieveMultiple (   $xml,
  $Return 
)
private

Parse the result of a RetrieveMultiple Query

Parameters
$xmlSimpleXml to be parsed
ObjectCrmResponse
Returns
Object CrmResponse

Definition at line 1275 of file DynamicsCrm.php.

References ParseDatas().

Referenced by call().

1275  {
1276  $Datas = $xml->Body->RetrieveMultipleResponse->RetrieveMultipleResult->Entities->Entity; // ->retrievemultipleresponse;//->retrievemultipleresult->entities->entity;
1277  $Return = $this->ParseDatas ( $Datas, $Return );
1278  return $Return;
1279  }
ParseDatas($Datas, $Return)
Retrieve (   $Table,
  $Id,
  $Columns 
)

Retrieve ONE and ONLY ONE Line in CRM By ID

See also
DynamicsCrm::FormatFilter() For a better understanding of where clause
Parameters
string$Idmostly a GUID from the id column (key)
string$TableTable name
array$Columnslist of columns to be shown , false to see all

array ('col1','col2',...)

Returns
Object CrmResponse
  • Bool $Error,
  • String $ErrorCode,
  • String $ErrorMessage,
  • $Result => false or std object with key parameter

Definition at line 207 of file DynamicsCrm.php.

References call(), and FormatColumn().

207  {
208 
209  // build Saop Enveloppe
210  $SoapEnvelope = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:con="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
211  <soap:Body>
212  <ser:Retrieve>
213  <ser:entityName>' . $Table . '</ser:entityName>
214  <ser:id>' . $Id . '</ser:id>';
215  $SoapEnvelope .= $this->FormatColumn ( $Columns );
216  $SoapEnvelope .= '</ser:Retrieve>
217  </soap:Body>
218  </soap:Envelope>';
219 
220  // call
221  Return $this->call ( 'Retrieve', $SoapEnvelope );
222  }
call($operation, $soapBody)
FormatColumn($Columns)
RetrieveMultiple (   $Table,
  $Where,
  $Columns = false,
  $Join = false,
  $Order = false 
)

Retrieve Multiple Lines in CRM

See also
FormatFilter For a better understanding of where clause
Parameters
array$Wheredetail of $Where attribute
array$Columnsdetail of $Columns attribute
array$Orderwill change order of results

array(
1=>('Column'=> 'Colname','Order'=>'Asc'),
2=>('Column'=> 'Colname2','Order'=>'Desc'),
...);

Returns
object CrmResponse.
  • Bool $Error,
  • String $ErrorCode,
  • String $ErrorMessage,
  • $Result => false or array of std object with key parameter,

Definition at line 249 of file DynamicsCrm.php.

References $Aggregate, array_key_exists_r(), call(), FormatFetchAttribute(), FormatFetchEntity(), FormatFetchJoin(), FormatFetchOrder(), and GetErrorObject().

249  {
250  // check if there is some agregate inside parameter
251  if (is_array ( $Columns )) {
252  if ($this->array_key_exists_r ( 'aggregate', $Columns ) || $this->array_key_exists_r ( 'groupby', $Columns )) {
253  $Aggregate = 'true';
254  } else
255  $Aggregate = 'false';
256  } else
257  $Aggregate = 'false';
258  // build Soap Enveloppe
259  try {
260  $Entity = $this->FormatFetchEntity ( $Table );
261  $Attributes = $this->FormatFetchAttribute ( $Columns );
262  $Order = $this->FormatFetchOrder ( $Order );
263  $Filter = $this->formatFetchFilter ( $Where );
264  if ($Join !== false){
265  $Join = $this->FormatFetchJoin ( $Join );
266  }else $Join='';
267  } catch ( Exception $e ) {
268  return $this->GetErrorObject ( $e->getMessage () );
269  }
270 
271  $SoapEnvelope = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
272  <s:Body>
273  <RetrieveMultiple xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
274  <query i:type="a:FetchExpression" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
275  <a:Query>
276  &lt;fetch version=\'1.0\' output-format=\'xml-platform\' mapping=\'logical\' aggregate=\'' . $Aggregate . '\' distinct=\'false\'&gt;';
277  $SoapEnvelope.=$Entity.$Attributes.$Order.$Filter.$Join;
278 
279  // add footer
280  $SoapEnvelope .= '&lt;/entity&gt;
281  &lt;/fetch&gt;
282  </a:Query>
283  </query>
284  </RetrieveMultiple>
285  </s:Body>
286  </s:Envelope>
287  ';
288 
289  // call
290  Return $this->call ( 'RetrieveMultiple', $SoapEnvelope );
291  }
array_key_exists_r($needle, $haystack)
FormatFetchAttribute($Columns)
call($operation, $soapBody)
GetErrorObject($message)
FormatFetchJoin($Joins)
FormatFetchOrder($Orders)
FormatFetchEntity($EntityName)
setPassword (   $password)
Parameters
string$passwordDynamics CRM connection's password

Definition at line 184 of file DynamicsCrm.php.

References $password.

Referenced by __construct().

184  {
185  $this->password = $password;
186  return $this;
187  }
setServAdress (   $serv_adress)
Parameters
string$serv_adressDynamics CRM connection's Url to service

Definition at line 147 of file DynamicsCrm.php.

References $serv_adress.

Referenced by __construct().

147  {
148  $this->serv_adress = $serv_adress;
149  return $this;
150  }
SetState (   $Id,
  $Table,
  $StateCode,
  $StatusCode 
)

Set state for a newly created object (can't be done in create)

Parameters
string$Id

the GUID of the entity you want to update

Parameters
string$Table

the table where you want to create a new row

Parameters
string$StateCodeState Code depending on Table
string$StatusCodeStatus Code depending on State Code
Returns
result|CrmResponse

Definition at line 443 of file DynamicsCrm.php.

References ExecuteBody(), and GetErrorObject().

443  {
444  if (isset ( $this->StateCheck [$Table] [$StateCode] ) && in_array ( $StatusCode, $this->StateCheck [$Table] [$StateCode] )) {
445 
446  $Request = '<request i:type="b:SetStateRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
447  <a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
448  <a:KeyValuePairOfstringanyType>
449  <c:key>EntityMoniker</c:key>
450  <c:value i:type="a:EntityReference">
451  <a:Id>' . $Id . '</a:Id>
452  <a:LogicalName>' . $Table . '</a:LogicalName>
453  <a:Name i:nil="true" />
454  </c:value>
455  </a:KeyValuePairOfstringanyType>
456  <a:KeyValuePairOfstringanyType>
457  <c:key>State</c:key>
458  <c:value i:type="a:OptionSetValue">
459  <a:Value>' . $StateCode . '</a:Value>
460  </c:value>
461  </a:KeyValuePairOfstringanyType>
462  <a:KeyValuePairOfstringanyType>
463  <c:key>Status</c:key>
464  <c:value i:type="a:OptionSetValue">
465  <a:Value>' . $StatusCode . '</a:Value>
466  </c:value>
467  </a:KeyValuePairOfstringanyType></a:Parameters>
468  <a:RequestId i:nil="true" />
469  <a:RequestName>SetState</a:RequestName>
470  </request>';
471  return $this->ExecuteBody ( $Request );
472  } else {
473  $strPair = print_r ( $this->StateCheck [$Table], true );
474  return $this->GetErrorObject ( 'Pair State and status not avaible for ' . $Table . ' should be in State => array( avaible status) : ' . $strPair );
475  }
476  }
GetErrorObject($message)
ExecuteBody($Request)
setUser (   $user)
Parameters
string$userDynamics CRM connection's User

(LDAP) Domain/user

Definition at line 166 of file DynamicsCrm.php.

References $user.

Referenced by __construct().

166  {
167  $this->user = $user;
168  return $this;
169  }
TestAgreggate (   $Param)
private
Parameters
unknown$Param
Exceptions
InvalidArgumentException

Definition at line 1001 of file DynamicsCrm.php.

Referenced by FormatFetchAttribute().

1001  {
1002  if (! in_array ( $Param, $this->Aggregate )) {
1003  $AggregateValue = print_r ( $this->Aggregate, true );
1004  throw new \InvalidArgumentException ( sprintf ( "Aggregate Invalid should be in : $AggregateValue" ) );
1005  }
1006  }
TestParameter (   $Param,
  $field 
)
private
Parameters
unknown$Param
unknown$field
Exceptions
InvalidArgumentException

Definition at line 990 of file DynamicsCrm.php.

Referenced by FormatAttribute(), FormatFetchAttribute(), and TestParameters().

990  {
991  if (! isset ( $Param [$field] )) {
992  $strArray = print_r ( $Param, true );
993  throw new \InvalidArgumentException ( sprintf ( "Missing Parameter $field for array : $strArray" ) );
994  }
995  }
TestParameters (   $Param,
  $Fields 
)
private
Parameters
unknown$Param
unknown$Fields

Definition at line 979 of file DynamicsCrm.php.

References TestParameter().

Referenced by FormatAttribute(), FormatCondition(), FormatFetchJoin(), and FormatFetchOrder().

979  {
980  foreach ( $Fields as $Field ) {
981  $this->TestParameter ( $Param, $Field );
982  }
983  }
TestParameter($Param, $field)
Update (   $Table,
  $Params,
  $Id 
)

Update a row in CRM

Parameters
string$Table

the table name where you want to insert a row

Parameters
string$Idmostly a GUID from the id column (key) too see the dif operator
array$Params

'ColumnName' => Value

Returns
obj CrmResponse.
  • Bool $Error,
  • String $ErrorCode,
  • String $ErrorMessage,
  • $Result => true or false...

Definition at line 348 of file DynamicsCrm.php.

References call(), FormatAttributes(), and GetErrorObject().

348  {
349  // check the array parameter first
350  try {
351  $Param = $this->FormatAttributes ( $Params );
352  } catch ( Exception $e ) {
353  return $this->GetErrorObject ( $e->getMessage () );
354  }
355  // build soap Enveloppe
356  $SoapEnvelope = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
357  <soap:Body><Update xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
358  <entity xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
359  <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
360  ' . $Param . '
361  </b:Attributes>
362  <b:EntityState i:nil="true"/>
363  <b:FormattedValues xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
364  <b:Id>' . $Id . '</b:Id>
365  <b:LogicalName>' . $Table . '</b:LogicalName>
366  <b:RelatedEntities xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
367  </entity></Update>
368  </soap:Body>
369  </soap:Envelope>';
370  // call
371  return $this->call ( 'Update', $SoapEnvelope );
372  }
call($operation, $soapBody)
GetErrorObject($message)
FormatAttributes($Params)
Workflow (   $EntityId,
  $WorkflowId 
)

Will run a workflow accordingly to the parameters

Parameters
string$EntityId

the GUID of the entity you want to run

Parameters
string$WorkflowId

the GUID of the Workflow you want to run

Returns
result

Definition at line 515 of file DynamicsCrm.php.

References ExecuteBody(), and ParseDatas().

515  {
516  $Request = '<request i:type="b:ExecuteWorkflowRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
517  <a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
518  <a:KeyValuePairOfstringanyType>
519  <c:key>EntityId</c:key>
520  <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">$EntityId</c:value>
521  </a:KeyValuePairOfstringanyType>
522  <a:KeyValuePairOfstringanyType>
523  <c:key>WorkflowId</c:key>
524  <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">$WorkflowId</c:value>
525  </a:KeyValuePairOfstringanyType>
526  </a:Parameters>
527  <a:RequestId i:nil="true" />
528  <a:RequestName>ExecuteWorkflow</a:RequestName>
529  </request>';
530  $Return = $this->ExecuteBody ( $Request );
531  $Return = $this->ParseDatas ( $Return->Result->Body->ExecuteResponse->ExecuteResult->Results, $Return );
532  return $this->ExecuteBody ( $Request );
533  }
ParseDatas($Datas, $Return)
ExecuteBody($Request)

Field Documentation

$Aggregate = array ('avg','max','min','sum','count','countcolumn','countdistinct')
private

Definition at line 103 of file DynamicsCrm.php.

Referenced by RetrieveMultiple().

$Operator
private
Initial value:
= array(
'0'=>array('eq-userid','ne-userid','eq-bysinessid','ne-bysinessid',
'eq-userteams','last-seven-days','last-fiscal-period','last-fiscal-year','last-month',
'last-week','last-year','next-seven-days','next-fiscal-period','next-fiscal-year','next-month','next-week',
'next-year','null','this-fiscal-period','this-fiscal-year','this-month','this-week','this-year','today','not-null','tomorrow','yesterday') ,
'1'=>array('like','not-like','eq','ge','gt','le','lt','ne','on','on-or-after','on-or-before',
'in-fiscal-period','in-fiscal-year','last-x-days','last-x-fiscal-periods','last-x-fiscal-years','last-x-hours',
'last-x-months','last-x-weeks','last-x-years','next-x-days','next-x-fiscal-periods','next-x-fiscal-years',
'next-x-hours','next-x-months','next-x-weeks','next-x-years','olderthan-x-months') ,
'2'=> array('not-in','in'),
'3'=> array('between','not-between','in-fiscal-period-and-year','in-or-after-fiscal-period-and-year','in-or-before-fiscal-period-and-year')
)

Definition at line 104 of file DynamicsCrm.php.

$password

Definition at line 71 of file DynamicsCrm.php.

Referenced by getPassword(), and setPassword().

$serv_adress

Definition at line 69 of file DynamicsCrm.php.

Referenced by getServAdress(), and setServAdress().

$StateCheck
private

Definition at line 72 of file DynamicsCrm.php.

$user

Definition at line 70 of file DynamicsCrm.php.

Referenced by getUser(), and setUser().


The documentation for this class was generated from the following file: