Skip to content

Commit

Permalink
new method getSearchRecordsByPDC
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianpontes committed Mar 13, 2017
1 parent a15057d commit bf47485
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Request/GetRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function configureRequest()
* Column names to select i.e, ['Last Name', 'Website', 'Email']
* When not set defaults to all columns
*
* @param array $columns
* @param array|string $columns
* @return GetRecords
*/
public function selectColumns($columns)
Expand Down
106 changes: 106 additions & 0 deletions Request/GetSearchRecordsByPDC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
namespace CristianPontes\ZohoCRMClient\Request;
use CristianPontes\ZohoCRMClient\Response\Record;

/**
* GetRelatedRecords API Call
*
* You can use the getRelatedRecords method to fetch related records
*
* @see https://www.zoho.com/crm/help/api/getrelatedrecords.html
*/
class GetSearchRecordsByPDC extends AbstractRequest
{

protected function configureRequest()
{
$this->request
->setMethod('getRelatedRecords')
->setParam('newFormat', '1')
->setParam('selectColumns', 'All');
}

/**
* @param int $index
* @return GetSearchRecordsByPDC
*/
public function fromIndex($index)
{
$this->request->setParam('fromIndex', (int) $index);
return $this;
}

/**
* @param int $index
* @return GetSearchRecordsByPDC
*/
public function toIndex($index)
{
$this->request->setParam('toIndex', (int) $index);
return $this;
}

/**
* Column names to select i.e, ['Last Name', 'Website', 'Email']
* When not set defaults to all columns
*
* @param array|string $columns
* @return GetSearchRecordsByPDC
*/
public function selectColumns($columns)
{
if (!is_array($columns)) {
$columns = func_get_args();
}
$this->request->setParam(
'selectColumns',
$this->request->getModule() . '(' . implode(',', $columns) . ')'
);
return $this;
}

/**
* Include the empty fields in the response.
*
* @return GetSearchRecordsByPDC
*/
public function withEmptyFields()
{
$this->request->setParam('newFormat', "2");
return $this;
}

/**
* Specify the predefined search column
* @see https://www.zoho.com/crm/help/api/getsearchrecordsbypdc.html#Default_Predefined_Columns
*
* @param $column string
* @return GetSearchRecordsByPDC
*/
public function searchColumn($column)
{
$this->request->setParam('searchColumn', $column);
return $this;
}

/**
* Specify the value to be searched
*
* @param $value string
* @return GetSearchRecordsByPDC
*/
public function searchValue($value)
{
$this->request->setParam('searchValue', $value);
return $this;
}

/**
* @return Record[]
*/
public function request()
{
return $this->request
->request();
}
}
65 changes: 65 additions & 0 deletions Tests/Request/GetSearchRecordsByPDCTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
namespace CristianPontes\ZohoCRMClient\Tests\Request;

use CristianPontes\ZohoCRMClient\Request;
use CristianPontes\ZohoCRMClient\Transport\TransportRequest;

class GetSearchRecordsByPDCTest extends \PHPUnit_Framework_TestCase
{
/** @var TransportRequest */
private $request;
/** @var Request\GetSearchRecordsByPDC */
private $getSearchRecordsByPDC;

public function testFromIndex()
{
$this->getSearchRecordsByPDC->fromIndex(10);

$this->assertEquals(10, $this->request->getParam('fromIndex'));
}

public function testToIndex()
{
$this->getSearchRecordsByPDC->toIndex(-10);

$this->assertEquals(-10, $this->request->getParam('toIndex'));
}

public function testWithEmptyFields()
{
$this->getSearchRecordsByPDC->withEmptyFields();
$this->assertEquals(
'2',
$this->request->getParam('newFormat')
);
}

public function testSelectColumns()
{
$key = 'selectColumns';

$this->assertEquals('All', $this->request->getParam($key));

$this->getSearchRecordsByPDC->selectColumns('Last Name', 'Email');

$this->assertEquals('SomeModuleName(Last Name,Email)', $this->request->getParam($key));
}

public function testSearchValue()
{
$this->getSearchRecordsByPDC->searchValue('123');
$this->assertEquals('123', $this->request->getParam('searchValue'));
}

public function testSearchColumn()
{
$this->getSearchRecordsByPDC->searchColumn('SomeColumn');
$this->assertEquals('SomeColumn', $this->request->getParam('searchColumn'));
}

protected function setUp()
{
$this->request = new TransportRequest('SomeModuleName');
$this->getSearchRecordsByPDC = new Request\GetSearchRecordsByPDC($this->request);
}
}
8 changes: 8 additions & 0 deletions ZohoCRMClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ public function searchRecords()
return new Request\SearchRecords($this->request());
}

/**
* @return Request\GetSearchRecordsByPDC
*/
public function getSearchRecordsByPDC()
{
return new Request\GetSearchRecordsByPDC($this->request());
}

/**
* @return Request\GetRelatedRecords
*/
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"psr/log": "~1.0.0"
},
"require-dev":{
"phpunit/phpunit": "3.7.*"
"phpunit/phpunit": "4.8.*"
},
"autoload": {
"psr-0": {"CristianPontes\\ZohoCRMClient": ""}
Expand Down

0 comments on commit bf47485

Please sign in to comment.