Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds CountRecords functionality. #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/com/zoho/crm/api/record/CountHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace com\zoho\crm\api\record;

interface CountHandler
{

}
28 changes: 28 additions & 0 deletions src/com/zoho/crm/api/record/CountWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace com\zoho\crm\api\record;

use com\zoho\crm\api\util\Model;

class CountWrapper implements Model, CountHandler
{

private $count;

/**
* The method to get the data
* @return int Count of Records
*/
public function getCount()
{
return $this->count;
}

/**
* The method to set the count
* @param int $count Count
*/
public function setCount(int $count)
{
$this->count=$count;
}
}
30 changes: 26 additions & 4 deletions src/com/zoho/crm/api/record/RecordOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,33 @@ public function searchRecords(string $moduleAPIName, ParameterMap $paramInstanc
$handlerInstance->setHttpMethod(Constants::REQUEST_METHOD_GET);
$handlerInstance->setCategoryMethod(Constants::REQUEST_CATEGORY_READ);
$handlerInstance->setParam($paramInstance);
$handlerInstance->setHeader($headerInstance);
Utility::getFields($moduleAPIName);
$handlerInstance->setModuleAPIName($moduleAPIName);
return $handlerInstance->apiCall(ResponseHandler::class, 'application/json');
Utility::getFields($moduleAPIName);
$handlerInstance->setHeader($headerInstance);
$handlerInstance->setModuleAPIName($moduleAPIName);
return $handlerInstance->apiCall(ResponseHandler::class, 'application/json');

}

/**
* The method to count records
* @param string $moduleAPIName A string
* @param ParameterMap $paramInstance An instance of ParameterMap
* @return APIResponse An instance of APIResponse
*/
public function countRecords(string $moduleAPIName, ParameterMap $paramInstance=null)
{
$handlerInstance=new CommonAPIHandler();
$apiPath="";
$apiPath=$apiPath.('/crm/v2.1/');
$apiPath=$apiPath.(strval($moduleAPIName));
$apiPath=$apiPath.('/actions/count');
$handlerInstance->setAPIPath($apiPath);
$handlerInstance->setHttpMethod(Constants::REQUEST_METHOD_GET);
$handlerInstance->setCategoryMethod(Constants::REQUEST_CATEGORY_READ);
$handlerInstance->setParam($paramInstance);
Utility::getFields($moduleAPIName);
$handlerInstance->setModuleAPIName($moduleAPIName);
return $handlerInstance->apiCall(CountHandler::class, 'application/json');
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/com/zoho/crm/api/util/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ class Constants

const MODULE_RESPONSEWRAPPER = "com\zoho\crm\api\modules\ResponseWrapper";

const MODULE_COUNTWRAPPER = "com\zoho\crm\api\modules\CountWrapper";

const MODULE_API_EXCEPTION = "com\zoho\crm\api\modules\APIException";

const JSON_DETAILS_FILE_PATH = "src/resources/JSONDetails.json";
Expand Down
2 changes: 1 addition & 1 deletion src/com/zoho/crm/api/util/JSONConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ public function findRatio($className, $responseJson)
$keyName = $memberDetail[Constants::NAME];
}

if ($keyName != null && array_key_exists($keyName, $responseJson) && (is_array($responseJson[$keyName]) || $responseJson[$keyName] != null))
if ($keyName != null && array_key_exists($keyName, $responseJson) && (is_array($responseJson[$keyName]) || $responseJson[$keyName] !== null))
{
$keyData = $responseJson[$keyName];

Expand Down
2 changes: 1 addition & 1 deletion src/resources/JSONDetails.json

Large diffs are not rendered by default.