PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Entity/Form/Form.php +174 -24 0.6 → 1.5 View file →
@@ -1,20 +1,18 @@
1 1 <?php
2 2
3 3 /**
4 - * @copyright © TMS-Plugins. All rights reserved.
4 + * @copyright © Melograno Venture Studio. All rights reserved.
5 5 * @licence See LICENCE.md for license details.
6 6 */
7 7
8 8 namespace IvyForms\Entity\Form;
9 9
10 -// phpcs:disable PSR1.Files.SideEffects
11 -if (!defined('ABSPATH')) {
12 - exit; // Exit if accessed directly
13 -}
14 -
15 10 use IvyForms\ValueObjects\Form\Form as FormValueObject;
16 11 use IvyForms\ValueObjects\Form\IntegrationSettings;
12 +use IvyForms\ValueObjects\Form\PaymentSettings;
13 +use IvyForms\ValueObjects\Form\StyleSettings;
14 +use IvyForms\Services\Template\TemplateDefaults;
17 15
18 16 /**
19 17 * Class Form
20 18 *
@@ -27,8 +25,15 @@
27 25 */
28 26 private FormValueObject $form;
29 27
30 28 /**
29 + * Top-level extension keys (e.g. Pro settings) for the request lifecycle.
30 + *
31 + * @var array<string, mixed>
32 + */
33 + private array $extensionData = [];
34 +
35 + /**
31 36 * Form constructor.
32 37 *
33 38 * @param FormValueObject $form The form object.
34 39 */
@@ -37,8 +42,24 @@
37 42 $this->form = $form;
38 43 }
39 44
40 45 /**
46 + * @param array<string, mixed> $data
47 + */
48 + public function setExtensionData(array $data): void
49 + {
50 + $this->extensionData = $data;
51 + }
52 +
53 + /**
54 + * @return array<string, mixed>
55 + */
56 + public function getExtensionData(): array
57 + {
58 + return $this->extensionData;
59 + }
60 +
61 + /**
41 62 * Get the ID of the form.
42 63 *
43 64 * @return int The form ID.
44 65 */
@@ -77,8 +98,24 @@
77 98 $this->form->name = $name;
78 99 }
79 100
80 101 /**
102 + * @return string classic|conversational
103 + */
104 + public function getFormType(): string
105 + {
106 + return $this->form->getFormType();
107 + }
108 +
109 + /**
110 + * @param string $formType
111 + */
112 + public function setFormType(string $formType): void
113 + {
114 + $this->form->setFormType($formType);
115 + }
116 +
117 + /**
81 118 * Get the author of the form.
82 119 *
83 120 * @return string The form author.
84 121 */
@@ -83,9 +120,9 @@
83 120 * @return string The form author.
84 121 */
85 122 public function getAuthor(): string
86 123 {
87 - return $this->form->getAuthor();
124 + return $this->form->metadata->getAuthor();
88 125 }
89 126
90 127 /**
91 128 * Set the author of the form.
@@ -93,9 +130,9 @@
93 130 * @param string $author The form author to set.
94 131 */
95 132 public function setAuthor(string $author): void
96 133 {
97 - $this->form->author = $author;
134 + $this->form->metadata->author = $author;
98 135 }
99 136
100 137 /**
101 138 * Get the starred status of the form.
@@ -103,9 +140,9 @@
103 140 * @return bool The form starred status.
104 141 */
105 142 public function isStarred(): bool
106 143 {
107 - return $this->form->isStarred();
144 + return $this->form->metadata->isStarred();
108 145 }
109 146
110 147 /**
111 148 * Set the starred status of the form.
@@ -113,9 +150,9 @@
113 150 * @param bool $starred The form starred status to set.
114 151 */
115 152 public function setStarred(bool $starred): void
116 153 {
117 - $this->form->starred = $starred;
154 + $this->form->metadata->starred = $starred;
118 155 }
119 156
120 157 /**
121 158 * Get the published status of the form.
@@ -123,9 +160,9 @@
123 160 * @return bool The form published status.
124 161 */
125 162 public function isPublished(): bool
126 163 {
127 - return $this->form->isPublished();
164 + return $this->form->metadata->isPublished();
128 165 }
129 166
130 167 /**
131 168 * Set the published status of the form.
@@ -133,9 +170,9 @@
133 170 * @param bool $published The form published status to set.
134 171 */
135 172 public function setPublished(bool $published): void
136 173 {
137 - $this->form->published = $published;
174 + $this->form->metadata->published = $published;
138 175 }
139 176
140 177 /**
141 178 * Get the creation date of the form.
@@ -143,9 +180,9 @@
143 180 * @return string The form of date creation.
144 181 */
145 182 public function getDateCreated(): string
146 183 {
147 - return $this->form->getDateCreated();
184 + return $this->form->metadata->getDateCreated();
148 185 }
149 186 /**
150 187 * Get the date edited of the form.
151 188 *
@@ -152,9 +189,9 @@
152 189 * @return string The form date edited.
153 190 */
154 191 public function getDateEdited(): string
155 192 {
156 - return $this->form->getDateEdited();
193 + return $this->form->metadata->getDateEdited();
157 194 }
158 195
159 196 /**
160 197 * Get the form fields.
@@ -202,9 +239,9 @@
202 239 * @return bool The form show title status.
203 240 */
204 241 public function isTitleVisible(): bool
205 242 {
206 - return $this->form->isTitleVisible();
243 + return $this->form->settings->isShowTitle();
207 244 }
208 245
209 246 /**
210 247 * Set the show title of the form.
@@ -212,9 +249,9 @@
212 249 * @param bool $showTitle The form show title to set.
213 250 */
214 251 public function setTitleVisible(bool $showTitle): void
215 252 {
216 - $this->form->showTitle = $showTitle;
253 + $this->form->settings->showTitle = $showTitle;
217 254 }
218 255 /**
219 256 * Get the show description of the form.
220 257 *
@@ -221,12 +258,10 @@
221 258 * @return bool The form show description status.
222 259 */
223 260 public function isDescriptionVisible(): bool
224 261 {
225 - return $this->form->isDescriptionVisible();
262 + return $this->form->settings->isShowDescription();
226 263 }
227 -
228 -
229 264 /**
230 265 * Set the show description of the form.
231 266 *
232 267 * @param bool $description The form show title to set.
@@ -232,13 +267,12 @@
232 267 * @param bool $description The form show title to set.
233 268 */
234 269 public function setDescriptionVisible(bool $description): void
235 270 {
236 - $this->form->showDescription = $description;
271 + $this->form->settings->showDescription = $description;
237 272 }
238 273
239 274 /**
240 - *
241 275 * Set whether to store entries or not.
242 276 *
243 277 * @param bool $storeEntries
244 278 * @return void
@@ -244,9 +278,9 @@
244 278 * @return void
245 279 */
246 280 public function setStoreEntries(bool $storeEntries): void
247 281 {
248 - $this->form->storeEntries = $storeEntries;
282 + $this->form->settings->storeEntries = $storeEntries;
249 283 }
250 284 /**
251 285 *
252 286 * Get whether to store entries or not.
@@ -254,9 +288,9 @@
254 288 * @return bool
255 289 */
256 290 public function isStoreEntries(): bool
257 291 {
258 - return $this->form->storeEntries;
292 + return $this->form->settings->isStoreEntries();
259 293 }
260 294
261 295 /**
262 296 * Get integration settings.
@@ -275,8 +309,109 @@
275 309 $this->form->integrationSettings = $settings;
276 310 }
277 311
278 312 /**
313 + * Get pages.
314 + * @return array<int, array<string, mixed>> The pages array.
315 + */
316 + public function getPages(): array
317 + {
318 + return $this->form->pages ?? [];
319 + }
320 +
321 + /**
322 + * Set pages.
323 + * @param array<int, array<string, mixed>> $pages The pages array to set.
324 + */
325 + public function setPages(array $pages): void
326 + {
327 + $this->form->pages = $pages;
328 + }
329 +
330 + /**
331 + * Get progress indicator settings.
332 + * @return array<string, mixed> The progress indicator settings.
333 + */
334 + public function getProgressIndicator(): array
335 + {
336 + return $this->form->progressIndicator ?? [];
337 + }
338 +
339 + /**
340 + * Set progress indicator settings.
341 + * @param array<string, mixed> $progressIndicator The progress indicator settings to set.
342 + */
343 + public function setProgressIndicator(array $progressIndicator): void
344 + {
345 + $this->form->progressIndicator = $progressIndicator;
346 + }
347 +
348 + /**
349 + * Get form action buttons settings.
350 + *
351 + * @return array<string, mixed> The form action buttons settings.
352 + */
353 + public function getFormActionButtons(): array
354 + {
355 + return $this->form->formActionButtons;
356 + }
357 +
358 + /**
359 + * Set form action buttons settings.
360 + *
361 + * @param array<string, mixed> $formActionButtons The form action buttons settings to set.
362 + * @return void
363 + */
364 + public function setFormActionButtons(array $formActionButtons): void
365 + {
366 + $this->form->formActionButtons = $formActionButtons;
367 + }
368 +
369 + /**
370 + * Get payment-related form settings (e.g., currency).
371 + */
372 + public function getPaymentSettings(): PaymentSettings
373 + {
374 + return $this->form->getPaymentSettings();
375 + }
376 +
377 + /**
378 + * Set payment-related form settings.
379 + */
380 + public function setPaymentSettings(PaymentSettings $paymentSettings): void
381 + {
382 + $this->form->setPaymentSettings($paymentSettings);
383 + }
384 +
385 + /**
386 + * Get style settings as array
387 + *
388 + * @return array<string, mixed>
389 + */
390 + public function getStyleSettings(): array
391 + {
392 + $settings = $this->form->getStyleSettings();
393 + if (null === $settings) {
394 + return TemplateDefaults::getDefaultFormStylesSafe();
395 + }
396 + return $settings->getAll();
397 + }
398 +
399 + /**
400 + * Set style settings from array (wraps {@see StyleSettings} like integration settings).
401 + *
402 + * @param array<string, mixed>|null $settings The style settings to set.
403 + */
404 + public function setStyleSettings(?array $settings): void
405 + {
406 + if (null === $settings) {
407 + $this->form->setStyleSettings(null);
408 + return;
409 + }
410 + $this->form->setStyleSettings(new StyleSettings($settings));
411 + }
412 +
413 + /**
279 414 * Convert the form entity to an array.
280 415 *
281 416 * @return array<string, mixed> The form entity as an array.
282 417 */
@@ -281,8 +416,13 @@
281 416 * @return array<string, mixed> The form entity as an array.
282 417 */
283 418 public function toArray(): array
284 419 {
420 + $integrationSettings = $this->getIntegrationSettings();
421 + $integrationPayload = $integrationSettings !== null
422 + ? $integrationSettings->toArray()
423 + : ['integrationSettings' => TemplateDefaults::getDefaultIntegrationSettings()];
424 +
285 425 $data = array_merge(
286 426 [
287 427 'id' => $this->getId(),
288 428 'name' => $this->getName(),
@@ -292,13 +432,23 @@
292 432 'dateCreated' => $this->getDateCreated(),
293 433 'dateEdited' => $this->getDateEdited(),
294 434 'fields' => $this->getFields(),
295 435 'description' => $this->getDescription(),
436 + 'formType' => $this->getFormType(),
296 437 'showTitle' => $this->isTitleVisible(),
297 438 'showDescription' => $this->isDescriptionVisible(),
298 439 'storeEntries' => $this->isStoreEntries(),
440 + 'pages' => $this->getPages(),
441 + 'progressIndicator' => $this->getProgressIndicator(),
442 + 'styleSettings' => $this->getStyleSettings(),
443 + 'formActionButtons' => $this->getFormActionButtons(),
299 444 ],
300 - $this->getIntegrationSettings()->toArray()
445 + $this->form->metadata->toArray(),
446 + $this->form->settings->toArray(),
447 + $integrationPayload,
448 + $this->extensionData,
449 + $this->getPaymentSettings()->toArray()
301 450 );
451 +
302 452 return $data;
303 453 }
304 454 }