PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
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 +228 -32 0.1.2 → 1.5.1 View file →
@@ -1,19 +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;
11 +use IvyForms\ValueObjects\Form\IntegrationSettings;
12 +use IvyForms\ValueObjects\Form\PaymentSettings;
13 +use IvyForms\ValueObjects\Form\StyleSettings;
14 +use IvyForms\Services\Template\TemplateDefaults;
16 15
17 16 /**
18 17 * Class Form
19 18 *
@@ -26,8 +25,15 @@
26 25 */
27 26 private FormValueObject $form;
28 27
29 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 + /**
30 36 * Form constructor.
31 37 *
32 38 * @param FormValueObject $form The form object.
33 39 */
@@ -36,8 +42,24 @@
36 42 $this->form = $form;
37 43 }
38 44
39 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 + /**
40 62 * Get the ID of the form.
41 63 *
42 64 * @return int The form ID.
43 65 */
@@ -76,8 +98,24 @@
76 98 $this->form->name = $name;
77 99 }
78 100
79 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 + /**
80 118 * Get the author of the form.
81 119 *
82 120 * @return string The form author.
83 121 */
@@ -82,9 +120,9 @@
82 120 * @return string The form author.
83 121 */
84 122 public function getAuthor(): string
85 123 {
86 - return $this->form->getAuthor();
124 + return $this->form->metadata->getAuthor();
87 125 }
88 126
89 127 /**
90 128 * Set the author of the form.
@@ -92,9 +130,9 @@
92 130 * @param string $author The form author to set.
93 131 */
94 132 public function setAuthor(string $author): void
95 133 {
96 - $this->form->author = $author;
134 + $this->form->metadata->author = $author;
97 135 }
98 136
99 137 /**
100 138 * Get the starred status of the form.
@@ -102,9 +140,9 @@
102 140 * @return bool The form starred status.
103 141 */
104 142 public function isStarred(): bool
105 143 {
106 - return $this->form->isStarred();
144 + return $this->form->metadata->isStarred();
107 145 }
108 146
109 147 /**
110 148 * Set the starred status of the form.
@@ -112,9 +150,9 @@
112 150 * @param bool $starred The form starred status to set.
113 151 */
114 152 public function setStarred(bool $starred): void
115 153 {
116 - $this->form->starred = $starred;
154 + $this->form->metadata->starred = $starred;
117 155 }
118 156
119 157 /**
120 158 * Get the published status of the form.
@@ -122,9 +160,9 @@
122 160 * @return bool The form published status.
123 161 */
124 162 public function isPublished(): bool
125 163 {
126 - return $this->form->isPublished();
164 + return $this->form->metadata->isPublished();
127 165 }
128 166
129 167 /**
130 168 * Set the published status of the form.
@@ -132,9 +170,9 @@
132 170 * @param bool $published The form published status to set.
133 171 */
134 172 public function setPublished(bool $published): void
135 173 {
136 - $this->form->published = $published;
174 + $this->form->metadata->published = $published;
137 175 }
138 176
139 177 /**
140 178 * Get the creation date of the form.
@@ -142,9 +180,9 @@
142 180 * @return string The form of date creation.
143 181 */
144 182 public function getDateCreated(): string
145 183 {
146 - return $this->form->getDateCreated();
184 + return $this->form->metadata->getDateCreated();
147 185 }
148 186 /**
149 187 * Get the date edited of the form.
150 188 *
@@ -151,9 +189,9 @@
151 189 * @return string The form date edited.
152 190 */
153 191 public function getDateEdited(): string
154 192 {
155 - return $this->form->getDateEdited();
193 + return $this->form->metadata->getDateEdited();
156 194 }
157 195
158 196 /**
159 197 * Get the form fields.
@@ -201,9 +239,9 @@
201 239 * @return bool The form show title status.
202 240 */
203 241 public function isTitleVisible(): bool
204 242 {
205 - return $this->form->isTitleVisible();
243 + return $this->form->settings->isShowTitle();
206 244 }
207 245
208 246 /**
209 247 * Set the show title of the form.
@@ -211,9 +249,9 @@
211 249 * @param bool $showTitle The form show title to set.
212 250 */
213 251 public function setTitleVisible(bool $showTitle): void
214 252 {
215 - $this->form->showTitle = $showTitle;
253 + $this->form->settings->showTitle = $showTitle;
216 254 }
217 255 /**
218 256 * Get the show description of the form.
219 257 *
@@ -220,11 +258,10 @@
220 258 * @return bool The form show description status.
221 259 */
222 260 public function isDescriptionVisible(): bool
223 261 {
224 - return $this->form->isDescriptionVisible();
262 + return $this->form->settings->isShowDescription();
225 263 }
226 -
227 264 /**
228 265 * Set the show description of the form.
229 266 *
230 267 * @param bool $description The form show title to set.
@@ -230,12 +267,151 @@
230 267 * @param bool $description The form show title to set.
231 268 */
232 269 public function setDescriptionVisible(bool $description): void
233 270 {
234 - $this->form->showDescription = $description;
271 + $this->form->settings->showDescription = $description;
235 272 }
236 273
237 274 /**
275 + * Set whether to store entries or not.
276 + *
277 + * @param bool $storeEntries
278 + * @return void
279 + */
280 + public function setStoreEntries(bool $storeEntries): void
281 + {
282 + $this->form->settings->storeEntries = $storeEntries;
283 + }
284 + /**
285 + *
286 + * Get whether to store entries or not.
287 + *
288 + * @return bool
289 + */
290 + public function isStoreEntries(): bool
291 + {
292 + return $this->form->settings->isStoreEntries();
293 + }
294 +
295 + /**
296 + * Get integration settings.
297 + * @return IntegrationSettings|null The integration settings.
298 + */
299 + public function getIntegrationSettings(): ?IntegrationSettings
300 + {
301 + return $this->form->integrationSettings;
302 + }
303 + /**
304 + * Set integration settings.
305 + * @param IntegrationSettings|null $settings The integration settings to set.
306 + */
307 + public function setIntegrationSettings(?IntegrationSettings $settings): void
308 + {
309 + $this->form->integrationSettings = $settings;
310 + }
311 +
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 + /**
238 414 * Convert the form entity to an array.
239 415 *
240 416 * @return array<string, mixed> The form entity as an array.
241 417 */
@@ -240,19 +416,39 @@
240 416 * @return array<string, mixed> The form entity as an array.
241 417 */
242 418 public function toArray(): array
243 419 {
244 - return [
245 - 'id' => $this->getId(),
246 - 'name' => $this->getName(),
247 - 'author' => $this->getAuthor(),
248 - 'starred' => $this->isStarred(),
249 - 'published' => $this->isPublished(),
250 - 'dateCreated' => $this->getDateCreated(),
251 - 'dateEdited' => $this->getDateEdited(),
252 - 'fields' => $this->getFields(),
253 - 'description' => $this->getDescription(),
254 - 'showTitle' => $this->isTitleVisible(),
255 - 'showDescription' => $this->isDescriptionVisible(),
256 - ];
420 + $integrationSettings = $this->getIntegrationSettings();
421 + $integrationPayload = $integrationSettings !== null
422 + ? $integrationSettings->toArray()
423 + : ['integrationSettings' => TemplateDefaults::getDefaultIntegrationSettings()];
424 +
425 + $data = array_merge(
426 + [
427 + 'id' => $this->getId(),
428 + 'name' => $this->getName(),
429 + 'author' => $this->getAuthor(),
430 + 'starred' => $this->isStarred(),
431 + 'published' => $this->isPublished(),
432 + 'dateCreated' => $this->getDateCreated(),
433 + 'dateEdited' => $this->getDateEdited(),
434 + 'fields' => $this->getFields(),
435 + 'description' => $this->getDescription(),
436 + 'formType' => $this->getFormType(),
437 + 'showTitle' => $this->isTitleVisible(),
438 + 'showDescription' => $this->isDescriptionVisible(),
439 + 'storeEntries' => $this->isStoreEntries(),
440 + 'pages' => $this->getPages(),
441 + 'progressIndicator' => $this->getProgressIndicator(),
442 + 'styleSettings' => $this->getStyleSettings(),
443 + 'formActionButtons' => $this->getFormActionButtons(),
444 + ],
445 + $this->form->metadata->toArray(),
446 + $this->form->settings->toArray(),
447 + $integrationPayload,
448 + $this->extensionData,
449 + $this->getPaymentSettings()->toArray()
450 + );
451 +
452 + return $data;
257 453 }
258 454 }