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 / Autonami / 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/Autonami/RecordApiHelper.php

89 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Autonami Record Api
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\Autonami;
9
10 use BitCode\BitForm\Core\Util\ApiResponse as UtilApiResponse;
11 use BWF_Contacts;
12 use BWFCRM_Contact;
13
14 /**
15 * Provide functionality for Record insert
16 */
17 class RecordApiHelper
18 {
19 private $_integrationID;
20 private $_logID;
21 private $_logResponse;
22
23 public function __construct($integId, $logID, $entryID)
24 {
25 $this->_integrationID = $integId;
26 $this->_logID = $logID;
27 $this->_logResponse = new UtilApiResponse();
28 }
29
30 public function insertRecord($data, $actions)
31 {
32 $contact_obj = BWF_Contacts::get_instance();
33 $contact = $contact_obj->get_contact_by('email', $data['email']);
34 $userExist = (absint($contact->get_id()) > 0);
35
36 if ($userExist && isset($actions->skip_if_exists) && $actions->skip_if_exists) {
37 $response = ['success' => false, 'messages' => 'Contact already exists!'];
38 } else {
39 foreach ($data as $key => $item) {
40 $obj = 'set_' . $key;
41 $contact->$obj($item);
42 }
43 $contact->set_status(1);
44 $contact->save();
45
46 $customContact = new BWFCRM_Contact($data['email']);
47 foreach ($data as $key => $item) {
48 if ('address' === $key) {
49 $key = 'address-1';
50 }
51 $customContact->set_field_by_slug($key, $item);
52 }
53 $customContact->save_fields();
54
55 if (absint($contact->get_id()) > 0) {
56 $response = ['success' => true, 'messages' => 'Insert successfully!'];
57 } else {
58 $response = ['success' => false, 'messages' => 'Something wrong!'];
59 }
60 }
61 return $response;
62 }
63
64 public function executeRecordApi($fieldValues, $fieldMap, $actions, $lists, $tags)
65 {
66 $fieldData = [];
67 foreach ($fieldMap as $fieldPair) {
68 if (!empty($fieldPair->autonamiField)) {
69 if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) {
70 $fieldData[$fieldPair->autonamiField] = $fieldPair->customValue;
71 } else {
72 $fieldData[$fieldPair->autonamiField] = is_array($fieldValues[$fieldPair->formField]) ? json_encode($fieldValues[$fieldPair->formField]) : $fieldValues[$fieldPair->formField];
73 }
74 }
75 }
76 $fieldData['lists'] = $lists;
77 $fieldData['tags'] = $tags;
78
79 $recordApiResponse = $this->insertRecord($fieldData, $actions);
80
81 if ($recordApiResponse['success']) {
82 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'success', $recordApiResponse);
83 } else {
84 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', $recordApiResponse);
85 }
86 return $recordApiResponse;
87 }
88 }
89