address: render distribution in street line + init renderLines function

This commit is contained in:
nobohan 2022-01-05 18:42:27 +01:00
parent 78cf817921
commit 3c2ebee12a
3 changed files with 58 additions and 7 deletions

View File

@ -60,6 +60,8 @@ class Address
/**
* @var string|null
*
* used for the CEDEX information
*
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"write"})
*/

View File

@ -25,6 +25,7 @@
<p class="postcode">
<span class="code">{{ address.postCode.code }}</span>
<span class="name">{{ address.postCode.name }}</span>
<span class="name">{{ address.distribution }}</span>
</p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
{% endif %}
@ -60,6 +61,7 @@
<p class="postcode">
<span class="code">{{ address.postCode.code }}</span>
<span class="name">{{ address.postCode.name }}</span>
<span class="name">{{ address.distribution }}</span>
</p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
{% endif %}
@ -118,6 +120,7 @@
<p class="postcode">
<span class="code">{{ address.postCode.code }}</span>
<span class="name">{{ address.postCode.name }}</span>
<span class="name">{{ address.distribution }}</span>
</p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
</div>

View File

@ -36,6 +36,36 @@ class AddressRender implements ChillEntityRenderInterface
$this->templating = $templating;
}
/**
* @param Address addr
* @param mixed $addr
* @return string[]
*/
public function renderLines($addr): array
{
$lines = [];
$lines[0] = $this->renderBuildingLine($addr);
$lines[1] = $this->renderDeliveryLine($addr);
$lines[2] = $this->renderStreetLine($addr);
$lines[3] = $this->renderCityLine($addr);
$lines[4] = $this->renderCountryLine($addr);
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
$lines[0] = $this->renderIntraBuildingLine($addr);
$lines[1] = $this->renderBuildingLine($addr);
$lines[2] = $this->renderStreetLine($addr);
$lines[3] = $this->renderDeliveryLine($addr);
$lines[4] = $this->renderCityLine($addr);
$lines[5] = $this->renderCountryLine($addr);
}
}
return $lines;
}
/**
* @param Address addr
* @param mixed $addr
@ -62,14 +92,9 @@ class AddressRender implements ChillEntityRenderInterface
$lines = [];
$lines[0] = $this->renderStreetLine($addr);
$lines[1] = $this->renderCityLine($addr);
if (!empty($addr->getPostcode())) {
$lines[1] = strtr('{postcode} {label}', [
'{postcode}' => $addr->getPostcode()->getCode(),
'{label}' => $addr->getPostcode()->getName(),
]);
}
//TODO simply replace this by a call to renderLines to get all other lines???
return implode(' - ', $lines);
}
@ -106,4 +131,25 @@ class AddressRender implements ChillEntityRenderInterface
return $res;
}
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();
}
}
}
return $res;
}
}