Skip to content

Commit

Permalink
Tags API support provided in SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanthchilka committed Nov 27, 2018
1 parent 71411d1 commit 3ce8de9
Show file tree
Hide file tree
Showing 8 changed files with 795 additions and 8 deletions.
428 changes: 428 additions & 0 deletions src/com/zoho/crm/library/api/handler/TagApiHandler.php

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/com/zoho/crm/library/api/response/APIResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function processResponseData()
if(array_key_exists("data",$responseJSON))
{
$responseJSON=$responseJSON['data'][0];
}
if(array_key_exists("tags",$responseJSON))
{
$responseJSON=$responseJSON['tags'][0];
}
else if(array_key_exists("users",$responseJSON))
{
Expand Down
20 changes: 16 additions & 4 deletions src/com/zoho/crm/library/api/response/BulkAPIResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,24 @@ public function processResponseData()
$recordsArray = $bulkResponseJSON[APIConstants::DATA];
foreach ($recordsArray as $record)
{
if($record!=null && array_key_exists(APIConstants::STATUS,$record))
{
array_push($this->bulkEntitiesResponse,new EntityResponse($record));
}
if($record!=null && array_key_exists(APIConstants::STATUS,$record))
{
array_push($this->bulkEntitiesResponse,new EntityResponse($record));
}
}
}
if(array_key_exists(APIConstants::TAGS,$bulkResponseJSON))
{
$recordsArray = $bulkResponseJSON[APIConstants::TAGS];
foreach ($recordsArray as $record)
{
if($record!=null && array_key_exists(APIConstants::STATUS,$record))
{
array_push($this->bulkEntitiesResponse,new EntityResponse($record));
}
}
}

}

/**
Expand Down
25 changes: 23 additions & 2 deletions src/com/zoho/crm/library/api/response/ResponseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ class ResponseInfo
private $recordCount=null;
private $pageNo=null;
private $perPage=null;

private $tagAllowedCount=null;

public function __construct($reponseInfoJSON)
{
$this->moreRecords=(bool)$reponseInfoJSON[APIConstants::MORE_RECORDS];
$this->recordCount=$reponseInfoJSON[APIConstants::COUNT]+0;
$this->pageNo=$reponseInfoJSON[APIConstants::PAGE]+0;
$this->perPage=$reponseInfoJSON[APIConstants::PER_PAGE]+0;
$this->perPage=$reponseInfoJSON[APIConstants::PER_PAGE]+0;
if(array_key_exists(APIConstants::ALLOWED_COUNT,$reponseInfoJSON))
{
$this->tagAllowedCount=$reponseInfoJSON[APIConstants::ALLOWED_COUNT]+0;
}
}

/**
Expand Down Expand Up @@ -80,5 +85,21 @@ public function setPerPage($perPage){
$this->perPage = $perPage;
}

/**
* allowedCount
* @return int
*/
public function getAllowedCount(){
return $this->allowedCount;
}

/**
* $allowedCount
* @param int $allowedCount
*/
public function setAllowedCount($allowedCount){
$this->allowedCount = $allowedCount;
}

}
?>
4 changes: 4 additions & 0 deletions src/com/zoho/crm/library/common/APIConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class APIConstants
const API_NAME="api_name";
const INVALID_ID_MSG = "The given id seems to be invalid.";
const API_MAX_RECORDS_MSG = "Cannot process more than 100 records at a time.";
const API_MAX_TAGS_MSG = "Cannot process more than 50 tags at a time.";
const API_MAX_RECORD_TAGS_MSG = "Cannot process more than 10 tags at a time.";
const INVALID_DATA="INVALID_DATA";

const CODE_SUCCESS = "SUCCESS";
Expand All @@ -36,12 +38,14 @@ class APIConstants
const PAGE = "page";
const COUNT = "count";
const MORE_RECORDS = "more_records";
const ALLOWED_COUNT = "allowed_count";

const MESSAGE = "message";
const CODE = "code";
const STATUS = "status";

const DATA = "data";
const TAGS = "tags";
const INFO = "info";

const RESPONSECODE_OK=200;
Expand Down
78 changes: 78 additions & 0 deletions src/com/zoho/crm/library/crud/ZCRMModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require_once 'ZCRMRecord.php';
require_once realpath(dirname(__FILE__).'/../api/handler/EntityAPIHandler.php');
require_once realpath(dirname(__FILE__).'/../api/handler/MassEntityAPIHandler.php');
require_once realpath(dirname(__FILE__).'/../api/handler/TagAPIHandler.php');

