address: renderLines

This commit is contained in:
nobohan 2022-01-06 11:51:10 +01:00
parent 3c2ebee12a
commit 077317c2bf

View File

@ -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);
}
}