-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a15057d
commit bf47485
Showing
5 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters