change field lookup logic

This commit is contained in:
2026-07-22 16:14:00 +02:00
parent 90851908b7
commit 5ae01c3038
2 changed files with 23 additions and 19 deletions
@@ -50,7 +50,7 @@ class ElixFormsController
$matchingInstances = []; $matchingInstances = [];
foreach ($instances as $instance) { foreach ($instances as $instance) {
if (!is_array($instance)) { if (!\is_array($instance)) {
continue; continue;
} }
@@ -67,18 +67,16 @@ class ElixFormsController
$exportGroup $exportGroup
); );
foreach ($exportTags as $exportTag) { $exportTagsByName = array_column($exportTags, null, 'name');
if (!is_array($exportTag) || !isset($exportTag['name'])) { if (!\array_key_exists($fieldName, $exportTagsByName)) {
continue; continue;
} }
$name = (string) $exportTag['name']; $exportTag = $exportTagsByName[$fieldName];
$value = isset($exportTag['value']) ? (string) $exportTag['value'] : ''; $value = isset($exportTag['value']) ? (string) $exportTag['value'] : '';
if (strcasecmp($name, $fieldName) === 0 && stripos($value, $fieldValue) !== false) { if (stripos($value, $fieldValue) !== false) {
$matchingInstances[] = $instance; $matchingInstances[] = $instance;
break;
}
} }
} }
+14 -8
View File
@@ -54,16 +54,22 @@ final class ElixFormsControllerTest extends TestCase
throw new \RuntimeException('exportGroup non inoltrato al client.'); throw new \RuntimeException('exportGroup non inoltrato al client.');
} }
$values = [ $tags = [
10 => 'Nessuna corrispondenza', 10 => [
20 => 'Il contratto ABC-123 è presente', 'name' => 'contratto.altro',
30 => 'Altro valore', 'value' => 'Il contratto ABC-123 è presente',
],
20 => [
'name' => 'contratto.id',
'value' => 'Il contratto ABC-123 è presente',
],
30 => [
'name' => 'contratto.id',
'value' => 'Altro valore',
],
]; ];
return [[ return [$tags[$requestId]];
'name' => 'contratto.id',
'value' => $values[$requestId],
]];
} }
}; };
$config = new class extends Config { $config = new class extends Config {