Skip to content

Commit

Permalink
1.multiple notes and notes attachment support
Browse files Browse the repository at this point in the history
2.adding taxes to product (bug fix)
  • Loading branch information
pravesh-a committed Oct 8, 2019
1 parent fb1f546 commit 168de63
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/crm/api/handler/EntityAPIHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function getZCRMRecordAsJSON()
$recordJSON["Pricing_Details"] = self::getPriceDetailsAsJSONArray();
}
if (sizeof($this->record->getTaxList()) > 0) {
if ($this->record->getModuleApiName == "Product")
if ($this->record->getModuleApiName() == "Products")
$key = "Tax";
else
$key = "\$line_tax";
Expand Down
70 changes: 69 additions & 1 deletion src/crm/api/handler/OrganizationAPIHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use zcrmsdk\crm\setup\users\ZCRMUserCustomizeInfo;
use zcrmsdk\crm\setup\users\ZCRMUserTheme;
use zcrmsdk\crm\utility\APIConstants;
use zcrmsdk\crm\crud\ZCRMRecord;
use zcrmsdk\crm\crud\ZCRMNote;


/**
Expand All @@ -34,7 +36,73 @@ public static function getInstance()
{
return new OrganizationAPIHandler();
}

public function getNotes(){
try {
$this->urlPath = "Notes";
$this->requestMethod = APIConstants::REQUEST_METHOD_GET;
$this->addHeader("Content-Type", "application/json");
$responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
$responseJSON = $responseInstance->getResponseJSON();
$notesDetails = $responseJSON['data'];
$noteInstancesArray = array();
foreach ($notesDetails as $notesObj) {
$record_Ins=ZCRMRecord::getInstance($notesObj["\$se_module"], $notesObj["Parent_Id"]["id"]);
$noteIns=ZCRMNote::getInstance($record_Ins,$notesObj["id"]);
array_push($noteInstancesArray,RelatedListAPIHandler::getInstance($record_Ins, "Notes")->getZCRMNote($notesObj,$noteIns));
}
$responseInstance->setData($noteInstancesArray);
return $responseInstance;
} catch (ZCRMException $exception) {
APIExceptionHandler::logException($exception);
throw $exception;
}
}
public function createNotes($noteInstances){
if (sizeof($noteInstances) > 100) {
throw new ZCRMException(APIConstants::API_MAX_NOTES_MSG, APIConstants::RESPONSECODE_BAD_REQUEST);
}
try {
$dataArray = array();
foreach ($noteInstances as $noteInstance) {
if ($noteInstance->getId() == null) {
$record_Ins=ZCRMRecord::getInstance($noteInstance->getParentModule(),$noteInstance->getParentId());
array_push($dataArray, RelatedListAPIHandler::getInstance($record_Ins,"Notes")->getZCRMNoteAsJSON($noteInstance));
} else {
throw new ZCRMException(" ID MUST be null for create operation.", APIConstants::RESPONSECODE_BAD_REQUEST);
}
}

$requestBodyObj = array();
$requestBodyObj["data"] = $dataArray;
$this->urlPath = "Notes";
$this->requestMethod = APIConstants::REQUEST_METHOD_POST;
$this->addHeader("Content-Type", "application/json");
$this->requestBody = $requestBodyObj;

$responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
return $responseInstance;
} catch (ZCRMException $exception) {
APIExceptionHandler::logException($exception);
throw $exception;
}
}
public function deleteNotes($noteIds){
if (sizeof($noteIds) > 100) {
throw new ZCRMException(APIConstants::API_MAX_NOTES_MSG, APIConstants::RESPONSECODE_BAD_REQUEST);
}
try {

$this->urlPath = "Notes";
$this->requestMethod = APIConstants::REQUEST_METHOD_DELETE;
$this->addHeader("Content-Type", "application/json");
$this->addParam("ids", implode(",", $noteIds)); // converts array to string with specified seperator
$responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
return $responseInstance;
} catch (ZCRMException $exception) {
APIExceptionHandler::logException($exception);
throw $exception;
}
}
public function getOrganizationDetails()
{
try {
Expand Down
38 changes: 36 additions & 2 deletions src/crm/api/handler/RelatedListAPIHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,32 @@ public function getAttachments($page, $perPage)
throw $exception;
}
}

public function addNotes($noteInstances){
if (sizeof($noteInstances) > 100) {
throw new ZCRMException(APIConstants::API_MAX_NOTES_MSG, APIConstants::RESPONSECODE_BAD_REQUEST);
}
try {
$dataArray = array();
foreach ($noteInstances as $noteInstance) {
if ($noteInstance->getId() == null) {
array_push($dataArray, $this->getZCRMNoteAsJSON($noteInstance));
} else {
throw new ZCRMException(" ID MUST be null for create operation.", APIConstants::RESPONSECODE_BAD_REQUEST);
}
}
$requestBodyObj = array();
$requestBodyObj["data"] = $dataArray;
$this->urlPath = $this->parentRecord->getModuleApiName() . "/" . $this->parentRecord->getEntityId() . "/" . $this->relatedList->getApiName();
$this->requestMethod = APIConstants::REQUEST_METHOD_POST;
$this->addHeader("Content-Type", "application/json");
$this->requestBody = $requestBodyObj;
$responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
return $responseInstance;
} catch (ZCRMException $exception) {
APIExceptionHandler::logException($exception);
throw $exception;
}
}
public function addNote($zcrmNote)
{
try {
Expand Down Expand Up @@ -307,11 +332,20 @@ public function getZCRMNoteAsJSON($noteIns)
if ($noteIns->getTitle() != null) {
$noteJson['Note_Title'] = $noteIns->getTitle();
}
if ($noteIns->getParentModule() != null) {
$noteJson['se_module'] = $noteIns->getParentModule();
}
if ($noteIns->getParentId() != null) {
$noteJson['Parent_Id'] = $noteIns->getParentId();
}
if ($noteIns->getTitle() != null) {
$noteJson['Note_Title'] = $noteIns->getTitle();
}
$noteJson['Note_Content'] = $noteIns->getContent();
return $noteJson;
}

private function getZCRMNote($noteDetails, $noteIns)
public function getZCRMNote($noteDetails, $noteIns)
{
if ($noteIns == null) {
$noteIns = ZCRMNote::getInstance($this->parentRecord, $noteDetails["id"]);
Expand Down
5 changes: 4 additions & 1 deletion src/crm/crud/ZCRMModuleRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ public function addNote($zcrmNote)
{
return RelatedListAPIHandler::getInstance($this->parentRecord, $this)->addNote($zcrmNote);
}

public function addNotes($noteInstances)
{
return RelatedListAPIHandler::getInstance($this->parentRecord, $this)->addNotes($noteInstances);
}
/**
* method to update the note of the module relation
*
Expand Down
22 changes: 20 additions & 2 deletions src/crm/crud/ZCRMNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ class ZCRMNote
*/
private function __construct($parentRecord, $noteId)
{
$this->parentRecord = $parentRecord;
if(!is_null($parentRecord)){
$this->parentId=$parentRecord->getEntityId();
$this->parentModule=$parentRecord->getModuleApiName();
$this->parentRecord = $parentRecord;
}
$this->id = $noteId;
}

Expand All @@ -130,7 +134,7 @@ private function __construct($parentRecord, $noteId)
* @param string $noteId note id
* @return ZCRMNote instance of the ZCRMNote class
*/
public static function getInstance($parentRecord, $noteId = null)
public static function getInstance($parentRecord=null, $noteId = null)
{
return new ZCRMNote($parentRecord, $noteId);
}
Expand Down Expand Up @@ -434,4 +438,18 @@ public function setParentId($parentId)
{
$this->parentId = $parentId;
}
public function getAttachmentsOfNote($page = 1, $perPage = 20){
return ZCRMModuleRelation::getInstance(ZCRMRecord::getInstance("Notes", $this->getId()), "Attachments")->getAttachments($page, $perPage);
}
public function uploadAttachment($filePath)
{
return ZCRMModuleRelation::getInstance(ZCRMRecord::getInstance("Notes", $this->getId()), "Attachments")->uploadAttachment($filePath);
}
public function downloadAttachment($attachmentId){
return ZCRMModuleRelation::getInstance(ZCRMRecord::getInstance("Notes", $this->getId()), "Attachments")->downloadAttachment($attachmentId);
}
public function deleteAttachment($attachmentId)
{
return ZCRMModuleRelation::getInstance(ZCRMRecord::getInstance("Notes", $this->getId()), "Attachments")->deleteAttachment($attachmentId);
}
}
5 changes: 4 additions & 1 deletion src/crm/crud/ZCRMRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,10 @@ public function addNote($zcrmNoteIns)
}
return ZCRMModuleRelation::getInstance($this, "Notes")->addNote($zcrmNoteIns);
}

