improve layout of third parties in AddPerson

This commit is contained in:
2021-10-11 11:07:49 +02:00
parent c54edd8407
commit 08764aa0b4
7 changed files with 120 additions and 29 deletions

View File

@@ -20,7 +20,7 @@
#}
{% macro raw(thirdparty, options) %}
<span class="name">{{ thirdparty.name }}</span>
<span class="name">{{ thirdparty|chill_entity_render_string }}</span>
{% endmacro raw %}
{% macro label(thirdparty, options) %}

View File

@@ -3,6 +3,7 @@
namespace Chill\ThirdPartyBundle\Serializer\Normalizer;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -12,19 +13,27 @@ class ThirdPartyNormalizer implements NormalizerInterface, NormalizerAwareInterf
{
use NormalizerAwareTrait;
private ThirdPartyRender $thirdPartyRender;
public function __construct(ThirdPartyRender $thirdPartyRender)
{
$this->thirdPartyRender = $thirdPartyRender;
}
public function normalize($thirdParty, string $format = null, array $context = [])
{
/** @var $thirdParty ThirdParty */
$data['type'] = 'thirdparty';
// TODO should be replaced by a "render entity"
$data['text'] = $thirdParty->getName();
$data['text'] = $this->thirdPartyRender->renderString($thirdParty, []);
$data['id'] = $thirdParty->getId();
$data['kind'] = $thirdParty->getKind();
$data['address'] = $this->normalizer->normalize($thirdParty->getAddress(), $format,
[ 'address_rendering' => 'short' ]);
$data['phonenumber'] = $thirdParty->getTelephone();
$data['email'] = $thirdParty->getEmail();
$data['isChild'] = $thirdParty->isChild();
$data['parent'] = $this->normalizer->normalize($thirdParty->getParent(), $format, $context);
$data['civility'] = $this->normalizer->normalize($thirdParty->getCivility(), $format, $context);
return $data;
}

View File

@@ -21,6 +21,7 @@
namespace Chill\ThirdPartyBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Templating\EngineInterface;
@@ -32,10 +33,15 @@ class ThirdPartyRender extends AbstractChillEntityRender
{
protected EngineInterface $engine;
protected TranslatableStringHelper $translatableStringHelper;
public function __construct(EngineInterface $engine)
public function __construct(
EngineInterface $engine,
TranslatableStringHelper $translatableStringHelper
)
{
$this->engine = $engine;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
@@ -76,7 +82,18 @@ class ThirdPartyRender extends AbstractChillEntityRender
*/
public function renderString($entity, array $options): string
{
return $entity->getName();
if ($entity->getCivility() !== NULL) {
$civility = $this->translatableStringHelper
->localize($entity->getCivility()->getAbbreviation()).' ';
} else {
$civility = '';
}
if (!empty($entity->getAcronym())) {
$acronym = ' ('.$entity->getAcronym().')';
} else {
$acronym = '';
}
return $civility.$entity->getName().$acronym;
}
public function supports($entity, array $options): bool

View File

@@ -1,6 +1,6 @@
services:
Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender:
arguments:
$engine: '@Symfony\Component\Templating\EngineInterface'
autowire: true
autoconfigure: true
tags:
- 'chill.render_entity'

View File

@@ -39,6 +39,7 @@ thirdparty.a_company_explanation: >-
thirdparty.a_contact_explanation: >-
Les personnes physiques ne disposent pas d'acronyme, de service, ou de contacts sous-jacents.
thirdparty.Which kind of third party ?: Quel type de tiers souhaitez-vous créer ?
thirdparty.Contact data are confidential: Données de contact confidentielles
New third party: Ajouter un nouveau tiers
Show third party %name%: Tiers "%name%"