Skip to content

Commit 168de63

Browse files
committed
1.multiple notes and notes attachment support
2.adding taxes to product (bug fix)
1 parent fb1f546 commit 168de63

File tree

8 files changed

+146
-10
lines changed

8 files changed

+146
-10
lines changed

src/crm/api/handler/EntityAPIHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function getZCRMRecordAsJSON()
280280
$recordJSON["Pricing_Details"] = self::getPriceDetailsAsJSONArray();
281281
}
282282
if (sizeof($this->record->getTaxList()) > 0) {
283-
if ($this->record->getModuleApiName == "Product")
283+
if ($this->record->getModuleApiName() == "Products")
284284
$key = "Tax";
285285
else
286286
$key = "\$line_tax";

src/crm/api/handler/OrganizationAPIHandler.php

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use zcrmsdk\crm\setup\users\ZCRMUserCustomizeInfo;
1616
use zcrmsdk\crm\setup\users\ZCRMUserTheme;
1717
use zcrmsdk\crm\utility\APIConstants;
18+
use zcrmsdk\crm\crud\ZCRMRecord;
19+
use zcrmsdk\crm\crud\ZCRMNote;
1820

1921

2022
/**
@@ -34,7 +36,73 @@ public static function getInstance()
3436
{
3537
return new OrganizationAPIHandler();
3638
}
37-
39+
public function getNotes(){
40+
try {
41+
$this->urlPath = "Notes";
42+
$this->requestMethod = APIConstants::REQUEST_METHOD_GET;
43+
$this->addHeader("Content-Type", "application/json");
44+
$responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
45+
$responseJSON = $responseInstance->getResponseJSON();
46+
$notesDetails = $responseJSON['data'];
47+
$noteInstancesArray = array();
48+
foreach ($notesDetails as $notesObj) {
49+
$record_Ins=ZCRMRecord::getInstance($notesObj["\$se_module"], $notesObj["Parent_Id"]["id"]);
50+
$noteIns=ZCRMNote::getInstance($record_Ins,$notesObj["id"]);
51+
array_push($noteInstancesArray,RelatedListAPIHandler::getInstance($record_Ins, "Notes")->getZCRMNote($notesObj,$noteIns));
52+
}
53+
$responseInstance->setData($noteInstancesArray);
54+
return $responseInstance;
55+
} catch (ZCRMException $exception) {
56+
APIExceptionHandler::logException($exception);
57+
throw $exception;
58+
}
59+
}
60+
public function createNotes($noteInstances){
61+
if (sizeof($noteInstances) > 100) {
62+
throw new ZCRMException(APIConstants::API_MAX_NOTES_MSG, APIConstants::RESPONSECODE_BAD_REQUEST);
63+
}
64+
try {
65+
$dataArray = array();
66+
foreach ($noteInstances as $noteInstance) {
67+
if ($noteInstance->getId() == null) {
68+
$record_Ins=ZCRMRecord::getInstance($noteInstance->getParentModule(),$noteInstance->getParentId());
69+
array_push($dataArray, RelatedListAPIHandler::getInstance($record_Ins,"Notes")->getZCRMNoteAsJSON($noteInstance));
70+
} else {
71+
throw new ZCRMException(" ID MUST be null for create operation.", APIConstants::RESPONSECODE_BAD_REQUEST);
72+
}
73+
}
74+
75+
$requestBodyObj = array();
76+
$requestBodyObj["data"] = $dataArray;
77+
$this->urlPath = "Notes";
78+
$this->requestMethod = APIConstants::REQUEST_METHOD_POST;
79+
$this->addHeader("Content-Type", "application/json");
80+
$this->requestBody = $requestBodyObj;
81+
82+
$responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
83+
return $responseInstance;
84+
} catch (ZCRMException $exception) {
85+
APIExceptionHandler::logException($exception);
86+
throw $exception;
87+
}
88+
}
89+
public function deleteNotes($noteIds){
90+
if (sizeof($noteIds) > 100) {
91+
throw new ZCRMException(APIConstants::API_MAX_NOTES_MSG, APIConstants::RESPONSECODE_BAD_REQUEST);
92+
}
93+
try {
94+
95+
$this->urlPath = "Notes";
96+
$this->requestMethod = APIConstants::REQUEST_METHOD_DELETE;
97+
$this->addHeader("Content-Type", "application/json");
98+
$this->addParam("ids", implode(",", $noteIds)); // converts array to string with specified seperator
99+
$responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
100+
return $responseInstance;
101+
} catch (ZCRMException $exception) {
102+
APIExceptionHandler::logException($exception);
103+
throw $exception;
104+
}
105+
}
38106
public function getOrganizationDetails()
39107
{
40108
try {

src/crm/api/handler/RelatedListAPIHandler.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,32 @@ public function getAttachments($page, $perPage)
130130
throw $exception;
131131
}
132132
}
133-
133+
public function addNotes($noteInstances){
134+
if (sizeof($noteInstances) > 100) {
135+
throw new ZCRMException(APIConstants::API_MAX_NOTES_MSG, APIConstants::RESPONSECODE_BAD_REQUEST);
136+
}
137+
try {
138+
$dataArray = array();
139+
foreach ($noteInstances as $noteInstance) {
140+
if ($noteInstance->getId() == null) {
141+
array_push($dataArray, $this->getZCRMNoteAsJSON($noteInstance));
142+
} else {
143+
throw new ZCRMException(" ID MUST be null for create operation.", APIConstants::RESPONSECODE_BAD_REQUEST);
144+
}
145+
}
146+
$requestBodyObj = array();
147+
$requestBodyObj["data"] = $dataArray;
148+
$this->urlPath = $this->parentRecord->getModuleApiName() . "/" . $this->parentRecord->getEntityId() . "/" . $this->relatedList->getApiName();
149+
$this->requestMethod = APIConstants::REQUEST_METHOD_POST;
150+
$this->addHeader("Content-Type", "application/json");
151+
$this->requestBody = $requestBodyObj;
152+
$responseInstance = APIRequest::getInstance($this)->getBulkAPIResponse();
153+
return $responseInstance;
154+
} catch (ZCRMException $exception) {
155+
APIExceptionHandler::logException($exception);
156+
throw $exception;
157+
}
158+
}
134159
public function addNote($zcrmNote)
135160
{
136161
try {
@@ -307,11 +332,20 @@ public function getZCRMNoteAsJSON($noteIns)
307332
if ($noteIns->getTitle() != null) {
308333
$noteJson['Note_Title'] = $noteIns->getTitle();
309334
}
335+
if ($noteIns->getParentModule() != null) {
336+
$noteJson['se_module'] = $noteIns->getParentModule();
337+
}
338+
if ($noteIns->getParentId() != null) {
339+
$noteJson['Parent_Id'] = $noteIns->getParentId();
340+
}
341+
if ($noteIns->getTitle() != null) {
342+
$noteJson['Note_Title'] = $noteIns->getTitle();
343+
}
310344
$noteJson['Note_Content'] = $noteIns->getContent();
311345
return $noteJson;
312346
}
313347

314-
private function getZCRMNote($noteDetails, $noteIns)
348+
public function getZCRMNote($noteDetails, $noteIns)
315349
{
316350
if ($noteIns == null) {
317351
$noteIns = ZCRMNote::getInstance($this->parentRecord, $noteDetails["id"]);

src/crm/crud/ZCRMModuleRelation.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ public function addNote($zcrmNote)
132132
{
133133
return RelatedListAPIHandler::getInstance($this->parentRecord, $this)->addNote($zcrmNote);
134134
}
135-
135+
public function addNotes($noteInstances)
136+
{
137+
return RelatedListAPIHandler::getInstance($this->parentRecord, $this)->addNotes($noteInstances);
138+
}
136139
/**
137140
* method to update the note of the module relation
138141
*

src/crm/crud/ZCRMNote.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ class ZCRMNote
119119
*/
120120
private function __construct($parentRecord, $noteId)
121121
{
122-
$this->parentRecord = $parentRecord;
122+
if(!is_null($parentRecord)){
123+
$this->parentId=$parentRecord->getEntityId();
124+
$this->parentModule=$parentRecord->getModuleApiName();
125+
$this->parentRecord = $parentRecord;
126+
}
123127
$this->id = $noteId;
124128
}
125129

@@ -130,7 +134,7 @@ private function __construct($parentRecord, $noteId)
130134
* @param string $noteId note id
131135
* @return ZCRMNote instance of the ZCRMNote class
132136
*/
133-
public static function getInstance($parentRecord, $noteId = null)
137+
public static function getInstance($parentRecord=null, $noteId = null)
134138
{
135139
return new ZCRMNote($parentRecord, $noteId);
136140
}
@@ -434,4 +438,18 @@ public function setParentId($parentId)
434438
{
435439
$this->parentId = $parentId;
436440
}
441+
public function getAttachmentsOfNote($page = 1, $perPage = 20){
442+
return ZCRMModuleRelation::getInstance(ZCRMRecord::getInstance("Notes", $this->getId()), "Attachments")->getAttachments($page, $perPage);
443+
}
444+
public function uploadAttachment($filePath)
445+
{
446+
return ZCRMModuleRelation::getInstance(ZCRMRecord::getInstance("Notes", $this->getId()), "Attachments")->uploadAttachment($filePath);
447+
}
448+
public function downloadAttachment($attachmentId){
449+
return ZCRMModuleRelation::getInstance(ZCRMRecord::getInstance("Notes", $this->getId()), "Attachments")->downloadAttachment($attachmentId);
450+
}
451+
public function deleteAttachment($attachmentId)
452+
{
453+
return ZCRMModuleRelation::getInstance(ZCRMRecord::getInstance("Notes", $this->getId()), "Attachments")->deleteAttachment($attachmentId);
454+
}
437455
}