public function addNotes($noteInstances)
{
return ZCRMModuleRelation::getInstance($this, "Notes")->addNotes($noteInstances);
}
/**
* Method to update the note of the reecord
*
Expand Down
10 changes: 9 additions & 1 deletion src/crm/setup/org/ZCRMOrganization.php
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,14 @@ public function updateVariables($variable)
$instance = VariableAPIHandler::getInstance();
return $instance->updateVariables($variable);
}

public function getNotes(){
return OrganizationAPIHandler::getInstance()->getNotes();
}
public function createNotes($noteInstances){
return OrganizationAPIHandler::getInstance()->createNotes($noteInstances);
}
public function deleteNotes($noteIds){
return OrganizationAPIHandler::getInstance()->deleteNotes($noteIds);
}

}
4 changes: 3 additions & 1 deletion src/crm/utility/APIConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class APIConstants

const API_MAX_ORGTAX_MSG = "Cannot process more than 100 org taxes at a time.";

const API_MAX_NOTES_MSG = "Cannot process more than 100 notes 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.";
Expand Down Expand Up @@ -77,7 +79,7 @@ class APIConstants
const TAXES = "taxes";

const INFO = "info";

const VARIABLES = "variables";

const RESPONSECODE_OK = 200;
Expand Down

0 comments on commit 168de63

Please sign in to comment.