PluginProbe
The Innovative Form Builder – IvyForms / 0.3
The Innovative Form Builder – IvyForms v0.3
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 / Factory / Form / FormFactory.php

FormFactory.php in The Innovative Form Builder – IvyForms 0.3, at backend/src/Factory/Form/FormFactory.php

101 lines 2.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 © TMS-Plugins. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace IvyForms\Factory\Form;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Common\Exceptions\ValidationException;
16 use IvyForms\Entity\Form\Form as FormEntity;
17 use IvyForms\ValueObjects\Form\Form;
18
19 /**
20 * Class FormFactory
21 *
22 * @package IvyForms\Factory\Form
23 */
24 class FormFactory
25 {
26 /**
27 * @param array<string, mixed> $data
28 *
29 * @retrun FormEntity
30 *
31 * @throws ValidationException
32 */
33 public static function create(array $data): FormEntity
34 {
35 $settings = isset($data['settings']) ? json_decode($data['settings'], true) : [];
36
37 if (!empty($settings)) {
38 $data['showTitle'] = $settings['showTitle'] ?? true;
39 $data['showDescription'] = $settings['showDescription'] ?? false;
40 $data['storeEntries'] = isset($settings['storeEntries']) ? (bool)$settings['storeEntries'] : true;
41 }
42
43 $formObject = new Form(
44 $data['id'] ?? 0,
45 $data['name'] ?? '',
46 $data['author'] ?? '',
47 $data['starred'] ?? false,
48 $data['published'] ?? true,
49 $data['description'] ?? '',
50 $data['showTitle'] ?? true,
51 $data['showDescription'] ?? false,
52 isset($data['storeEntries']) ? (bool)$data['storeEntries'] : true,
53 $data['fields'] ?? [],
54 );
55
56 $form = new FormEntity($formObject);
57
58 if (isset($data['id'])) {
59 $form->setId($data['id']);
60 }
61
62 if (isset($data['name'])) {
63 $form->setName($data['name']);
64 }
65
66 if (isset($data['author'])) {
67 $form->setAuthor($data['author']);
68 }
69
70 if (isset($data['starred'])) {
71 $form->setStarred($data['starred']);
72 }
73
74 if (isset($data['published'])) {
75 $form->setPublished($data['published']);
76 }
77
78 if (isset($data['description'])) {
79 $form->setDescription($data['description']);
80 }
81
82 if (isset($data['fields'])) {
83 $form->setFields($data['fields']);
84 }
85
86 if (isset($data['showTitle'])) {
87 $form->setTitleVisible($data['showTitle']);
88 }
89
90 if (isset($data['showDescription'])) {
91 $form->setDescriptionVisible($data['showDescription']);
92 }
93
94 if (isset($data['storeEntries'])) {
95 $form->setStoreEntries($data['storeEntries']);
96 }
97
98 return $form;
99 }
100 }
101