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
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 / Migration / MigrationHelper.php

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

214 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Migration;
4
5 class MigrationHelper {
6 public static function setNestedProperty(&$rootObj, $properties, $value) {
7 $firstProperty = array_shift($properties);
8 $current = &$rootObj;
9
10 if (is_object($current)) {
11 if (!property_exists($current, $firstProperty)) {
12 $current->$firstProperty = (object)[];
13 }
14 if (count($properties) > 0) {
15 self::setNestedProperty($current->$firstProperty, $properties, $value);
16 } else {
17 $current->$firstProperty = $value;
18 }
19 } elseif (is_array($current)) {
20 if (!array_key_exists($firstProperty, $current)) {
21 $current[$firstProperty] = [];
22 }
23 if (count($properties) > 0) {
24 self::setNestedProperty($current[$firstProperty], $properties, $value);
25 } else {
26 $current[$firstProperty] = $value;
27 }
28 }
29 }
30
31 public static function getNestedPropertyValue($rootObj, $properties) {
32 $firstProperty = array_shift($properties);
33 $current = $rootObj;
34 if (is_object($current) && count($properties) > 0) {
35 return self::getNestedPropertyValue($current->$firstProperty, $properties);
36 } elseif (is_object($current)) {
37 return property_exists($current, $firstProperty) ? $current->$firstProperty : null;
38 } elseif (is_array($current) && count($properties) > 0) {
39 return self::getNestedPropertyValue($current[$firstProperty], $properties);
40 } elseif (is_array($current)) {
41 return array_key_exists($firstProperty, $current) ? $current[$firstProperty] : null;
42 }
43 }
44
45 public static function optionListConvert($optionList) {
46 $newOptionList = [];
47 foreach ($optionList as $option) {
48 $newOpt = (object)[];
49 if (isset($option->label)) {
50 $newOpt->lbl = $option->label;
51 }
52 if (isset($option->value)) {
53 $newOpt->val = $option->value;
54 }
55 if (isset($option->code)) {
56 $newOpt->i = $option->code;
57 }
58 if (isset($option->prefix_img)) {
59 $newOpt->img = str_replace('/v1', '', BITFORMS_ASSET_URI . $option->prefix_img);
60 }
61 $newOptionList[] = $newOpt;
62 }
63 return $newOptionList;
64 }
65
66 public static function convertFields($fieldsArray) {
67 $conversionFormate = new FieldsConversionFormate();
68 $newFieldsArray = [];
69
70 foreach ($fieldsArray as $fieldKey => $field) {
71 // print_r(gettype($field));
72 $convertFormate = $conversionFormate->getFormate($field->typ);
73 $newFieldProperty = [];
74
75 // convert unchange property
76 foreach ($convertFormate['unchangeProperty'] as $property) {
77 if (property_exists($field, $property)) {
78 $newFieldProperty[$property] = $field->{$property};
79 }
80 }
81
82 // add new property
83 foreach ($convertFormate['newProperty'] as $property => $value) {
84 $properties = explode('->', $property);
85 self::setNestedProperty($newFieldProperty, $properties, $value);
86 }
87
88 // modify changed property
89 foreach ($convertFormate['changedProperty'] as $oldProperty => $newPropertyArr) {
90 $properties = explode('->', $oldProperty);
91 $value = self::getNestedPropertyValue($field, $properties);
92 foreach ($newPropertyArr as $newProperty) {
93 if (is_null($value) && isset($newProperty['val'])) {
94 $value = $newProperty['val'];
95 }
96 if (isset($newProperty['isEqualTo']) && $value === $newProperty['isEqualTo']) {
97 $value = $newProperty['val'];
98 } elseif (isset($newProperty['isEqualTo'])) {
99 continue;
100 }
101 if (!is_null($value)) {
102 $properties = explode('->', $newProperty['path']);
103 self::setNestedProperty($newFieldProperty, $properties, $value);
104 }
105 }
106 }
107 $newFieldProperty['fieldName'] .= "-$fieldKey";
108
109 if ('select' === $newFieldProperty['typ']) {
110 $newFieldProperty['optionsList'][0]['List-1'] = self::optionListConvert($field->opt);
111 if (isset($newFieldProperty['val']) && is_array($newFieldProperty['val'])) {
112 $newFieldProperty['val'] = implode(BITFORMS_BF_SEPARATOR, $newFieldProperty['val']);
113 }
114 if (isset($field->opt[0]->prefix_img) && !is_null($field->opt[0]->prefix_img)) {
115 $newFieldProperty['config']['optionIcon'] = true;
116 }
117 }
118 $newFieldsArray[$fieldKey] = $newFieldProperty;
119 }
120
121 return $newFieldsArray;
122 }
123
124 public static function convertLayout($layoutObj) {
125 $newLayoutArray = [];
126
127 foreach ($layoutObj as $breakdownSize => $layoutArr) {
128 // v1 width variation
129 $v1WidthVariation = [
130 'lg' => 6,
131 'md' => 4,
132 'sm' => 2,
133 ];
134 $v2Width = 60;
135 $v2RowHeight = 43;
136
137 $newLayoutArray[$breakdownSize] = [];
138 foreach ($layoutArr as $index => $fieldLayout) {
139 $fieldLayout->w = $fieldLayout->w * ($v2Width / $v1WidthVariation[$breakdownSize]);
140 $fieldLayout->x = $fieldLayout->x * ($v2Width / $v1WidthVariation[$breakdownSize]);
141 $fieldLayout->h = $fieldLayout->h * $v2RowHeight;
142 $fieldLayout->y = $fieldLayout->y * $v2RowHeight;
143 unset($fieldLayout->minH, $fieldLayout->maxH);
144 $newLayoutArray[$breakdownSize][] = $fieldLayout;
145 }
146 }
147 return $newLayoutArray;
148 }
149
150 public static function convertSuccessMessage($successMessageArr) {
151 $newSuccessMessageArr = [];
152
153 // this config is set as snackbar in bottom right corner
154 $defaultMessageConfig = [
155 'msgType' => 'snackbar',
156 'position' => 'bottom-right',
157 'animation'=> 'slide-up',
158 'autoHide' => true,
159 'duration' => 3,
160 'styles' => [
161 'width' => '300px',
162 'padding' => '10px 35px 10px 20px',
163 'background' => '#383838',
164 'color' => '#fff',
165 'borderWidth' => '1px',
166 'borderType' => 'none',
167 'borderColor' => 'var(--bg-5)',
168 'borderRadius'=> 'var(--g-bdr-rad)',
169 'boxShadow' => [
170 [
171 'x' => '0px',
172 'y' => '27px',
173 'blur' => '30px',
174 'spread'=> '',
175 'color' => 'rgb(0 0 0 / 18%)',
176 'inset' => ''
177 ]
178 ],
179 'closeBackground'=> '#666',
180 'closeHover' => 'var(--bg-10)',
181 'closeIconColor' => '#fff',
182 'closeIconHover' => 'var(--bg-50)'
183 ]
184 ];
185 foreach ($successMessageArr as $message) {
186 $message->config = $defaultMessageConfig;
187 $newSuccessMessageArr[] = $message;
188 }
189 return $newSuccessMessageArr;
190 }
191
192 public static function recursiveDeleteFiles($src) {
193 if (is_file($src)) {
194 return unlink($src);
195 } elseif (is_dir($src)) {
196 $scan = glob(rtrim($src, '/') . '/*');
197 foreach ($scan as $path) {
198 self::recursiveDeleteFiles($path);
199 }
200 }
201 }
202
203 public static function recursiveCopyFiles($src, $dst) {
204 if (is_file($src) && !is_dir($dst)) {
205 return copy($src, $dst);
206 } elseif (is_dir($src)) {
207 $scan = glob(rtrim($src, '/') . '/*');
208 foreach ($scan as $path) {
209 self::recursiveCopyFiles($path, $dst . '/' . basename($path));
210 }
211 }
212 }
213 }
214