PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
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.0, at backend/src/Entity/Form/Form.php

355 lines 8.6 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->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->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->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->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->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->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->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->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->isTitleVisible();
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->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->isDescriptionVisible();
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->showDescription = $description;
232 }
233
234 /**
235 *
236 * Set whether to store entries or not.
237 *
238 * @param bool $storeEntries
239 * @return void
240 */
241 public function setStoreEntries(bool $storeEntries): void
242 {
243 $this->form->storeEntries = $storeEntries;
244 }
245 /**
246 *
247 * Get whether to store entries or not.
248 *
249 * @return bool
250 */
251 public function isStoreEntries(): bool
252 {
253 return $this->form->storeEntries;
254 }
255
256 /**
257 * Get integration settings.
258 * @return IntegrationSettings|null The integration settings.
259 */
260 public function getIntegrationSettings(): ?IntegrationSettings
261 {
262 return $this->form->integrationSettings;
263 }
264 /**
265 * Set integration settings.
266 * @param IntegrationSettings|null $settings The integration settings to set.
267 */
268 public function setIntegrationSettings(?IntegrationSettings $settings): void
269 {
270 $this->form->integrationSettings = $settings;
271 }
272
273 /**
274 * Get form action buttons settings.
275 *
276 * @return array<string, mixed> The form action buttons settings.
277 */
278 public function getFormActionButtons(): array
279 {
280 return $this->form->formActionButtons;
281 }
282
283 /**
284 * Set form action buttons settings.
285 *
286 * @param array<string, mixed> $formActionButtons The form action buttons settings to set.
287 * @return void
288 */
289 public function setFormActionButtons(array $formActionButtons): void
290 {
291 $this->form->formActionButtons = $formActionButtons;
292 }
293
294 /**
295 * Get style settings as array
296 *
297 * @return array<string, mixed>
298 */
299 public function getStyleSettings(): array
300 {
301 $settings = $this->form->getStyleSettings();
302 if (null === $settings) {
303 return TemplateDefaults::getDefaultFormStylesSafe();
304 }
305 return $settings->getAll();
306 }
307
308 /**
309 * Set style settings from array (wraps {@see StyleSettings} like integration settings).
310 *
311 * @param array<string, mixed>|null $settings The style settings to set.
312 */
313 public function setStyleSettings(?array $settings): void
314 {
315 if (null === $settings) {
316 $this->form->setStyleSettings(null);
317 return;
318 }
319 $this->form->setStyleSettings(new StyleSettings($settings));
320 }
321
322 /**
323 * Convert the form entity to an array.
324 *
325 * @return array<string, mixed> The form entity as an array.
326 */
327 public function toArray(): array
328 {
329 $integrationSettings = $this->getIntegrationSettings();
330 $integrationPayload = $integrationSettings !== null
331 ? $integrationSettings->toArray()
332 : ['integrationSettings' => TemplateDefaults::getDefaultIntegrationSettings()];
333
334 return array_merge(
335 [
336 'id' => $this->getId(),
337 'name' => $this->getName(),
338 'author' => $this->getAuthor(),
339 'starred' => $this->isStarred(),
340 'published' => $this->isPublished(),
341 'dateCreated' => $this->getDateCreated(),
342 'dateEdited' => $this->getDateEdited(),
343 'fields' => $this->getFields(),
344 'description' => $this->getDescription(),
345 'showTitle' => $this->isTitleVisible(),
346 'showDescription' => $this->isDescriptionVisible(),
347 'storeEntries' => $this->isStoreEntries(),
348 'styleSettings' => $this->getStyleSettings(),
349 'formActionButtons' => $this->getFormActionButtons(),
350 ],
351 $integrationPayload
352 );
353 }
354 }
355