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

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

85 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 private $_integrationID;
19 private $_logID;
20 private $_logResponse;
21
22 public function __construct($integId, $logID, $entryID) {
23 $this->_integrationID = $integId;
24 $this->_logID = $logID;
25 $this->_logResponse = new UtilApiResponse();
26 }
27
28 public function insertRecord($data, $actions) {
29 $contact_obj = BWF_Contacts::get_instance();
30 $contact = $contact_obj->get_contact_by('email', $data['email']);
31 $userExist = (absint($contact->get_id()) > 0);
32
33 if ($userExist && isset($actions->skip_if_exists) && $actions->skip_if_exists) {
34 $response = ['success' => false, 'messages' => 'Contact already exists!'];
35 } else {
36 foreach ($data as $key => $item) {
37 $obj = 'set_' . $key;
38 $contact->$obj($item);
39 }
40 $contact->set_status(1);
41 $contact->save();
42
43 $customContact = new BWFCRM_Contact($data['email']);
44 foreach ($data as $key => $item) {
45 if ('address' === $key) {
46 $key = 'address-1';
47 }
48 $customContact->set_field_by_slug($key, $item);
49 }
50 $customContact->save_fields();
51
52 if (absint($contact->get_id()) > 0) {
53 $response = ['success' => true, 'messages' => 'Insert successfully!'];
54 } else {
55 $response = ['success' => false, 'messages' => 'Something wrong!'];
56 }
57 }
58 return $response;
59 }
60
61 public function executeRecordApi($fieldValues, $fieldMap, $actions, $lists, $tags) {
62 $fieldData = [];
63 foreach ($fieldMap as $fieldPair) {
64 if (!empty($fieldPair->autonamiField)) {
65 if ('custom' === $fieldPair->formField && isset($fieldPair->customValue)) {
66 $fieldData[$fieldPair->autonamiField] = $fieldPair->customValue;
67 } else {
68 $fieldData[$fieldPair->autonamiField] = is_array($fieldValues[$fieldPair->formField]) ? json_encode($fieldValues[$fieldPair->formField]) : $fieldValues[$fieldPair->formField];
69 }
70 }
71 }
72 $fieldData['lists'] = $lists;
73 $fieldData['tags'] = $tags;
74
75 $recordApiResponse = $this->insertRecord($fieldData, $actions);
76
77 if ($recordApiResponse['success']) {
78 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'success', $recordApiResponse);
79 } else {
80 $this->_logResponse->apiResponse($this->_logID, $this->_integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', $recordApiResponse);
81 }
82 return $recordApiResponse;
83 }
84 }
85