From 077317c2bfaa23e7e3ec6afb95700e3a914d1c71 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 6 Jan 2022 11:51:10 +0100 Subject: [PATCH] address: renderLines --- .../Templating/Entity/AddressRender.php | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php index 04b8234d8..0888a76ac 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/AddressRender.php @@ -89,13 +89,7 @@ class AddressRender implements ChillEntityRenderInterface */ public function renderString($addr, array $options): string { - $lines = []; - - $lines[0] = $this->renderStreetLine($addr); - $lines[1] = $this->renderCityLine($addr); - - //TODO simply replace this by a call to renderLines to get all other lines??? - return implode(' - ', $lines); + return implode(' - ', $this->renderLines($addr)); } public function supports($entity, array $options): bool @@ -134,22 +128,67 @@ class AddressRender implements ChillEntityRenderInterface private function renderCityLine($addr): string { - if (!empty($addr->getPostcode())) { $res = strtr('{postcode} {label}', [ '{postcode}' => $addr->getPostcode()->getCode(), '{label}' => $addr->getPostcode()->getName(), ]); } - if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) { if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') { if ($addr->getDistribution()) { - $res.$addr->getDistribution(); + $res = $res.$addr->getDistribution(); } } } return $res; } + + private function renderCountryLine($addr): ?string + { + return $addr->getPostCode()->getCountry()->getName(); + } + + private function renderDeliveryLine($addr): ?string + { + return $addr->getExtra(); + } + + private function renderBuildingLine($addr): ?string + { + $res = $addr->getBuildingName() . ' - ' . $this->renderIntraBuildingLine($addr); + + if (null === $addr->getBuildingName()) { + $res = $this->renderIntraBuildingLine($addr); + if (null === $this->renderIntraBuildingLine($addr)) { + return null; + } + } + if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) { + if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') { + $res = $addr->getBuildingName(); + } + } + return $res; + } + + private function renderIntraBuildingLine($addr): ?string + { + $arr = []; + if ($addr->getFlat()) { + array_push($arr, $addr->getFlat()); + } + if ($addr->getFloor()) { + array_push($arr, $addr->getFloor()); + } + if ($addr->getSteps()) { + array_push($arr, $addr->getSteps()); + } + if ($addr->getCorridor()) { + array_push($arr, $addr->getCorridor()); + } + + return join(' - ', $arr); + } }