From bfba10e61e8df95728e15ced6d5a08e2e403bf5f Mon Sep 17 00:00:00 2001 From: aB0t Date: Wed, 25 Sep 2024 00:04:36 +0200 Subject: [PATCH] Update 2024-09-25 12:04:01 --- .../README.md | 8 ++++ .../code.php | 46 +++++++++++++++++++ .../code.power | 46 +++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/README.md b/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/README.md index abf6780..6a14244 100644 --- a/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/README.md +++ b/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/README.md @@ -31,6 +31,7 @@ class MultiSubform << (F,LightGreen) >> #RoyalBlue { - handleRegularSetMap(array $subform, array $map, ...) : bool - validGetMap(array $map) : bool - validSetMap(array $map) : bool + - prepLinkValue(array $subform, array $setMap) : void } note right of MultiSubform::__construct @@ -252,6 +253,13 @@ Ensures all required keys are present and have valid values. since: 3.2.2 return: bool end note + +note right of MultiSubform::prepLinkValue + Prepare the linkValue needed by the sub-subform + + since: 5.0.3 + return: void +end note @enduml ``` diff --git a/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.php b/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.php index 4b80165..d3551c6 100644 --- a/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.php +++ b/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.php @@ -130,6 +130,13 @@ final class MultiSubform implements MultiSubformInterface { $items = []; // will delete all existing linked items :( not ideal, but real } + else + { + // make sure the sub-subform:linkValue[data:guid] + // is set with the needed key if possible + // this ensures that new sub-subform data is correctly linked + $this->prepLinkValue($items, $setMap); + } // Save the core data if (!$this->setSubformData($items, $setMap['_core'])) @@ -515,6 +522,45 @@ final class MultiSubform implements MultiSubformInterface } return true; // All checks passed + } + + /** + * Prepare the linkValue needed by the sub-subform + * + * @param array $subform The subform data + * @param array $setMap Mapping data for processing subforms + * + * @return void + * @since 5.0.3 + */ + private function prepLinkValue(array &$subform, array $setMap): void + { + $code_table = null; + foreach ($setMap as $key => $map) + { + if ($key === '_core') + { + $code_table = $map['table'] ?? null; + continue; + } + + if (strpos($map['linkValue'], ':') !== false) + { + [$table, $field] = explode(':', $map['linkValue']); + if ($code_table !== null && + 'guid' === $field && + $table === $code_table) + { + foreach ($subform as &$row) + { + if (empty($row['guid'])) + { + $row['guid'] = $this->subform->table($table)->getGuid($field); + } + } + } + } + } } } diff --git a/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.power b/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.power index 463e2cf..a8eb95e 100644 --- a/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.power +++ b/src/e0198c3f-777a-4a0b-87b7-e6a198afc8f9/code.power @@ -105,6 +105,13 @@ { $items = []; // will delete all existing linked items :( not ideal, but real } + else + { + // make sure the sub-subform:linkValue[data:guid] + // is set with the needed key if possible + // this ensures that new sub-subform data is correctly linked + $this->prepLinkValue($items, $setMap); + } // Save the core data if (!$this->setSubformData($items, $setMap['_core'])) @@ -490,4 +497,43 @@ } return true; // All checks passed + } + + /** + * Prepare the linkValue needed by the sub-subform + * + * @param array $subform The subform data + * @param array $setMap Mapping data for processing subforms + * + * @return void + * @since 5.0.3 + */ + private function prepLinkValue(array &$subform, array $setMap): void + { + $code_table = null; + foreach ($setMap as $key => $map) + { + if ($key === '_core') + { + $code_table = $map['table'] ?? null; + continue; + } + + if (strpos($map['linkValue'], ':') !== false) + { + [$table, $field] = explode(':', $map['linkValue']); + if ($code_table !== null && + 'guid' === $field && + $table === $code_table) + { + foreach ($subform as &$row) + { + if (empty($row['guid'])) + { + $row['guid'] = $this->subform->table($table)->getGuid($field); + } + } + } + } + } } \ No newline at end of file