src/crm/crud/ZCRMRecord.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,10 @@ public function addNote($zcrmNoteIns)
590590
}
591591
return ZCRMModuleRelation::getInstance($this, "Notes")->addNote($zcrmNoteIns);
592592
}
593-
593+
public function addNotes($noteInstances)
594+
{
595+
return ZCRMModuleRelation::getInstance($this, "Notes")->addNotes($noteInstances);
596+
}
594597
/**
595598
* Method to update the note of the reecord
596599
*

src/crm/setup/org/ZCRMOrganization.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,14 @@ public function updateVariables($variable)
10891089
$instance = VariableAPIHandler::getInstance();
10901090
return $instance->updateVariables($variable);
10911091
}
1092-
1092+
public function getNotes(){
1093+
return OrganizationAPIHandler::getInstance()->getNotes();
1094+
}
1095+
public function createNotes($noteInstances){
1096+
return OrganizationAPIHandler::getInstance()->createNotes($noteInstances);
1097+
}
1098+
public function deleteNotes($noteIds){
1099+
return OrganizationAPIHandler::getInstance()->deleteNotes($noteIds);
1100+
}
10931101

10941102
}

src/crm/utility/APIConstants.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class APIConstants
2626

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

29+
const API_MAX_NOTES_MSG = "Cannot process more than 100 notes at a time.";
30+
2931
const API_MAX_TAGS_MSG = "Cannot process more than 50 tags at a time.";
3032

3133
const API_MAX_RECORD_TAGS_MSG = "Cannot process more than 10 tags at a time.";
@@ -77,7 +79,7 @@ class APIConstants
7779
const TAXES = "taxes";
7880

7981
const INFO = "info";
80-
82+
8183
const VARIABLES = "variables";
8284

8385
const RESPONSECODE_OK = 200;

0 commit comments

Comments
 (0)