PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.0
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.0
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Integration / ZohoProjects / RecordApiHelper.php

RecordApiHelper.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.0, at includes/Core/Integration/ZohoProjects/RecordApiHelper.php

533 lines 24.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * ZohoRecruit Record Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\ZohoProjects;
9
10 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
11 use BitCode\BitForm\Core\Util\FieldValueHandler;
12 use BitCode\BitForm\Core\Util\HttpHelper;
13 use WP_Error;
14
15 /**
16 * Provide functionality for Record insert,upsert
17 */
18 class RecordApiHelper {
19 private $_defaultHeader;
20 private $_apiDomain;
21 private $_tokenDetails;
22
23 private $_integrationID;
24
25 private $_logID;
26
27 private $_logResponse;
28
29 public function __construct($tokenDetails, $integId, $logID) {
30 $this->_defaultHeader['Authorization'] = "Zoho-oauthtoken {$tokenDetails->access_token}";
31 $this->_defaultHeader['Content-Type'] = 'application/json';
32 $this->_apiDomain = \urldecode($tokenDetails->api_domain);
33 $this->_tokenDetails = $tokenDetails;
34 $this->_integrationID = $integId;
35 $this->_logID = $logID;
36 $this->_logResponse = new UtilApiResponse();
37 }
38
39 private function createProject($dataCenter, $portalId, $data) {
40 $createProjectEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/";
41
42 $createProjectEndpoint .= '?' . http_build_query($data);
43
44 // var_dump($createProjectEndpoint);
45
46 return HttpHelper::post($createProjectEndpoint, null, $this->_defaultHeader);
47 }
48
49 private function createMilestone($dataCenter, $portalId, $projectId, $data) {
50 $createMilestoneEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/milestones/";
51
52 $createMilestoneEndpoint .= '?' . http_build_query($data);
53
54 return HttpHelper::post($createMilestoneEndpoint, null, $this->_defaultHeader);
55 }
56
57 private function createTasklist($dataCenter, $portalId, $projectId, $data) {
58 $createTasklistEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/tasklists/";
59
60 $createTasklistEndpoint .= '?' . http_build_query($data);
61
62 return HttpHelper::post($createTasklistEndpoint, null, $this->_defaultHeader);
63 }
64
65 private function createTask($dataCenter, $portalId, $projectId, $data) {
66 $createTaskEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/tasks/";
67
68 $createTaskEndpoint .= '?' . http_build_query($data);
69
70 // var_dump($createTaskEndpoint);
71
72 return HttpHelper::post($createTaskEndpoint, null, $this->_defaultHeader);
73 }
74
75 private function createSubTask($dataCenter, $portalId, $projectId, $taskId, $data) {
76 $createSubTaskEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/tasks/{$taskId}/subtasks/";
77
78 $createSubTaskEndpoint .= '?' . http_build_query($data);
79
80 return HttpHelper::post($createSubTaskEndpoint, null, $this->_defaultHeader);
81 }
82
83 private function createIssue($dataCenter, $portalId, $projectId, $data) {
84 $createIssueEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/bugs/";
85
86 $createIssueEndpoint .= '?' . http_build_query($data);
87
88 // var_dump($createIssueEndpoint);
89
90 return HttpHelper::post($createIssueEndpoint, null, $this->_defaultHeader);
91 }
92
93 private function getAllTags($dataCenter, $portalId) {
94 $tagsMetaApiEndpoint = "https://projectsapi.zoho.{$dataCenter}/api/v3/portal/{$portalId}/tags?range=10000";
95
96 return HttpHelper::get($tagsMetaApiEndpoint, null, $this->_defaultHeader);
97 }
98
99 private function createTags($dataCenter, $portalId, $data) {
100 $createTagsEndpoint = "https://projectsapi.zoho.{$dataCenter}/api/v3/portal/{$portalId}/tags";
101
102 $createTagsEndpoint .= '?' . http_build_query($data);
103
104 return HttpHelper::post($createTagsEndpoint, null, $this->_defaultHeader);
105 }
106
107 private function associateTags($dataCenter, $portalId, $projectId, $data) {
108 $associateTagEndpoint = "https://projectsapi.zoho.{$dataCenter}/api/v3/portal/{$portalId}/projects/{$projectId}/tags/associate";
109
110 $associateTagEndpoint .= '?' . http_build_query($data);
111
112 // var_dump($associateTagEndpoint);
113
114 return HttpHelper::post($associateTagEndpoint, null, $this->_defaultHeader);
115 }
116
117 private function associateUsers($dataCenter, $portalId, $projectId, $data) {
118 $associateUsersEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/users/";
119
120 $associateUsersEndpoint .= '?' . http_build_query($data);
121
122 return HttpHelper::post($associateUsersEndpoint, null, $this->_defaultHeader);
123 }
124
125 private function addBugFollower($dataCenter, $portalId, $projectId, $bugId, $data) {
126 $addBugFollowerEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/bugs/{$bugId}/bugfollowers/";
127
128 $addBugFollowerEndpoint .= '?' . http_build_query($data);
129
130 return HttpHelper::post($addBugFollowerEndpoint, null, $this->_defaultHeader);
131 }
132
133 private function addTimeLog($dataCenter, $portalId, $projectId, $event, $eventId, $data) {
134 $addTimeLogEndpoint = "https://projectsapi.zoho.{$dataCenter}/restapi/portal/{$portalId}/projects/{$projectId}/" . (in_array($event, ['task', 'subtask']) ? 'tasks' : 'bugs') . "/{$eventId}/logs/";
135
136 $addTimeLogEndpoint .= '?' . http_build_query($data);
137
138 // var_dump($addTimeLogEndpoint);
139
140 return HttpHelper::post($addTimeLogEndpoint, null, $this->_defaultHeader);
141 }
142
143 private function testDate($x) {
144 if (date('Y-m-d', strtotime($x)) === $x) {
145 return true;
146 }
147 return false;
148 }
149
150 public function executeRecordApi($formID, $entryID, $projectsConf, $dataCenter, $fieldMap, $fieldValues) {
151 $portalId = $projectsConf->portalId;
152 $subEvent = $projectsConf->subEvent;
153 $actions = $projectsConf->actions;
154 $fieldData = [];
155 $projectId = '';
156
157 $eventApiResponse = [];
158
159 // Map Field & Actions Start
160 foreach ($subEvent as $sEvent) {
161 $required = $projectsConf->default->fields->{$portalId}->{$sEvent}->required;
162 // Field Mapping
163 foreach ($fieldMap->{$sEvent} as $fieldKey => $fieldPair) {
164 if (!empty($fieldPair->zohoFormField)) {
165 if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) {
166 if ('cf' === strtok($fieldPair->zohoFormField, '_')) {
167 $fieldPair->zohoFormField = str_replace('cf_', '', $fieldPair->zohoFormField);
168 $fieldData[$sEvent]['custom_fields'][$fieldPair->zohoFormField] = $this->testDate($fieldPair->customValue) ? date_format(date_create($fieldPair->customValue), 'm-d-Y') : $fieldPair->customValue;
169 } else {
170 $fieldData[$sEvent][$fieldPair->zohoFormField] = $this->testDate($fieldPair->customValue) ? date_format(date_create($fieldPair->customValue), 'm-d-Y') : $fieldPair->customValue;
171 }
172 } else {
173 if ('cf' === strtok($fieldPair->zohoFormField, '_')) {
174 $fieldPair->zohoFormField = str_replace('cf_', '', $fieldPair->zohoFormField);
175 $fieldData[$sEvent]['custom_fields'][$fieldPair->zohoFormField] = $this->testDate($fieldValues[$fieldPair->formField]) ? date_format(date_create($fieldValues[$fieldPair->formField]), 'm-d-Y') : $fieldValues[$fieldPair->formField];
176 } else {
177 $fieldData[$sEvent][$fieldPair->zohoFormField] = $this->testDate($fieldValues[$fieldPair->formField]) ? date_format(date_create($fieldValues[$fieldPair->formField]), 'm-d-Y') : $fieldValues[$fieldPair->formField];
178 }
179 }
180 }
181 if (empty($fieldData[$sEvent][$fieldPair->zohoFormField]) && \in_array($fieldPair->zohoFormField, $required)) {
182 $error = new WP_Error('REQ_FIELD_EMPTY', wp_sprintf(__('%s is required for %s', 'bit-form'), $fieldPair->zohoFormField, $sEvent));
183 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'field'], 'validation', $error);
184 return $error;
185 }
186 }
187
188 if (isset($fieldData[$sEvent]['custom_fields'])) {
189 $fieldData[$sEvent]['custom_fields'] = json_encode($fieldData[$sEvent]['custom_fields']);
190 }
191
192 // Actions Mapping
193 foreach ($actions->{$sEvent} as $fieldKey => $action) {
194 if (in_array($fieldKey, ['tags', 'attachments', 'users', 'timelog', 'bug_followers'])) {
195 continue;
196 }
197 if (('object' === gettype($action) && count((array) $action)) || ('string' === gettype($action) && !empty($action))) {
198 if ('owner' === $fieldKey) {
199 if ('task' === $sEvent || 'subtask' === $sEvent) {
200 $fieldData[$sEvent]['person_responsible'] = $action;
201 } elseif ('issue' === $sEvent) {
202 $fieldData[$sEvent]['assignee'] = $action;
203 } else {
204 $fieldData[$sEvent]['owner'] = $action;
205 }
206 } elseif ('reminder_string' === $fieldKey && !empty($action->reminder_criteria)) {
207 if (isset($action->custom_date_fld)) {
208 $action->custom_date = FieldValueHandler::replaceFieldWithValue($action->custom_date_fld, $fieldValues);
209 }
210 if (isset($action->reminder_time_fld)) {
211 $action->reminder_time = FieldValueHandler::replaceFieldWithValue($action->reminder_time_fld, $fieldValues);
212 }
213
214 if (isset($action->custom_date)) {
215 $action->custom_date = date_format(date_create($action->custom_date), 'm-d-Y');
216 }
217 if (isset($action->reminder_time)) {
218 $action->reminder_time = date('H:i', strtotime($action->reminder_time));
219 }
220
221 unset($action->custom_date_fld, $action->reminder_time_fld);
222 $fieldData[$sEvent][$fieldKey] = '{"reminder":[' . wp_json_encode($action) . ']}';
223 } elseif ('recurrence_string' === $fieldKey && !empty($action->recurring_frequency)) {
224 if (isset($action->time_span_fld)) {
225 $action->time_span = FieldValueHandler::replaceFieldWithValue($action->time_span_fld, $fieldValues);
226 }
227 if (isset($action->number_of_occurrences_fld)) {
228 $action->number_of_occurrences = FieldValueHandler::replaceFieldWithValue($action->number_of_occurrences_fld, $fieldValues);
229 }
230 unset($action->time_span_fld, $action->number_of_occurrences_fld);
231 if (!isset($action->time_span)) {
232 $action->time_span = '1';
233 }
234 if (!isset($action->number_of_occurrences)) {
235 $action->number_of_occurrences = '2';
236 }
237 if (!isset($action->is_comments_recurred)) {
238 $action->is_comments_recurred = 'false';
239 }
240 if (!isset($action->set_previous_business_day)) {
241 $action->set_previous_business_day = 'false';
242 }
243 if (!isset($action->recurrence_type)) {
244 $action->recurrence_type = 'specified_interval_creation';
245 }
246
247 $fieldData[$sEvent]['json_string'] = '{"recurrence":' . wp_json_encode($action) . '}';
248 } else {
249 $fieldData[$sEvent][$fieldKey] = $action;
250 }
251 }
252 }
253 }
254 // Map Field & Actions End
255
256 // Create Events Start
257 $data = null;
258 if (in_array('project', $subEvent)) {
259 $apiResponse = $this->createProject($dataCenter, $portalId, $fieldData['project']);
260
261 if (isset($apiResponse->error)) {
262 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'project'], 'error', $apiResponse);
263 return new WP_Error('project not created');
264 } else {
265 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'project'], 'success', $apiResponse);
266 }
267
268 // var_dump('project', $apiResponse);
269
270 $eventApiResponse['project'] = $apiResponse->projects[0]->id_string;
271
272 if (isset($actions->project->users)) {
273 foreach ($actions->project->users as $user) {
274 $data = [
275 'email' => $user->email,
276 'role' => $user->role
277 ];
278
279 $apiResponse = $this->associateUsers($dataCenter, $portalId, $eventApiResponse['project'], $data);
280
281 if (isset($apiResponse->error)) {
282 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'user', 'type_name' => 'project'], 'error', $apiResponse);
283 } else {
284 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'user', 'type_name' => 'project'], 'success', $apiResponse);
285 }
286 }
287 }
288 }
289
290 if (isset($projectsConf->projectId) && $projectsConf->projectId) {
291 $projectId = $projectsConf->projectId;
292 } else {
293 $projectId = $eventApiResponse['project'];
294 }
295
296 if (in_array('milestone', $subEvent)) {
297 $apiResponse = $this->createMilestone($dataCenter, $portalId, $projectId, $fieldData['milestone']);
298 $eventApiResponse['milestone'] = $apiResponse->milestones[0]->id_string;
299 if (isset($apiResponse->error)) {
300 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'milestone'], 'error', $apiResponse);
301 return new WP_Error('milestone not created');
302 } else {
303 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'milestone'], 'success', $apiResponse);
304 }
305 }
306
307 if (in_array('tasklist', $subEvent)) {
308 if (isset($projectsConf->milestoneId) && $projectsConf->milestoneId) {
309 $fieldData['tasklist']['milestone_id'] = $projectsConf->milestoneId;
310 } elseif (array_key_exists('milestone', $eventApiResponse)) {
311 $fieldData['tasklist']['milestone_id'] = $eventApiResponse['milestone'];
312 }
313 $apiResponse = $this->createTasklist($dataCenter, $portalId, $projectId, $fieldData['tasklist']);
314 $eventApiResponse['tasklist'] = $apiResponse->tasklists[0]->id_string;
315 if (isset($apiResponse->error)) {
316 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'tasklist'], 'error', $apiResponse);
317 return new WP_Error('tasklist not created');
318 } else {
319 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'tasklist'], 'success', $apiResponse);
320 }
321 }
322
323 if (in_array('task', $subEvent)) {
324 if (isset($projectsConf->tasklistId) && $projectsConf->tasklistId) {
325 $fieldData['task']['tasklist_id'] = $projectsConf->tasklistId;
326 } elseif (array_key_exists('tasklist', $eventApiResponse)) {
327 $fieldData['task']['tasklist_id'] = $eventApiResponse['tasklist'];
328 }
329 $apiResponse = $this->createTask($dataCenter, $portalId, $projectId, $fieldData['task']);
330 $eventApiResponse['task'] = $apiResponse->tasks[0]->id_string;
331 if (isset($apiResponse->error)) {
332 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'task'], 'error', $apiResponse);
333 return new WP_Error('task not created');
334 } else {
335 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'task'], 'success', $apiResponse);
336 }
337 }
338
339 if (in_array('subtask', $subEvent)) {
340 $taskId = '';
341 if (isset($projectsConf->taskId) && $projectsConf->taskId) {
342 $taskId = $projectsConf->taskId;
343 } else {
344 $taskId = $eventApiResponse['task'];
345 }
346 $apiResponse = $this->createSubTask($dataCenter, $portalId, $projectId, $taskId, $fieldData['subtask']);
347 $eventApiResponse['subtask'] = $apiResponse->tasks[0]->id_string;
348 if (isset($apiResponse->error)) {
349 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'subtask'], 'error', $apiResponse);
350 return new WP_Error('subtask not created');
351 } else {
352 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'subtask'], 'success', $apiResponse);
353 }
354 }
355
356 if (in_array('issue', $subEvent)) {
357 if (isset($projectsConf->milestoneId) && $projectsConf->milestoneId) {
358 $fieldData['issue']['milestone_id'] = $projectsConf->milestoneId;
359 } elseif (array_key_exists('milestone', $eventApiResponse)) {
360 $fieldData['issue']['milestone_id'] = $eventApiResponse['milestone'];
361 }
362 $apiResponse = $this->createIssue($dataCenter, $portalId, $projectId, $fieldData['issue']);
363 $eventApiResponse['issue'] = $apiResponse->bugs[0]->id_string;
364 if (isset($apiResponse->error)) {
365 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'issue'], 'error', $apiResponse);
366 return new WP_Error('issue not created');
367 } else {
368 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'issue'], 'success', $apiResponse);
369 }
370
371 if (isset($actions->issue->bug_followers)) {
372 $bug_followers = explode(',', $actions->issue->bug_followers);
373 foreach ($bug_followers as $follower) {
374 $data = [
375 'bug_followers' => $follower
376 ];
377
378 $apiResponse = $this->addBugFollower($dataCenter, $portalId, $projectId, $eventApiResponse['issue'], $data);
379 if (isset($apiResponse->error)) {
380 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'follower', 'type_name' => 'issue'], 'error', $apiResponse);
381 } else {
382 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'follower', 'type_name' => 'issue'], 'success', $apiResponse);
383 }
384 }
385 }
386 }
387 // Create Events End
388
389 // Actions Start
390 foreach ($eventApiResponse as $eventKey => $eventId) {
391 // Attachments
392 if (isset($actions->{$eventKey}->attachments)) {
393 $filesApiHelper = new FilesApiHelper($this->_tokenDetails, $formID, $entryID);
394 $fileFound = 0;
395 $responseType = 'success';
396 $attachmentApiResponses = [];
397 $attachments = explode(',', $actions->{$eventKey}->attachments);
398 foreach ($attachments as $fileField) {
399 if (isset($fieldValues[$fileField]) && !empty($fieldValues[$fileField])) {
400 $fileFound = 1;
401 if (is_array($fieldValues[$fileField])) {
402 foreach ($fieldValues[$fileField] as $singleFile) {
403 $attachmentApiResponse = $filesApiHelper->uploadFiles($singleFile, $portalId, $projectId, $eventKey, $eventId, $dataCenter);
404 if (isset($attachmentApiResponse->error)) {
405 $responseType = 'error';
406 }
407 $attachmentApiResponses[] = $attachmentApiResponse;
408 }
409 } else {
410 $attachmentApiResponse = $filesApiHelper->uploadFiles($fieldValues[$fileField], $portalId, $projectId, $eventKey, $eventId, $dataCenter);
411 if (isset($attachmentApiResponse->error)) {
412 $responseType = 'error';
413 }
414 $attachmentApiResponses[] = $attachmentApiResponse;
415 }
416 }
417 }
418 if ($fileFound) {
419 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'file', 'type_name' => $eventKey], $responseType, $attachmentApiResponses);
420 }
421 }
422
423 // Tags
424 if (isset($actions->{$eventKey}->tags) || isset($actions->{$eventKey}->customTags)) {
425 $tag_ids = '';
426 if (isset($actions->{$eventKey}->customTags) && count($actions->{$eventKey}->customTags)) {
427 $tags = [];
428 foreach ($actions->{$eventKey}->customTags as $tag) {
429 $tag_found = 0;
430 $tag_name = FieldValueHandler::replaceFieldWithValue($tag->name, $fieldValues);
431
432 $old_tags = $this->getAllTags($dataCenter, $portalId)->tags;
433
434 foreach ($old_tags as $old_tag) {
435 if ($old_tag->name === $tag_name) {
436 $tag_ids .= ($tag_ids ? ',' : '') . $old_tag->id;
437 $tag_found = 1;
438 break;
439 }
440 }
441
442 if (!$tag_found) {
443 $tags[] = (object) [
444 'name' => $tag_name,
445 'color_class' => $tag->color ? $tag->color : 'bg15a8e2'
446 ];
447 }
448 }
449 if (count($tags)) {
450 $data['tags'] = wp_json_encode($tags);
451 $apiResponse = $this->createTags($dataCenter, $portalId, $data);
452 if (isset($apiResponse->error)) {
453 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'tag', 'type_name' => $eventKey], 'error', $apiResponse);
454 } else {
455 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'tag', 'type_name' => $eventKey], 'success', $apiResponse);
456 }
457
458 foreach ($apiResponse->tags as $tag) {
459 $tag_ids .= ($tag_ids ? ',' : '') . $tag->id;
460 }
461 }
462 }
463
464 if (isset($actions->{$eventKey}->tags)) {
465 $tags = explode(',', $actions->{$eventKey}->tags);
466 foreach ($tags as $tag) {
467 $tag_name = FieldValueHandler::replaceFieldWithValue($tag, $fieldValues);
468 $tag_ids .= (!empty($tag_ids) ? ',' : '') . $tag_name;
469 }
470 }
471
472 $tagEntitySeq = ['project' => 2, 'milestone' => 3, 'tasklist' => 4, 'task' => 5, 'subtask' => 5, 'issue' => 6];
473 $data = [
474 'tag_id' => $tag_ids,
475 'entity_id' => $eventId,
476 'entityType' => $tagEntitySeq[$eventKey]
477 ];
478
479 $apiResponse = $this->associateTags($dataCenter, $portalId, $projectId, $data);
480 if (isset($apiResponse->error)) {
481 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'tag', 'type_name' => $eventKey], 'error', $apiResponse);
482 } else {
483 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'tag', 'type_name' => $eventKey], 'success', (object) ['code' => 200, 'message' => 'tags associated successfully']);
484 }
485 }
486
487 // Time Log
488 if (isset($actions->{$eventKey}->timelog)) {
489 $timelog = $actions->{$eventKey}->timelog;
490 if (isset($timelog->date_fld)) {
491 $timelog->date = FieldValueHandler::replaceFieldWithValue($timelog->date_fld, $fieldValues);
492 }
493 if (isset($timelog->hours_fld)) {
494 $timelog->hours = FieldValueHandler::replaceFieldWithValue($timelog->hours_fld, $fieldValues);
495 }
496 if (isset($timelog->notes_fld)) {
497 $timelog->notes = FieldValueHandler::replaceFieldWithValue($timelog->notes_fld, $fieldValues);
498 }
499 if (isset($timelog->start_time_fld)) {
500 $timelog->start_time = FieldValueHandler::replaceFieldWithValue($timelog->start_time_fld, $fieldValues);
501 }
502 if (isset($timelog->end_time_fld)) {
503 $timelog->end_time = FieldValueHandler::replaceFieldWithValue($timelog->end_time_fld, $fieldValues);
504 }
505
506 if (isset($timelog->start_time, $timelog->end_time)) {
507 $diff = abs(strtotime($timelog->end_time) - strtotime($timelog->start_time));
508 $tmins = $diff / 60;
509 $hours = floor($tmins / 60);
510 $mins = $tmins % 60;
511 $timelog->hours = "{$hours}:{$mins}";
512 }
513
514 unset($timelog->date_fld, $timelog->hours_fld, $timelog->notes_fld, $timelog->start_time, $timelog->start_time_fld, $timelog->end_time, $timelog->end_time_fld, $timelog->settime);
515
516 $timelog->date = date_format(date_create($timelog->date), 'm-d-Y');
517 $timelog->notes = $timelog->notes;
518 if (!isset($timelog->hours)) {
519 $timelog->hours = '0';
520 }
521 $apiResponse = $this->addTimeLog($dataCenter, $portalId, $projectId, $eventKey, $eventId, $timelog);
522 if (isset($apiResponse->error)) {
523 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'timelog', 'type_name' => $eventKey], 'error', $apiResponse);
524 } else {
525 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'timelog', 'type_name' => $eventKey], 'success', $apiResponse);
526 }
527 // var_dump($apiResponse);
528 }
529 }
530 // Actions End
531 }
532 }
533