Skip to content

Commit 765f5b8

Browse files
author
Ralf Hartung
committed
Issue #60
Modify key for repeatable items
1 parent 566b582 commit 765f5b8

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/EDI/Interpreter.php

+4-15
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ private function processSegment($segment, &$xmlMap, $segmentIdx, &$errors = null
250250
$attributes = $xmlMap[$id]['attributes'];
251251
$details_desc = $xmlMap[$id]['details'];
252252

253-
$entryCount = [];
254-
255253
$jsonelements = ["segmentIdx" => $segmentIdx, "segmentCode" => $id];
256254
foreach ($segment as $idx => $detail) {
257255
$n = $idx - 1;
@@ -271,12 +269,6 @@ private function processSegment($segment, &$xmlMap, $segmentIdx, &$errors = null
271269

272270
$d_desc_attr = $details_desc[$n]['attributes'];
273271

274-
if (!array_key_exists($d_desc_attr['name'], $entryCount)) {
275-
$entryCount[$d_desc_attr['name']] = 0;
276-
}
277-
278-
$entryCount[$d_desc_attr['name']]++;
279-
280272
$jsoncomposite = [];
281273
if (isset($details_desc[$n]['details']) && $detail !== '') {
282274
$sub_details_desc = $details_desc[$n]['details'];
@@ -309,15 +301,12 @@ private function processSegment($segment, &$xmlMap, $segmentIdx, &$errors = null
309301
$jsoncomposite = $detail;
310302
}
311303

312-
if ($entryCount[$d_desc_attr['name']] === 1) {
313-
$jsonelements[$d_desc_attr['name']] = $jsoncomposite;
304+
if (array_key_exists($d_desc_attr['name'], $jsonelements)) {
305+
$jsonelements[$d_desc_attr['name'].$n] = $jsoncomposite;
314306
} else {
315-
if ($entryCount[$d_desc_attr['name']] === 2) {
316-
$jsonelements[$d_desc_attr['name']] = [$jsonelements[$d_desc_attr['name']]];
317-
}
318-
319-
$jsonelements[$d_desc_attr['name']][] = $jsoncomposite;
307+
$jsonelements[$d_desc_attr['name']] = $jsoncomposite;
320308
}
309+
321310
}
322311
$jsonsegment['key'] = $attributes['name'];
323312
$jsonsegment['value'] = $jsonelements;

0 commit comments

Comments
 (0)