mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Merge branch 'master' into notification/completion
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Chill\MainBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Templating\Entity\AddressRender;
|
||||
use DateTimeInterface;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
@@ -46,6 +47,13 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
|
||||
'validTo' => DateTimeInterface::class,
|
||||
];
|
||||
|
||||
private AddressRender $addressRender;
|
||||
|
||||
public function __construct(AddressRender $addressRender)
|
||||
{
|
||||
$this->addressRender = $addressRender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address $address
|
||||
* @param string|null $format
|
||||
@@ -53,19 +61,9 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
|
||||
public function normalize($address, $format = null, array $context = [])
|
||||
{
|
||||
if ($address instanceof Address) {
|
||||
$text = $address->isNoAddress() ? '' : $address->getStreet() . ', ' . $address->getStreetNumber();
|
||||
|
||||
if (null !== $address->getPostCode()->getCountry()->getCountryCode()) {
|
||||
if ($address->getPostCode()->getCountry()->getCountryCode() === 'FR') {
|
||||
$text = $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet();
|
||||
} else {
|
||||
$text = $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet();
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'address_id' => $address->getId(),
|
||||
'text' => $text,
|
||||
'text' => $address->isNoAddress() ? null : $this->addressRender->renderStreetLine($address, []),
|
||||
'street' => $address->getStreet(),
|
||||
'streetNumber' => $address->getStreetNumber(),
|
||||
'postcode' => [
|
||||
@@ -85,6 +83,7 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
|
||||
'buildingName' => $address->getBuildingName(),
|
||||
'distribution' => $address->getDistribution(),
|
||||
'extra' => $address->getExtra(),
|
||||
'lines' => $this->addressRender->renderLines($address),
|
||||
];
|
||||
|
||||
if ('json' === $format) {
|
||||
|
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
@@ -55,16 +56,21 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
|
||||
$context,
|
||||
['docgen:expects' => Center::class, 'groups' => 'docgen:read']
|
||||
);
|
||||
$locationContext = array_merge(
|
||||
$context,
|
||||
['docgen:expects' => Location::class, 'groups' => 'dogen:read']
|
||||
);
|
||||
|
||||
if (null === $user && 'docgen' === $format) {
|
||||
return array_merge(self::NULL_USER, [
|
||||
'user_job' => $this->normalizer->normalize(null, $format, $userJobContext),
|
||||
'main_center' => $this->normalizer->normalize(null, $format, $centerContext),
|
||||
'main_scope' => $this->normalizer->normalize(null, $format, $scopeContext),
|
||||
'current_location' => $this->normalizer->normalize(null, $format, $locationContext),
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
$data = [
|
||||
'type' => 'user',
|
||||
'id' => $user->getId(),
|
||||
'username' => $user->getUsername(),
|
||||
@@ -75,6 +81,12 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware
|
||||
'main_center' => $this->normalizer->normalize($user->getMainCenter(), $format, $centerContext),
|
||||
'main_scope' => $this->normalizer->normalize($user->getMainScope(), $format, $scopeContext),
|
||||
];
|
||||
|
||||
if ('docgen' === $format) {
|
||||
$data['current_location'] = $this->normalizer->normalize($user->getCurrentLocation(), $format, $locationContext);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, $format = null, array $context = []): bool
|
||||
|
Reference in New Issue
Block a user