diff --git a/Request/UpdateRelatedRecords.php b/Request/UpdateRelatedRecords.php
new file mode 100644
index 0000000..c60cd62
--- /dev/null
+++ b/Request/UpdateRelatedRecords.php
@@ -0,0 +1,88 @@
+request
+ ->setMethod('updateRelatedRecords')
+ ->setParam('version', 4);
+ }
+
+ /**
+ * @param array $record Record as a simple associative array
+ * @return UpdateRelatedRecords
+ */
+ public function addRecord(array $record)
+ {
+ $this->records[] = $record;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getRecords()
+ {
+ return $this->records;
+ }
+
+ /**
+ * @param array $records array containing records otherwise added by addRecord()
+ * @return UpdateRelatedRecords
+ */
+ public function setRecords(array $records)
+ {
+ $this->records = $records;
+ return $this;
+ }
+
+ /**
+ * The ID of the record to be updated.
+ * @param $id
+ * @return UpdateRelatedRecords
+ */
+ public function id($id)
+ {
+ $this->request->setParam('id', $id);
+ return $this;
+ }
+
+ /**
+ * The module to which a record is related.
+ * i.e: If a lead related to a campaign needs to be updated, the value for this parameter will be Leads.
+ * @param $module
+ * @return UpdateRelatedRecords
+ */
+ public function relatedModule($module)
+ {
+ $this->request->setParam('relatedModule', $module);
+ return $this;
+ }
+
+ /**
+ * @return MutationResult[]
+ */
+ public function request()
+ {
+ return $this->request
+ ->setParam('xmlData', $this->records)
+ ->request();
+ }
+}
diff --git a/Tests/Request/UpdateRelatedRecordsTest.php b/Tests/Request/UpdateRelatedRecordsTest.php
new file mode 100644
index 0000000..4d17469
--- /dev/null
+++ b/Tests/Request/UpdateRelatedRecordsTest.php
@@ -0,0 +1,68 @@
+transport = new MockTransport();
+ $this->request = new TransportRequest('Products');
+ $this->request->setTransport($this->transport);
+ $this->updateRelatedRecords = new Request\UpdateRelatedRecords($this->request);
+ }
+
+ public function testInitial()
+ {
+ $this->assertEquals('updateRelatedRecords', $this->request->getMethod());
+ $this->assertEquals(
+ 4,
+ $this->request->getParam('version')
+ );
+ }
+
+ public function testRecords()
+ {
+ $record = array(
+ 'PRODUCTID' => '508020000000061987',
+ 'list_price' => '100.00'
+ );
+
+ $this->updateRelatedRecords->addRecord($record);
+
+ $this->transport->response = true;
+
+ $this->assertTrue($this->updateRelatedRecords->request());
+ $this->assertEquals(array('version' => 4, 'xmlData' => array($record)), $this->transport->paramList);
+ }
+
+ public function testRelatedModule()
+ {
+ $this->updateRelatedRecords->relatedModule('Leads');
+ $this->assertEquals(
+ 'Leads',
+ $this->request->getParam('relatedModule')
+ );
+ }
+
+ public function testId()
+ {
+ $this->updateRelatedRecords->id('123');
+ $this->assertEquals(
+ 123,
+ $this->request->getParam('id')
+ );
+ }
+}
diff --git a/Tests/ZohoCRMClientTest.php b/Tests/ZohoCRMClientTest.php
index dd3f850..91d7398 100644
--- a/Tests/ZohoCRMClientTest.php
+++ b/Tests/ZohoCRMClientTest.php
@@ -54,6 +54,34 @@ public function testUpdateRecords()
$this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\UpdateRecords', $request);
}
+ public function testUpdateRelatedRecords()
+ {
+ $request = $this->client->updateRelatedRecords();
+
+ $this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\UpdateRelatedRecords', $request);
+ }
+
+ public function testSearchRecords()
+ {
+ $request = $this->client->searchRecords();
+
+ $this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\SearchRecords', $request);
+ }
+
+ public function testGetSearchRecordsByPDC()
+ {
+ $request = $this->client->getSearchRecordsByPDC();
+
+ $this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\GetSearchRecordsByPDC', $request);
+ }
+
+ public function testConvertLead()
+ {
+ $request = $this->client->ConvertLead();
+
+ $this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\ConvertLead', $request);
+ }
+
public function testGetFields()
{
$request = $this->client->getFields();
@@ -68,6 +96,13 @@ public function testDeleteRecords()
$this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\DeleteRecords', $request);
}
+ public function testGetDeletedRecordIds()
+ {
+ $request = $this->client->getDeletedRecordIds();
+
+ $this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\GetDeletedRecordIds', $request);
+ }
+
public function testUploadFile()
{
$request = $this->client->uploadFile();
@@ -75,6 +110,20 @@ public function testUploadFile()
$this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\UploadFile', $request);
}
+ public function testDownloadFile()
+ {
+ $request = $this->client->downloadFile();
+
+ $this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\DownloadFile', $request);
+ }
+
+ public function testDeleteFile()
+ {
+ $request = $this->client->deleteFile();
+
+ $this->assertInstanceOf('CristianPontes\ZohoCRMClient\Request\DeleteFile', $request);
+ }
+
public function testRequest()
{
$request = $this->client->publicRequest();
diff --git a/Transport/Transport.php b/Transport/Transport.php
index 993b828..254de05 100644
--- a/Transport/Transport.php
+++ b/Transport/Transport.php
@@ -10,7 +10,7 @@ interface Transport
* @param string $module
* @param string $method
* @param array $paramList
- * @return array
+ * @return string
*/
public function call($module, $method, array $paramList);
}
\ No newline at end of file
diff --git a/Transport/XmlDataTransportDecorator.php b/Transport/XmlDataTransportDecorator.php
index b37ecf3..caef284 100644
--- a/Transport/XmlDataTransportDecorator.php
+++ b/Transport/XmlDataTransportDecorator.php
@@ -17,7 +17,7 @@ class XmlDataTransportDecorator extends AbstractTransportDecorator
private $module;
/** @var string */
private $method;
- /** @var string */
+ /** @var array */
private $call_params;
@@ -62,6 +62,7 @@ public function call($module, $method, array $paramList)
private function encodeRequestConvertLead(array $paramList)
{
$root = new SimpleXMLElement('');
+ $options = array();
// row 1 (options)
foreach (ConvertLead::getOptionFields() as $optionName) {
@@ -87,14 +88,15 @@ private function encodeRequestConvertLead(array $paramList)
/**
* @param array $records
- * @param string $rootName
- * @param array $options
* @throws \CristianPontes\ZohoCRMClient\Exception\RuntimeException
* @return string XML representation of the records
*/
private function encodeRecords(array $records)
{
- $root = new SimpleXMLElement('<'.$this->module.'>'.$this->module.'>');
+ $module = $this->method == 'updateRelatedRecords' ?
+ $this->call_params['relatedModule'] : $this->module;
+
+ $root = new SimpleXMLElement('<'.$module.'>'.$module.'>');
foreach ($records as $no => $record) {
$row = $root->addChild('row');
@@ -111,7 +113,6 @@ private function encodeRecords(array $records)
* @param array $record
* @param string $childName XML node name
* @param SimpleXMLElement $xml
- * @return string XML representation of the record
*/
private function encodeRecord($record, $childName, &$xml)
{
@@ -140,7 +141,7 @@ private function encodeRecord($record, $childName, &$xml)
/**
* @param $array
- * @param $xml
+ * @param SimpleXMLElement $xml
*/
private function parseNestedValues($array, &$xml)
{
@@ -171,7 +172,7 @@ private function parseNestedValues($array, &$xml)
* @throws Exception\UnexpectedValueException When invalid XML is given to parse
* @throws Exception\NoDataException when Zoho tells us there is no data
* @throws Exception\ZohoErrorException when content is a Error response
- * @return Response\Record[]|Response\Field[]|Response\MutationResult[]
+ * @return bool|Response\Record|Response\Record[]|Response\Field[]|Response\MutationResult
*/
private function parse($content)
{
@@ -222,6 +223,10 @@ private function parse($content)
return $this->parseResponseConvertLead($xml);
}
+ if ($this->method == 'updateRelatedRecords') {
+ return $this->parseUpdateRelatedRecords($xml);
+ }
+
if (isset($xml->result->{$this->module})) {
return $this->parseResponseGetRecords($xml);
}
@@ -251,7 +256,7 @@ private function parseResponseGetRecords(SimpleXMLElement $xml)
* @param SimpleXMLElement $row
* @return Response\Record
*/
- private function rowToRecord(SimpleXMLElement $row)
+ private function rowToRecord($row)
{
$data = array();
foreach($row as $field) {
@@ -271,7 +276,7 @@ private function rowToRecord(SimpleXMLElement $row)
}
/**
- * @param $xml
+ * @param SimpleXMLElement $xml
* @return array
*/
private function parseResponseGetFields($xml)
@@ -304,7 +309,7 @@ private function parseResponseGetFields($xml)
}
/**
- * @param $xml
+ * @param SimpleXMLElement $xml
* @return Response\MutationResult
*/
private function parseResponseDeleteRecords($xml)
@@ -313,7 +318,7 @@ private function parseResponseDeleteRecords($xml)
}
/**
- * @param $xml
+ * @param SimpleXMLElement $xml
* @return Response\MutationResult
*/
private function parseResponseUploadFile($xml)
@@ -330,7 +335,7 @@ private function parseResponseUploadFile($xml)
}
/**
- * @param $xml
+ * @param SimpleXMLElement $xml
* @return Response\MutationResult
*/
private function parseResponseDeleteFile($xml)
@@ -357,7 +362,7 @@ private function parseResponseDownloadFile($file_content)
}
/**
- * @param $xml
+ * @param SimpleXMLElement $xml
* @return Response\Record
*/
private function parseResponseGetDeletedRecordIds($xml)
@@ -367,7 +372,7 @@ private function parseResponseGetDeletedRecordIds($xml)
}
/**
- * @param $xml
+ * @param SimpleXMLElement $xml
* @return array
*/
private function parseResponseConvertLead($xml)
@@ -380,6 +385,23 @@ private function parseResponseConvertLead($xml)
return $records;
}
+ /**
+ * @param SimpleXMLElement $xml
+ * @return Response\Record
+ */
+ private function parseUpdateRelatedRecords($xml)
+ {
+ $result = (array) $xml->result;
+ $added = isset($result['added-ids']) ? eval('return ' . $result['added-ids'] . ';') : [];
+ $updated = isset($result['updated-ids']) ? eval('return ' . $result['updated-ids'] . ';') : [];
+ $data = array(
+ 'added-ids' => $added,
+ 'updated-ids' => $updated
+ );
+ return new Response\Record($data, 1);
+ }
+
+
/**
* @param $xml
* @return array
diff --git a/ZohoCRMClient.php b/ZohoCRMClient.php
index d631d06..983d465 100644
--- a/ZohoCRMClient.php
+++ b/ZohoCRMClient.php
@@ -110,6 +110,15 @@ public function updateRecords()
return new Request\UpdateRecords($this->request());
}
+
+ /**
+ * @return Request\UpdateRelatedRecords
+ */
+ public function updateRelatedRecords()
+ {
+ return new Request\UpdateRelatedRecords($this->request());
+ }
+
/**
* @return Request\ConvertLead
*/
diff --git a/readme.md b/readme.md
index 05d2e52..1b3465c 100644
--- a/readme.md
+++ b/readme.md
@@ -65,9 +65,9 @@ echo "";
+ deleteFile
+ getFields
+ convertLead
++ updateRelatedRecords
## Documentation
-
All the methods previously mentioned are well explained in the [library documentation page](https://cristianpontes.github.io/zoho-crm-client-php/).
-Also, the code are well documented too, so you'll be able to look around the methods, functions and check how them work.
\ No newline at end of file
+Also, the code is well documented too, so you'll be able to look at the methods, functions and check how they work.
\ No newline at end of file