PluginProbe
The Innovative Form Builder – IvyForms / 0.5
The Innovative Form Builder – IvyForms v0.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
ivyforms / backend / src / Factory / Form / FormFactory.php

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

105 lines 2.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 © 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\Common\Helpers\Helper;
17 use IvyForms\Entity\Form\Form as FormEntity;
18 use IvyForms\ValueObjects\Form\Form;
19 use IvyForms\ValueObjects\Form\IntegrationSettings;
20
21 /**
22 * Class FormFactory
23 *
24 * @package IvyForms\Factory\Form
25 */
26 class FormFactory
27 {
28 /**
29 * @param array<string, mixed> $data
30 *
31 * @return FormEntity
32 *
33 * @throws ValidationException
34 */
35 public static function create(array $data): FormEntity
36 {
37 $settings = isset($data['settings']) ? json_decode($data['settings'], true) : [];
38 $integrationSettings = Helper::parseToArray($data['integrationSettings']);
39
40 if (!empty($settings)) {
41 $data['showTitle'] = $settings['showTitle'] ?? true;
42 $data['showDescription'] = $settings['showDescription'] ?? false;
43 $data['storeEntries'] = !isset($settings['storeEntries']) || (bool)$settings['storeEntries'];
44 }
45
46 $formObject = new Form(
47 $data['id'] ?? 0,
48 $data['name'] ?? '',
49 $data['author'] ?? '',
50 $data['starred'] ?? false,
51 $data['published'] ?? true,
52 $data['description'] ?? '',
53 $data['showTitle'] ?? true,
54 $data['showDescription'] ?? false,
55 isset($data['storeEntries']) ? (bool)$data['storeEntries'] : true,
56 $data['fields'] ?? [],
57 new IntegrationSettings($integrationSettings)
58 );
59
60 $form = new FormEntity($formObject);
61
62 if (isset($data['id'])) {
63 $form->setId($data['id']);
64 }
65
66 if (isset($data['name'])) {
67 $form->setName($data['name']);
68 }
69
70 if (isset($data['author'])) {
71 $form->setAuthor($data['author']);
72 }
73
74 if (isset($data['starred'])) {
75 $form->setStarred($data['starred']);
76 }
77
78 if (isset($data['published'])) {
79 $form->setPublished($data['published']);
80 }
81
82 if (isset($data['description'])) {
83 $form->setDescription($data['description']);
84 }
85
86 if (isset($data['fields'])) {
87 $form->setFields($data['fields']);
88 }
89
90 if (isset($data['showTitle'])) {
91 $form->setTitleVisible($data['showTitle']);
92 }
93
94 if (isset($data['showDescription'])) {
95 $form->setDescriptionVisible($data['showDescription']);
96 }
97
98 if (isset($data['storeEntries'])) {
99 $form->setStoreEntries($data['storeEntries']);
100 }
101
102 return $form;
103 }
104 }
105