PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.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 / Common / Helpers / FormPageHelper.php

FormPageHelper.php in The Innovative Form Builder – IvyForms 1.5.1, at backend/src/Common/Helpers/FormPageHelper.php

49 lines 1.2 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\Common\Helpers;
9
10 class FormPageHelper
11 {
12 /**
13 * Group fields by page ID
14 *
15 * @param array<mixed> $fields
16 * @return array<string, array<mixed>>
17 */
18 public static function groupFieldsByPageId(array $fields): array
19 {
20 $fieldsByPage = [];
21 foreach ($fields as $field) {
22 $pageId = $field['pageId'] ?? ($field['settings']['pageId'] ?? null);
23 if ($pageId) {
24 if (!isset($fieldsByPage[$pageId])) {
25 $fieldsByPage[$pageId] = [];
26 }
27 $fieldsByPage[$pageId][] = $field;
28 }
29 }
30 return $fieldsByPage;
31 }
32
33 /**
34 * Assign grouped fields to pages
35 *
36 * @param array<mixed> $pages
37 * @param array<string, array<mixed>> $fieldsByPage
38 * @return array<mixed>
39 */
40 public static function assignFieldsToPages(array $pages, array $fieldsByPage): array
41 {
42 foreach ($pages as &$page) {
43 $pageId = $page['id'] ?? null;
44 $page['fields'] = $fieldsByPage[$pageId] ?? [];
45 }
46 return $pages;
47 }
48 }
49