PluginProbe
The Innovative Form Builder – IvyForms / 1.1.1
The Innovative Form Builder – IvyForms v1.1.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
ivyforms / backend / src / Entity / Form / Form.php

Form.php in The Innovative Form Builder – IvyForms 1.1.1, at backend/src/Entity/Form/Form.php

392 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Services\Template\TemplateDefaults;
11 use IvyForms\ValueObjects\Form\Form as FormValueObject;
12 use IvyForms\ValueObjects\Form\IntegrationSettings;
13 use IvyForms\ValueObjects\Form\StyleSettings;
14
15 /**
16 * Class Form
17 *
18 * @package IvyForms\Entity\Form
19 */
20 class Form
21 {
22 /**
23 * @var FormValueObject
24 */
25 private FormValueObject $form;
26
27 /**
28 * Form constructor.
29 *
30 * @param FormValueObject $form The form object.
31 */
32 public function __construct(FormValueObject $form)
33 {
34 $this->form = $form;
35 }
36
37 /**
38 * Get the ID of the form.
39 *
40 * @return int The form ID.
41 */
42 public function getId(): int
43 {
44 return $this->form->getId();
45 }
46
47 /**
48 * Set the ID of the form.
49 *
50 * @param int $formId The form ID to set.
51 */
52 public function setId(int $formId): void
53 {
54 $this->form->id = $formId;
55 }
56
57 /**
58 * Get the name of the form.
59 *
60 * @return string The form name.
61 */
62 public function getName(): string
63 {
64 return $this->form->getName();
65 }
66
67 /**
68 * Set the name of the form.
69 *
70 * @param string $name The form name to set.
71 */
72 public function setName(string $name): void
73 {
74 $this->form->name = $name;
75 }
76
77 /**
78 * Get the author of the form.
79 *
80 * @return string The form author.
81 */
82 public function getAuthor(): string
83 {
84 return $this->form->metadata->getAuthor();
85 }
86
87 /**
88 * Set the author of the form.
89 *
90 * @param string $author The form author to set.
91 */
92 public function setAuthor(string $author): void
93 {
94 $this->form->metadata->author = $author;
95 }
96
97 /**
98 * Get the starred status of the form.
99 *
100 * @return bool The form starred status.
101 */
102 public function isStarred(): bool
103 {
104 return $this->form->metadata->isStarred();
105 }
106
107 /**
108 * Set the starred status of the form.
109 *
110 * @param bool $starred The form starred status to set.
111 */
112 public function setStarred(bool $starred): void
113 {
114 $this->form->metadata->starred = $starred;
115 }
116
117 /**
118 * Get the published status of the form.
119 *
120 * @return bool The form published status.
121 */
122 public function isPublished(): bool
123 {
124 return $this->form->metadata->isPublished();
125 }
126
127 /**
128 * Set the published status of the form.
129 *
130 * @param bool $published The form published status to set.
131 */
132 public function setPublished(bool $published): void
133 {
134 $this->form->metadata->published = $published;
135 }
136
137 /**
138 * Get the creation date of the form.
139 *
140 * @return string The form of date creation.
141 */
142 public function getDateCreated(): string
143 {
144 return $this->form->metadata->getDateCreated();
145 }
146 /**
147 * Get the date edited of the form.
148 *
149 * @return string The form date edited.
150 */
151 public function getDateEdited(): string
152 {
153 return $this->form->metadata->getDateEdited();
154 }
155
156 /**
157 * Get the form fields.
158 *
159 * @return mixed[] The form fields.
160 */
161 public function getFields(): array
162 {
163 return $this->form->getFields();
164 }
165
166 /**
167 * Set the form fields.
168 *
169 * @param mixed[] $fields The form fields to set.
170 */
171 public function setFields(array $fields): void
172 {
173 $this->form->fields = $fields;
174 }
175
176 /**
177 * Get the form description.
178 *
179 * @return string The form description.
180 */
181 public function getDescription(): string
182 {
183 return $this->form->getDescription();
184 }
185
186 /**
187 * Set the form description.
188 *
189 * @param string $description The form description to set.
190 */
191 public function setDescription(string $description): void
192 {
193 $this->form->description = $description;
194 }
195
196 /**
197 * Get the show title of the form.
198 *
199 * @return bool The form show title status.
200 */
201 public function isTitleVisible(): bool
202 {
203 return $this->form->settings->isShowTitle();
204 }
205
206 /**
207 * Set the show title of the form.
208 *
209 * @param bool $showTitle The form show title to set.
210 */
211 public function setTitleVisible(bool $showTitle): void
212 {
213 $this->form->settings->showTitle = $showTitle;
214 }
215 /**
216 * Get the show description of the form.
217 *
218 * @return bool The form show description status.
219 */
220 public function isDescriptionVisible(): bool
221 {
222 return $this->form->settings->isShowDescription();
223 }
224 /**
225 * Set the show description of the form.
226 *
227 * @param bool $description The form show title to set.
228 */
229 public function setDescriptionVisible(bool $description): void
230 {
231 $this->form->settings->showDescription = $description;
232 }
233
234 /**
235 * Set whether to store entries or not.
236 *
237 * @param bool $storeEntries
238 * @return void
239 */
240 public function setStoreEntries(bool $storeEntries): void
241 {
242 $this->form->settings->storeEntries = $storeEntries;
243 }
244 /**
245 *
246 * Get whether to store entries or not.
247 *
248 * @return bool
249 */
250 public function isStoreEntries(): bool
251 {
252 return $this->form->settings->isStoreEntries();
253 }
254
255 /**
256 * Get integration settings.
257 * @return IntegrationSettings|null The integration settings.
258 */
259 public function getIntegrationSettings(): ?IntegrationSettings
260 {
261 return $this->form->integrationSettings;
262 }
263 /**
264 * Set integration settings.
265 * @param IntegrationSettings|null $settings The integration settings to set.
266 */
267 public function setIntegrationSettings(?IntegrationSettings $settings): void
268 {
269 $this->form->integrationSettings = $settings;
270 }
271
272 /**
273 * Get pages.
274 * @return array<int, array<string, mixed>> The pages array.
275 */
276 public function getPages(): array
277 {
278 return $this->form->pages ?? [];
279 }
280
281 /**
282 * Set pages.
283 * @param array<int, array<string, mixed>> $pages The pages array to set.
284 */
285 public function setPages(array $pages): void
286 {
287 $this->form->pages = $pages;
288 }
289
290 /**
291 * Get progress indicator settings.
292 * @return array<string, mixed> The progress indicator settings.
293 */
294 public function getProgressIndicator(): array
295 {
296 return $this->form->progressIndicator ?? [];
297 }
298
299 /**
300 * Set progress indicator settings.
301 * @param array<string, mixed> $progressIndicator The progress indicator settings to set.
302 */
303 public function setProgressIndicator(array $progressIndicator): void
304 {
305 $this->form->progressIndicator = $progressIndicator;
306 }
307
308 /**
309 * Get form action buttons settings.
310 *
311 * @return array<string, mixed> The form action buttons settings.
312 */
313 public function getFormActionButtons(): array
314 {
315 return $this->form->formActionButtons;
316 }
317
318 /**
319 * Set form action buttons settings.
320 *
321 * @param array<string, mixed> $formActionButtons The form action buttons settings to set.
322 * @return void
323 */
324 public function setFormActionButtons(array $formActionButtons): void
325 {
326 $this->form->formActionButtons = $formActionButtons;
327 }
328
329 /**
330 * Get style settings as array
331 *
332 * @return array<string, mixed>
333 */
334 public function getStyleSettings(): array
335 {
336 $settings = $this->form->getStyleSettings();
337 if (null === $settings) {
338 return TemplateDefaults::getDefaultFormStylesSafe();
339 }
340 return $settings->getAll();
341 }
342
343 /**
344 * Set style settings from array (wraps {@see StyleSettings} like integration settings).
345 *
346 * @param array<string, mixed>|null $settings The style settings to set.
347 */
348 public function setStyleSettings(?array $settings): void
349 {
350 if (null === $settings) {
351 $this->form->setStyleSettings(null);
352 return;
353 }
354 $this->form->setStyleSettings(new StyleSettings($settings));
355 }
356
357 /**
358 * Convert the form entity to an array.
359 *
360 * @return array<string, mixed> The form entity as an array.
361 */
362 public function toArray(): array
363 {
364 $integrationSettings = $this->getIntegrationSettings();
365 $integrationPayload = $integrationSettings !== null
366 ? $integrationSettings->toArray()
367 : ['integrationSettings' => TemplateDefaults::getDefaultIntegrationSettings()];
368
369 return array_merge(
370 [
371 'id' => $this->getId(),
372 'name' => $this->getName(),
373 'author' => $this->getAuthor(),
374 'starred' => $this->isStarred(),
375 'published' => $this->isPublished(),
376 'dateCreated' => $this->getDateCreated(),
377 'dateEdited' => $this->getDateEdited(),
378 'fields' => $this->getFields(),
379 'description' => $this->getDescription(),
380 'showTitle' => $this->isTitleVisible(),
381 'showDescription' => $this->isDescriptionVisible(),
382 'storeEntries' => $this->isStoreEntries(),
383 'pages' => $this->getPages(),
384 'progressIndicator' => $this->getProgressIndicator(),
385 'styleSettings' => $this->getStyleSettings(),
386 'formActionButtons' => $this->getFormActionButtons(),
387 ],
388 $integrationPayload
389 );
390 }
391 }
392