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 / v1 / includes / Admin / Form / CustomFieldHandler.php

CustomFieldHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.9.1, at v1/includes/Admin/Form/CustomFieldHandler.php

226 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Handle Form Create,Update,delete Operation
5 *
6 */
7
8 namespace BitCode\BitForm\Admin\Form;
9
10 class CustomFieldHandler
11 {
12 public function updatedEntries($formEntries, $fieldDetails)
13 {
14 foreach ($formEntries['entries'] as $index => $entry) {
15 foreach ($fieldDetails as $field) {
16 $fieldKey = $field['key'];
17 if (isset($field['customType']) && !empty($entry->$fieldKey) && !empty($field['customType']->hiddenValue)) {
18 $hiddenvalue = $field['customType']->hiddenValue;
19 if ($field['customType']->fieldType == 'taxanomy_field') {
20 $hiddenvalue = $field['customType']->hiddenValue;
21 if (isset($field['mul'])) {
22 $mul = $field['mul'];
23 } else {
24 $mul = '';
25 }
26
27 $value = $this->getTermFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
28 $formEntries['entries'][$index]->$fieldKey = $value;
29 } else if ($field['customType']->fieldType == "user_field") {
30 $hiddenvalue = $field['customType']->hiddenValue;
31 if (isset($field['mul'])) {
32 $mul = $field['mul'];
33 } else {
34 $mul = '';
35 }
36
37 $value = $this->getUserFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
38 $formEntries['entries'][$index]->$fieldKey = $value;
39 } else if ($field['customType']->fieldType == "post_field") {
40 $hiddenvalue = $field['customType']->hiddenValue;
41 if (isset($field['mul'])) {
42 $mul = $field['mul'];
43 } else {
44 $mul = '';
45 }
46
47 $value = $this->getPostFieldValue($field['type'], $entry->$fieldKey, $mul, $hiddenvalue);
48 $formEntries['entries'][$index]->$fieldKey = $value;
49 }
50 }
51 }
52 }
53 return $formEntries;
54 }
55
56 public function updatedData($form_fields, $toUpdateValues)
57 {
58 foreach ($form_fields as $field) {
59 if (isset($field['customType']) && !empty($toUpdateValues[$field['key']])) {
60 if (isset($field['customType']->hiddenValue)) {
61 $hiddenvalue = $field['customType']->hiddenValue;
62 if ($field['customType']->fieldType == 'taxanomy_field') {
63 if (isset($field['mul'])) {
64 $mul = $field['mul'];
65 } else {
66 $mul = '';
67 }
68
69 $value = $this->getTermFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
70 $toUpdateValues[$field['key']] = $value;
71 } else if ($field['customType']->fieldType == "user_field") {
72 if (isset($field['mul'])) {
73 $mul = $field['mul'];
74 } else {
75 $mul = '';
76 }
77
78 $value = $this->getUserFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
79 $toUpdateValues[$field['key']] = $value;
80 } else if ($field['customType']->fieldType == "post_field") {
81 if (isset($field['mul'])) {
82 $mul = $field['mul'];
83 } else {
84 $mul = '';
85 }
86
87 $value = $this->getPostFieldValue($field['type'], $toUpdateValues[$field['key']], $mul, $hiddenvalue);
88 $toUpdateValues[$field['key']] = $value;
89 }
90 }
91 }
92 }
93 return $toUpdateValues;
94 }
95
96 public function getPostFieldValue($type, $fieldValue, $mul, $hiddenvalue)
97 {
98 $value = '';
99
100 if ($type == "select") {
101
102 if ($mul == true) {
103 $multipleValue = [];
104 foreach (explode(',', $fieldValue) as $val) {
105 $exists = get_post($val);
106 if ($exists != false) {
107 $multipleValue[] = $exists->$hiddenvalue;
108 }
109 }
110 $value = implode(",", $multipleValue);
111 } else {
112 $exists = get_post($fieldValue);
113 if ($exists != false) {
114 $value = is_array($exists->$hiddenvalue) ? $exists->$hiddenvalue : (string) $exists->$hiddenvalue;
115 }
116 }
117
118 } else if ($type == "radio" || $type == "check") {
119
120 if (is_array(json_decode($fieldValue))) {
121 $multipleValues = [];
122 foreach (json_decode($fieldValue) as $value) {
123 $exists = get_post($value);
124 if ($exists != false) {
125 $multipleValues[] = $exists->$hiddenvalue;
126 }
127 }
128 $value = json_encode($multipleValues);
129 } else {
130 $exists = get_post($fieldValue);
131 if ($exists != false) {
132 $value = $exists->$hiddenvalue;
133 }
134 }
135
136 }
137 return $value;
138 }
139
140 public function getUserFieldValue($type, $fieldValue, $mul, $hiddenvalue)
141 {
142 $value = '';
143 if ($type == "select") {
144
145 if ($mul == true) {
146 $multipleValue = [];
147 foreach (explode(',', $fieldValue) as $val) {
148 $exists = get_user_by('ID', $val);
149 if ($exists != false) {
150 $multipleValue[] = $exists->data->$hiddenvalue;
151 }
152 }
153 $value = implode(",", $multipleValue);
154 } else {
155 $exists = get_user_by('ID', $fieldValue);
156 if ($exists != false) {
157 $value = is_array($exists->data->$hiddenvalue) ? $exists->data->$hiddenvalue : (string) $exists->data->$hiddenvalue;
158 }
159 }
160
161 } else if ($type == "radio" || $type == "check") {
162
163 if (is_array(json_decode($fieldValue))) {
164 $multipleValues = [];
165 foreach (json_decode($fieldValue) as $value) {
166 $exists = get_user_by('ID', $value);
167 if ($exists != false) {
168 $multipleValues[] = $exists->data->$hiddenvalue;
169 }
170 }
171 $value = json_encode($multipleValues);
172 } else {
173 $exists = get_user_by('ID', $fieldValue);
174 if ($exists != false) {
175 $value = $exists->data->$hiddenvalue;
176 }
177 }
178
179 }
180 return $value;
181 }
182
183 public function getTermFieldValue($type, $fieldValue, $mul, $hiddenvalue)
184 {
185 $value = '';
186 if ($type == "select") {
187
188 if ($mul == true) {
189 $multipleValue = [];
190 foreach (explode(',', $fieldValue) as $val) {
191 $exists = get_term_by('term_taxonomy_id', $val);
192 if ($exists != false) {
193 $multipleValue[] = $exists->$hiddenvalue;
194 }
195 }
196 $value = implode(",", $multipleValue);
197 } else {
198 $exists = get_term_by('term_taxonomy_id', $fieldValue);
199 if ($exists != false) {
200 $value = is_array($exists->$hiddenvalue) ? $exists->$hiddenvalue : (string) $exists->$hiddenvalue;
201 }
202 }
203
204 } else if ($type == "radio" || $type == "check") {
205
206 if (is_array(json_decode($fieldValue))) {
207 $multipleValues = [];
208 foreach (json_decode($fieldValue) as $value) {
209 $exists = get_term_by('term_taxonomy_id', $value);
210 if ($exists != false) {
211 $multipleValues[] = $exists->$hiddenvalue;
212 }
213 }
214 $value = json_encode($multipleValues);
215 } else {
216 $exists = get_term_by('term_taxonomy_id', $fieldValue);
217 if ($exists != false) {
218 $value = $exists->$hiddenvalue;
219 }
220 }
221
222 }
223 return $value;
224 }
225 }
226