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/Services/Entry/Managers/EntryFieldManager.php +56 -13 0.5 → 1.5 View file →
@@ -1,15 +1,12 @@
1 1 <?php
2 2
3 3 namespace IvyForms\Services\Entry\Managers;
4 4
5 -// phpcs:disable PSR1.Files.SideEffects
6 -if (!defined('ABSPATH')) {
7 - exit; // Exit if accessed directly
8 -}
9 -
10 5 use IvyForms\Common\Exceptions\ValidationException;
11 6 use IvyForms\Common\Helpers\EntryHelper;
7 +use IvyForms\Common\Helpers\FieldHelper;
8 +use IvyForms\Entity\EntryField\EntryField;
12 9 use IvyForms\Factory\EntryField\EntryFieldFactory;
13 10 use IvyForms\Repository\Entry\EntryRepositoryInterface;
14 11 use IvyForms\Repository\EntryField\EntryFieldRepositoryInterface;
15 12
@@ -36,14 +33,16 @@
36 33 * Fetch entries along with their associated fields.
37 34 * Automatically formats field values for display.
38 35 *
39 36 * @param array<int, array<string, mixed>> $entries
37 + * @param bool $skipFormatting Whether to skip formatting and return raw values (used for result tables).
40 38 * @return array<mixed>
39 + * @SuppressWarnings(PHPMD)
41 40 */
42 - public function getEntryFields(array $entries): array
41 + public function getEntryFields(array $entries, bool $skipFormatting = false): array
43 42 {
44 43 $entryFields = $this->entryRepository->getEntryFields($entries);
45 - return $this->valueManager->formatForFrontend($entryFields);
44 + return $this->valueManager->formatForFrontend($entryFields, $skipFormatting);
46 45 }
47 46
48 47 /**
49 48 * Check if a value already exists in entry fields for a specific field.
@@ -52,16 +51,27 @@
52 51 * @param int $fieldId
53 52 * @param string $value
54 53 * @return bool
55 54 */
56 - public function checkDuplicateValue(int $formId, int $fieldId, string $value): bool
57 - {
58 - return $this->entryFieldRepository->checkDuplicateValue($formId, $fieldId, $value);
55 + public function checkDuplicateValue(
56 + int $formId,
57 + int $fieldId,
58 + string $value,
59 + ?int $excludeEntryId = null
60 + ): bool {
61 + return $this->entryFieldRepository->checkDuplicateValue(
62 + $formId,
63 + $fieldId,
64 + $value,
65 + $excludeEntryId
66 + );
59 67 }
60 68
61 69 /**
62 70 * Add entry fields to the repository.
63 71 *
72 + * Resolves all field values in PHP, then persists with a single multi-row INSERT.
73 + *
64 74 * @param array<int, object> $formFields
65 75 * @param int $entryId
66 76 * @param array<mixed> $submissionData
67 77 * @throws ValidationException
@@ -68,11 +78,30 @@
68 78 */
69 79 public function addEntryFields(array $formFields, int $entryId, array $submissionData): void
70 80 {
71 81 $parentChildrenMap = EntryHelper::buildParentChildrenMap($formFields);
72 - $parentSubfieldKeys = EntryHelper::buildParentSubfieldKeys($parentChildrenMap, $submissionData);
82 + $parentSubfieldKeys = EntryHelper::buildParentSubfieldKeys(
83 + $parentChildrenMap,
84 + $submissionData,
85 + $formFields
86 + );
73 87
88 + /** @var list<array{entryField: EntryField, field: object}> $created */
89 + $created = [];
90 +
74 91 foreach ($formFields as $field) {
92 + // Skip security/CAPTCHA fields - their tokens are only needed for verification, not storage
93 + $fieldType = $field->getType();
94 + if (FieldHelper::isSecurityField($fieldType)) {
95 + continue;
96 + }
97 +
98 + /** @var bool $shouldSkip */
99 + $shouldSkip = apply_filters('ivyforms/entry/field/should_skip', false, $field);
100 + if ($shouldSkip) {
101 + continue;
102 + }
103 +
75 104 $value = $this->valueManager->resolveFieldValue(
76 105 $field,
77 106 $submissionData,
78 107 $parentChildrenMap,
@@ -120,11 +149,25 @@
120 149 $field,
121 150 $submissionData
122 151 );
123 152
124 - $entryField = EntryFieldFactory::create($entryFieldData);
153 + $created[] = [
154 + 'entryField' => EntryFieldFactory::create($entryFieldData),
155 + 'field' => $field,
156 + ];
157 + }
125 158
126 - $this->entryFieldRepository->add($entryField);
159 + if ($created === []) {
160 + return;
161 + }
162 +
163 + $this->entryFieldRepository->batchInsert(
164 + array_column($created, 'entryField')
165 + );
166 +
167 + foreach ($created as $item) {
168 + $entryField = $item['entryField'];
169 + $field = $item['field'];
127 170
128 171 /**
129 172 * Action fired after an entry field has been saved to the database.
130 173 * Allows post-processing or logging of entry field creation.