class ZCRMModule
{
Expand Down Expand Up @@ -580,5 +581,82 @@ public function getPermanentlyDeletedRecords()
{
return MassEntityAPIHandler::getInstance($this)->getPermanentlyDeletedRecords();
}
public function getTags()
{
if($this->apiName == null || $this->apiName == "")
{
throw new ZCRMException("Module Api Name MUST NOT be null/empty for getTags operation");
}
return TagAPIHandler::getInstance($this)->getTags();
}
public function getTagCount($tagid)
{
if($this->apiName == null || $this->apiName == "")
{
throw new ZCRMException("Module Api Name MUST NOT be null/empty for getTagCount operation");
}
if ($tagid == null || $tagid == 0)
{
throw new ZCRMException("Tag ID MUST NOT be null/empty for getTagCount operation");
}
return TagAPIHandler::getInstance($this)->getTagCount($tagid);
}
public function createTags($tags)
{
if($this->apiName == null || $this->apiName == "")
{
throw new ZCRMException("Module Api Name MUST NOT be null/empty for createTags operation");
}
if(sizeof($tags)<=0){
throw new ZCRMException("Tag object list MUST NOT be null/empty for createTags operation");
}
return TagAPIHandler::getInstance($this)->createTags($tags);

}
public function updateTags($tags)
{
if($this->apiName == null || $this->apiName == "")
{
throw new ZCRMException("Module Api Name MUST NOT be null/empty for updateTags operation");
}
if(sizeof($tags)<=0){
throw new ZCRMException("Tag object list MUST NOT be null/empty for updateTags operation");
}
return TagAPIHandler::getInstance($this)->updateTags($tags);

}
public function addTagsToRecords($recordIds, $tagNames)
{
if($this->apiName == null || $this->apiName == "")
{
throw new ZCRMException("Module Api Name MUST NOT be null/empty for Add Tags to Multiple records operation");
}
if(sizeof($tagNames)<=0)
{
throw new ZCRMException("Tag Name list MUST NOT be null/empty for Add Tags to Multiple records operation");
}
if(sizeof($recordIds)<=0)
{
throw new ZCRMException("Record ID list MUST NOT be null/empty for Add Tags to Multiple records operation");
}
return TagAPIHandler::getInstance($this)->addTagsToRecords($recordIds, $tagNames);
}

public function removeTagsFromRecords($recordIds, $tagNames)
{
if($this->apiName == null || $this->apiName == "")
{
throw new ZCRMException("Module Api Name MUST NOT be null/empty for Remove Tags from Multiple records operation");
}
if(sizeof($tagNames)<=0)
{
throw new ZCRMException("Tag Name list MUST NOT be null/empty for Remove Tags from Multiple records operation");
}
if(sizeof($recordIds)<=0)
{
throw new ZCRMException("Record ID list MUST NOT be null/empty for Remove Tags from Multiple records operation");
}
return TagAPIHandler::getInstance($this)->removeTagsFromRecords($recordIds, $tagNames);
}
}
?>
53 changes: 51 additions & 2 deletions src/com/zoho/crm/library/crud/ZCRMRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ZCRMRecord
private $priceDetails = array();
private $layout=null;
private $taxList=array();
private $lastActivityTime=null;
private $lastActivityTime=null;
private $tags=array();

private function __construct($module,$entityId)
{
Expand Down Expand Up @@ -213,6 +214,22 @@ public function getModifiedTime(){
public function setModifiedTime($modifiedTime){
$this->modifiedTime = $modifiedTime;
}

/**
* tags
* @return Array
*/
public function getTags(){
return $this->tags;
}

/**
* tags
* @param Array $tags
*/
public function setTags($tags){
$this->tags = $tags;
}

/**
* Returns the API response of the record creation.
Expand Down Expand Up @@ -364,7 +381,39 @@ public function removeRelation(ZCRMJunctionRecord $junctionRecord)
{
return ZCRMModuleRelation::getInstance($this, $junctionRecord)->removeRelation();
}

public function addTags($tagNames)
{
if ($this->entityId == null || $this->entityId == 0)
{
throw new ZCRMException("Record ID MUST NOT be null/empty for Add Tags to a Specific record operation");
}
if ($this->moduleApiName == null || $this->moduleApiName == "")
{
throw new ZCRMException("Module Api Name MUST NOT be null/empty for Add Tags to a Specific record operation");
}
if(sizeof($tagNames)<=0)
{
throw new ZCRMException("Tag Name list MUST NOT be null/empty for Add Tags to a Specific record operation");
}
return TagAPIHandler::getInstance()->addTags($this, $tagNames);
}

public function removeTags($tagNames)
{
if ($this->entityId == null || $this->entityId == 0)
{
throw new ZCRMException("Record ID MUST NOT be null/empty for Remove Tags from a Specific record operation");
}
if ($this->moduleApiName == null || $this->moduleApiName == "")
{
throw new ZCRMException("Module Api Name MUST NOT be null/empty for Remove Tags from a Specific record operation");
}
if(sizeof($tagNames)<=0)
{
throw new ZCRMException("Tag Name list MUST NOT be null/empty for Remove Tags from a Specific record operation");
}
return TagAPIHandler::getInstance()->removeTags($this, $tagNames);
}
/**
* properties
* @return HashMap
Expand Down
Loading

0 comments on commit 3ce8de9

Please sign in to comment.