PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.13
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.13
3.3.1 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 All 138 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.21.13, at includes/Core/Integration/ZohoProjects/RecordApiHelper.php

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