public function request($requestType) { switch (strtolower($requestType)) { case "create": SoapRequestsGenerator::generateCreateRequest($entity); break; case "update": break; case "delete": break; case "retrievemetadatachanges": break; case "retrieve": break; case "retrieveorganization": break; case "retrievemultiple": break; case "retrieveentity": break; case "executeaction": break; } }
/** * Send a Create request to the Dynamics CRM server, and return the ID of the newly created Entity * * @param Entity $entity the Entity to create * * @return string|bool EntityId on success, FALSE on failure * @throws Exception */ public function create(Entity &$entity) { $this->purgeEntityCache($entity->logicalName); /* Only allow "Create" for an Entity with no ID */ if ($entity->ID != self::EmptyGUID) { throw new Exception('Cannot Create an Entity that already exists.'); } /* Send the security request and get a security token */ $securityToken = $this->authentication->getOrganizationSecurityToken(); /* Generate the XML for the Body of a Create request */ $createNode = SoapRequestsGenerator::generateCreateRequest($entity); $this->logger->debug('Executing Create request', ['request' => $createNode->C14N()]); /* Turn this into a SOAP request, and send it */ $createRequest = $this->generateSoapRequest($this->settings->organizationUrl, $this->soapActions->getSoapAction('organization', 'Create'), $securityToken, $createNode); $soapResponse = self::getSoapResponse($this->settings->organizationUrl, $createRequest); $this->logger->debug('Finished executing Create request', ['response' => $soapResponse]); /* Load the XML into a DOMDocument */ $soapResponseDOM = new DOMDocument(); $soapResponseDOM->loadXML($soapResponse); /* Find the CreateResponse */ $createResponseNode = null; foreach ($soapResponseDOM->getElementsByTagName('CreateResponse') as $node) { $createResponseNode = $node; break; } unset($node); if ($createResponseNode == null) { throw new Exception('Could not find CreateResponse node in XML returned from Server'); } /* Get the EntityID from the CreateResult tag */ $entityID = $createResponseNode->getElementsByTagName('CreateResult')->item(0)->textContent; $entity->ID = $entityID; $entity->reset(); return $entityID; }