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 +454 -0 0.6.1 → 1.5 View file →
@@ -1,0 +1,454 @@
1 +<?php
2 +
3 +/**
4 + * @copyright © Melograno Venture Studio. All rights reserved.
5 + * @licence See LICENCE.md for license details.
6 + */
7 +
8 +namespace IvyForms\Entity\Form;
9 +
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;
15 +
16 +/**
17 + * Class Form
18 + *
19 + * @package IvyForms\Entity\Form
20 + */
21 +class Form
22 +{
23 + /**
24 + * @var FormValueObject
25 + */
26 + private FormValueObject $form;
27 +
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 + /**
36 + * Form constructor.
37 + *
38 + * @param FormValueObject $form The form object.
39 + */
40 + public function __construct(FormValueObject $form)
41 + {
42 + $this->form = $form;
43 + }
44 +
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 + /**
62 + * Get the ID of the form.
63 + *
64 + * @return int The form ID.
65 + */
66 + public function getId(): int
67 + {
68 + return $this->form->getId();
69 + }
70 +
71 + /**
72 + * Set the ID of the form.
73 + *
74 + * @param int $formId The form ID to set.
75 + */
76 + public function setId(int $formId): void
77 + {
78 + $this->form->id = $formId;
79 + }
80 +
81 + /**
82 + * Get the name of the form.
83 + *
84 + * @return string The form name.
85 + */
86 + public function getName(): string
87 + {
88 + return $this->form->getName();
89 + }
90 +
91 + /**
92 + * Set the name of the form.
93 + *
94 + * @param string $name The form name to set.
95 + */
96 + public function setName(string $name): void
97 + {
98 + $this->form->name = $name;
99 + }
100 +
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 + /**
118 + * Get the author of the form.
119 + *
120 + * @return string The form author.
121 + */
122 + public function getAuthor(): string
123 + {
124 + return $this->form->metadata->getAuthor();
125 + }
126 +
127 + /**
128 + * Set the author of the form.
129 + *
130 + * @param string $author The form author to set.
131 + */
132 + public function setAuthor(string $author): void
133 + {
134 + $this->form->metadata->author = $author;
135 + }
136 +
137 + /**
138 + * Get the starred status of the form.
139 + *
140 + * @return bool The form starred status.
141 + */
142 + public function isStarred(): bool
143 + {
144 + return $this->form->metadata->isStarred();
145 + }
146 +
147 + /**
148 + * Set the starred status of the form.
149 + *
150 + * @param bool $starred The form starred status to set.
151 + */
152 + public function setStarred(bool $starred): void
153 + {
154 + $this->form->metadata->starred = $starred;
155 + }
156 +
157 + /**
158 + * Get the published status of the form.
159 + *
160 + * @return bool The form published status.
161 + */
162 + public function isPublished(): bool
163 + {
164 + return $this->form->metadata->isPublished();
165 + }
166 +
167 + /**
168 + * Set the published status of the form.
169 + *
170 + * @param bool $published The form published status to set.
171 + */
172 + public function setPublished(bool $published): void
173 + {
174 + $this->form->metadata->published = $published;
175 + }
176 +
177 + /**
178 + * Get the creation date of the form.
179 + *
180 + * @return string The form of date creation.
181 + */
182 + public function getDateCreated(): string
183 + {
184 + return $this->form->metadata->getDateCreated();
185 + }
186 + /**
187 + * Get the date edited of the form.
188 + *
189 + * @return string The form date edited.
190 + */
191 + public function getDateEdited(): string
192 + {
193 + return $this->form->metadata->getDateEdited();
194 + }
195 +
196 + /**
197 + * Get the form fields.
198 + *
199 + * @return mixed[] The form fields.
200 + */
201 + public function getFields(): array
202 + {
203 + return $this->form->getFields();
204 + }
205 +
206 + /**
207 + * Set the form fields.
208 + *
209 + * @param mixed[] $fields The form fields to set.
210 + */
211 + public function setFields(array $fields): void
212 + {
213 + $this->form->fields = $fields;
214 + }
215 +
216 + /**
217 + * Get the form description.
218 + *
219 + * @return string The form description.
220 + */
221 + public function getDescription(): string
222 + {
223 + return $this->form->getDescription();
224 + }
225 +
226 + /**
227 + * Set the form description.
228 + *
229 + * @param string $description The form description to set.
230 + */
231 + public function setDescription(string $description): void
232 + {
233 + $this->form->description = $description;
234 + }
235 +
236 + /**
237 + * Get the show title of the form.
238 + *
239 + * @return bool The form show title status.
240 + */
241 + public function isTitleVisible(): bool
242 + {
243 + return $this->form->settings->isShowTitle();
244 + }
245 +
246 + /**
247 + * Set the show title of the form.
248 + *
249 + * @param bool $showTitle The form show title to set.
250 + */
251 + public function setTitleVisible(bool $showTitle): void
252 + {
253 + $this->form->settings->showTitle = $showTitle;
254 + }
255 + /**
256 + * Get the show description of the form.
257 + *
258 + * @return bool The form show description status.
259 + */
260 + public function isDescriptionVisible(): bool
261 + {
262 + return $this->form->settings->isShowDescription();
263 + }
264 + /**
265 + * Set the show description of the form.
266 + *
267 + * @param bool $description The form show title to set.
268 + */
269 + public function setDescriptionVisible(bool $description): void
270 + {
271 + $this->form->settings->showDescription = $description;
272 + }
273 +
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 + /**
414 + * Convert the form entity to an array.
415 + *
416 + * @return array<string, mixed> The form entity as an array.
417 + */
418 + public function toArray(): array
419 + {
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;
453 + }
454 +}