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

536 lines 23.7 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 (date('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 // Map Field & Actions Start
166 foreach ($subEvent as $sEvent) {
167 $required = $projectsConf->default->fields->{$portalId}->{$sEvent}->required;
168 // Field Mapping
169 foreach ($fieldMap->{$sEvent} as $fieldKey => $fieldPair) {
170 if (!empty($fieldPair->zohoFormField)) {
171 if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) {
172 if ('cf' === strtok($fieldPair->zohoFormField, '_')) {
173 $fieldPair->zohoFormField = str_replace('cf_', '', $fieldPair->zohoFormField);
174 $fieldData[$sEvent]['custom_fields'][$fieldPair->zohoFormField] = $this->testDate($fieldPair->customValue) ? date_format(date_create($fieldPair->customValue), 'm-d-Y') : $fieldPair->customValue;
175 } else {
176 $fieldData[$sEvent][$fieldPair->zohoFormField] = $this->testDate($fieldPair->customValue) ? date_format(date_create($fieldPair->customValue), 'm-d-Y') : $fieldPair->customValue;
177 }
178 } else {
179 if ('cf' === strtok($fieldPair->zohoFormField, '_')) {
180 $fieldPair->zohoFormField = str_replace('cf_', '', $fieldPair->zohoFormField);
181 $fieldData[$sEvent]['custom_fields'][$fieldPair->zohoFormField] = $this->testDate($fieldValues[$fieldPair->formField]) ? date_format(date_create($fieldValues[$fieldPair->formField]), 'm-d-Y') : $fieldValues[$fieldPair->formField];
182 } else {
183 $fieldData[$sEvent][$fieldPair->zohoFormField] = $this->testDate($fieldValues[$fieldPair->formField]) ? date_format(date_create($fieldValues[$fieldPair->formField]), 'm-d-Y') : $fieldValues[$fieldPair->formField];
184 }
185 }
186 }
187 if (empty($fieldData[$sEvent][$fieldPair->zohoFormField]) && \in_array($fieldPair->zohoFormField, $required)) {
188 $error = new WP_Error('REQ_FIELD_EMPTY', wp_sprintf(__('%s is required for %s', 'bit-form'), $fieldPair->zohoFormField, $sEvent));
189 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'field'], 'validation', $error);
190 return $error;
191 }
192 }
193
194 if (isset($fieldData[$sEvent]['custom_fields'])) {
195 $fieldData[$sEvent]['custom_fields'] = json_encode($fieldData[$sEvent]['custom_fields']);
196 }
197
198 // Actions Mapping
199 foreach ($actions->{$sEvent} as $fieldKey => $action) {
200 if (in_array($fieldKey, ['tags', 'attachments', 'users', 'timelog', 'bug_followers'])) {
201 continue;
202 }
203 if (('object' === gettype($action) && count((array) $action)) || ('string' === gettype($action) && !empty($action))) {
204 if ('owner' === $fieldKey) {
205 if ('task' === $sEvent || 'subtask' === $sEvent) {
206 $fieldData[$sEvent]['person_responsible'] = $action;
207 } elseif ('issue' === $sEvent) {
208 $fieldData[$sEvent]['assignee'] = $action;
209 } else {
210 $fieldData[$sEvent]['owner'] = $action;
211 }
212 } elseif ('reminder_string' === $fieldKey && !empty($action->reminder_criteria)) {
213 if (isset($action->custom_date_fld)) {
214 $action->custom_date = FieldValueHandler::replaceFieldWithValue($action->custom_date_fld, $fieldValues);
215 }
216 if (isset($action->reminder_time_fld)) {
217 $action->reminder_time = FieldValueHandler::replaceFieldWithValue($action->reminder_time_fld, $fieldValues);
218 }
219
220 if (isset($action->custom_date)) {
221 $action->custom_date = date_format(date_create($action->custom_date), 'm-d-Y');
222 }
223 if (isset($action->reminder_time)) {
224 $action->reminder_time = date('H:i', strtotime($action->reminder_time));
225 }
226
227 unset($action->custom_date_fld, $action->reminder_time_fld);
228 $fieldData[$sEvent][$fieldKey] = '{"reminder":[' . wp_json_encode($action) . ']}';
229 } elseif ('recurrence_string' === $fieldKey && !empty($action->recurring_frequency)) {
230 if (isset($action->time_span_fld)) {
231 $action->time_span = FieldValueHandler::replaceFieldWithValue($action->time_span_fld, $fieldValues);
232 }
233 if (isset($action->number_of_occurrences_fld)) {
234 $action->number_of_occurrences = FieldValueHandler::replaceFieldWithValue($action->number_of_occurrences_fld, $fieldValues);
235 }
236 unset($action->time_span_fld, $action->number_of_occurrences_fld);
237 if (!isset($action->time_span)) {
238 $action->time_span = '1';
239 }
240 if (!isset($action->number_of_occurrences)) {
241 $action->number_of_occurrences = '2';
242 }
243 if (!isset($action->is_comments_recurred)) {
244 $action->is_comments_recurred = 'false';
245 }
246 if (!isset($action->set_previous_business_day)) {
247 $action->set_previous_business_day = 'false';
248 }
249 if (!isset($action->recurrence_type)) {
250 $action->recurrence_type = 'specified_interval_creation';
251 }
252
253 $fieldData[$sEvent]['json_string'] = '{"recurrence":' . wp_json_encode($action) . '}';
254 } else {
255 $fieldData[$sEvent][$fieldKey] = $action;
256 }
257 }
258 }
259 }
260 // Map Field & Actions End
261
262 // Create Events Start
263 $data = null;
264 if (in_array('project', $subEvent)) {
265 $apiResponse = $this->createProject($dataCenter, $portalId, $fieldData['project']);
266
267 if (isset($apiResponse->error)) {
268 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'project'], 'error', $apiResponse);
269 return new WP_Error('project not created');
270 } else {
271 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'project'], 'success', $apiResponse);
272 }
273
274 $eventApiResponse['project'] = $apiResponse->projects[0]->id_string;
275
276 if (isset($actions->project->users)) {
277 foreach ($actions->project->users as $user) {
278 $data = [
279 'email' => $user->email,
280 'role' => $user->role
281 ];
282
283 $apiResponse = $this->associateUsers($dataCenter, $portalId, $eventApiResponse['project'], $data);
284
285 if (isset($apiResponse->error)) {
286 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'user', 'type_name' => 'project'], 'error', $apiResponse);
287 } else {
288 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'user', 'type_name' => 'project'], 'success', $apiResponse);
289 }
290 }
291 }
292 }
293
294 if (isset($projectsConf->projectId) && $projectsConf->projectId) {
295 $projectId = $projectsConf->projectId;
296 } else {
297 $projectId = $eventApiResponse['project'];
298 }
299
300 if (in_array('milestone', $subEvent)) {
301 $apiResponse = $this->createMilestone($dataCenter, $portalId, $projectId, $fieldData['milestone']);
302 $eventApiResponse['milestone'] = $apiResponse->milestones[0]->id_string;
303 if (isset($apiResponse->error)) {
304 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'milestone'], 'error', $apiResponse);
305 return new WP_Error('milestone not created');
306 } else {
307 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'milestone'], 'success', $apiResponse);
308 }
309 }
310
311 if (in_array('tasklist', $subEvent)) {
312 if (isset($projectsConf->milestoneId) && $projectsConf->milestoneId) {
313 $fieldData['tasklist']['milestone_id'] = $projectsConf->milestoneId;
314 } elseif (array_key_exists('milestone', $eventApiResponse)) {
315 $fieldData['tasklist']['milestone_id'] = $eventApiResponse['milestone'];
316 }
317 $apiResponse = $this->createTasklist($dataCenter, $portalId, $projectId, $fieldData['tasklist']);
318 $eventApiResponse['tasklist'] = $apiResponse->tasklists[0]->id_string;
319 if (isset($apiResponse->error)) {
320 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'tasklist'], 'error', $apiResponse);
321 return new WP_Error('tasklist not created');
322 } else {
323 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'tasklist'], 'success', $apiResponse);
324 }
325 }
326
327 if (in_array('task', $subEvent)) {
328 if (isset($projectsConf->tasklistId) && $projectsConf->tasklistId) {
329 $fieldData['task']['tasklist_id'] = $projectsConf->tasklistId;
330 } elseif (array_key_exists('tasklist', $eventApiResponse)) {
331 $fieldData['task']['tasklist_id'] = $eventApiResponse['tasklist'];
332 }
333 $apiResponse = $this->createTask($dataCenter, $portalId, $projectId, $fieldData['task']);
334 $eventApiResponse['task'] = $apiResponse->tasks[0]->id_string;
335 if (isset($apiResponse->error)) {
336 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'task'], 'error', $apiResponse);
337 return new WP_Error('task not created');
338 } else {
339 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'task'], 'success', $apiResponse);
340 }
341 }
342
343 if (in_array('subtask', $subEvent)) {
344 $taskId = '';
345 if (isset($projectsConf->taskId) && $projectsConf->taskId) {
346 $taskId = $projectsConf->taskId;
347 } else {
348 $taskId = $eventApiResponse['task'];
349 }
350 $apiResponse = $this->createSubTask($dataCenter, $portalId, $projectId, $taskId, $fieldData['subtask']);
351 $eventApiResponse['subtask'] = $apiResponse->tasks[0]->id_string;
352 if (isset($apiResponse->error)) {
353 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'subtask'], 'error', $apiResponse);
354 return new WP_Error('subtask not created');
355 } else {
356 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'subtask'], 'success', $apiResponse);
357 }
358 }
359
360 if (in_array('issue', $subEvent)) {
361 if (isset($projectsConf->milestoneId) && $projectsConf->milestoneId) {
362 $fieldData['issue']['milestone_id'] = $projectsConf->milestoneId;
363 } elseif (array_key_exists('milestone', $eventApiResponse)) {
364 $fieldData['issue']['milestone_id'] = $eventApiResponse['milestone'];
365 }
366 $apiResponse = $this->createIssue($dataCenter, $portalId, $projectId, $fieldData['issue']);
367 $eventApiResponse['issue'] = $apiResponse->bugs[0]->id_string;
368 if (isset($apiResponse->error)) {
369 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'issue'], 'error', $apiResponse);
370 return new WP_Error('issue not created');
371 } else {
372 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'issue'], 'success', $apiResponse);
373 }
374
375 if (isset($actions->issue->bug_followers)) {
376 $bug_followers = explode(',', $actions->issue->bug_followers);
377 foreach ($bug_followers as $follower) {
378 $data = [
379 'bug_followers' => $follower
380 ];
381
382 $apiResponse = $this->addBugFollower($dataCenter, $portalId, $projectId, $eventApiResponse['issue'], $data);
383 if (isset($apiResponse->error)) {
384 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'follower', 'type_name' => 'issue'], 'error', $apiResponse);
385 } else {
386 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'follower', 'type_name' => 'issue'], 'success', $apiResponse);
387 }
388 }
389 }
390 }
391 // Create Events End
392
393 // Actions Start
394 foreach ($eventApiResponse as $eventKey => $eventId) {
395 // Attachments
396 if (isset($actions->{$eventKey}->attachments)) {
397 $filesApiHelper = new FilesApiHelper($this->_tokenDetails, $formID, $entryID);
398 $fileFound = 0;
399 $responseType = 'success';
400 $attachmentApiResponses = [];
401 $attachments = explode(',', $actions->{$eventKey}->attachments);
402 foreach ($attachments as $fileField) {
403 if (isset($fieldValues[$fileField]) && !empty($fieldValues[$fileField])) {
404 $fileFound = 1;
405 if (is_array($fieldValues[$fileField])) {
406 foreach ($fieldValues[$fileField] as $singleFile) {
407 $attachmentApiResponse = $filesApiHelper->uploadFiles($singleFile, $portalId, $projectId, $eventKey, $eventId, $dataCenter);
408 if (isset($attachmentApiResponse->error)) {
409 $responseType = 'error';
410 }
411 $attachmentApiResponses[] = $attachmentApiResponse;
412 }
413 } else {
414 $attachmentApiResponse = $filesApiHelper->uploadFiles($fieldValues[$fileField], $portalId, $projectId, $eventKey, $eventId, $dataCenter);
415 if (isset($attachmentApiResponse->error)) {
416 $responseType = 'error';
417 }
418 $attachmentApiResponses[] = $attachmentApiResponse;
419 }
420 }
421 }
422 if ($fileFound) {
423 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'file', 'type_name' => $eventKey], $responseType, $attachmentApiResponses);
424 }
425 }
426
427 // Tags
428 if (isset($actions->{$eventKey}->tags) || isset($actions->{$eventKey}->customTags)) {
429 $tag_ids = '';
430 if (isset($actions->{$eventKey}->customTags) && count($actions->{$eventKey}->customTags)) {
431 $tags = [];
432 foreach ($actions->{$eventKey}->customTags as $tag) {
433 $tag_found = 0;
434 $tag_name = FieldValueHandler::replaceFieldWithValue($tag->name, $fieldValues);
435
436 $old_tags = $this->getAllTags($dataCenter, $portalId)->tags;
437
438 foreach ($old_tags as $old_tag) {
439 if ($old_tag->name === $tag_name) {
440 $tag_ids .= ($tag_ids ? ',' : '') . $old_tag->id;
441 $tag_found = 1;
442 break;
443 }
444 }
445
446 if (!$tag_found) {
447 $tags[] = (object) [
448 'name' => $tag_name,
449 'color_class' => $tag->color ? $tag->color : 'bg15a8e2'
450 ];
451 }
452 }
453 if (count($tags)) {
454 $data['tags'] = wp_json_encode($tags);
455 $apiResponse = $this->createTags($dataCenter, $portalId, $data);
456 if (isset($apiResponse->error)) {
457 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'tag', 'type_name' => $eventKey], 'error', $apiResponse);
458 } else {
459 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'tag', 'type_name' => $eventKey], 'success', $apiResponse);
460 }
461
462 foreach ($apiResponse->tags as $tag) {
463 $tag_ids .= ($tag_ids ? ',' : '') . $tag->id;
464 }
465 }
466 }
467
468 if (isset($actions->{$eventKey}->tags)) {
469 $tags = explode(',', $actions->{$eventKey}->tags);
470 foreach ($tags as $tag) {
471 $tag_name = FieldValueHandler::replaceFieldWithValue($tag, $fieldValues);
472 $tag_ids .= (!empty($tag_ids) ? ',' : '') . $tag_name;
473 }
474 }
475
476 $tagEntitySeq = ['project' => 2, 'milestone' => 3, 'tasklist' => 4, 'task' => 5, 'subtask' => 5, 'issue' => 6];
477 $data = [
478 'tag_id' => $tag_ids,
479 'entity_id' => $eventId,
480 'entityType' => $tagEntitySeq[$eventKey]
481 ];
482
483 $apiResponse = $this->associateTags($dataCenter, $portalId, $projectId, $data);
484 if (isset($apiResponse->error)) {
485 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'tag', 'type_name' => $eventKey], 'error', $apiResponse);
486 } else {
487 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'tag', 'type_name' => $eventKey], 'success', (object) ['code' => 200, 'message' => 'tags associated successfully']);
488 }
489 }
490
491 // Time Log
492 if (isset($actions->{$eventKey}->timelog)) {
493 $timelog = $actions->{$eventKey}->timelog;
494 if (isset($timelog->date_fld)) {
495 $timelog->date = FieldValueHandler::replaceFieldWithValue($timelog->date_fld, $fieldValues);
496 }
497 if (isset($timelog->hours_fld)) {
498 $timelog->hours = FieldValueHandler::replaceFieldWithValue($timelog->hours_fld, $fieldValues);
499 }
500 if (isset($timelog->notes_fld)) {
501 $timelog->notes = FieldValueHandler::replaceFieldWithValue($timelog->notes_fld, $fieldValues);
502 }
503 if (isset($timelog->start_time_fld)) {
504 $timelog->start_time = FieldValueHandler::replaceFieldWithValue($timelog->start_time_fld, $fieldValues);
505 }
506 if (isset($timelog->end_time_fld)) {
507 $timelog->end_time = FieldValueHandler::replaceFieldWithValue($timelog->end_time_fld, $fieldValues);
508 }
509
510 if (isset($timelog->start_time, $timelog->end_time)) {
511 $diff = abs(strtotime($timelog->end_time) - strtotime($timelog->start_time));
512 $tmins = $diff / 60;
513 $hours = floor($tmins / 60);
514 $mins = $tmins % 60;
515 $timelog->hours = "{$hours}:{$mins}";
516 }
517
518 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);
519
520 $timelog->date = date_format(date_create($timelog->date), 'm-d-Y');
521 $timelog->notes = $timelog->notes;
522 if (!isset($timelog->hours)) {
523 $timelog->hours = '0';
524 }
525 $apiResponse = $this->addTimeLog($dataCenter, $portalId, $projectId, $eventKey, $eventId, $timelog);
526 if (isset($apiResponse->error)) {
527 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'timelog', 'type_name' => $eventKey], 'error', $apiResponse);
528 } else {
529 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'timelog', 'type_name' => $eventKey], 'success', $apiResponse);
530 }
531 }
532 }
533 // Actions End
534 }
535 }
536