1515use zcrmsdk \crm \setup \users \ZCRMUserCustomizeInfo ;
1616use zcrmsdk \crm \setup \users \ZCRMUserTheme ;
1717use 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 {
0 commit comments