mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
57 lines
2.0 KiB
PHP
57 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
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;
|
|
|
|
class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
|
{
|
|
use NormalizerAwareTrait;
|
|
|
|
private ThirdPartyRender $thirdPartyRender;
|
|
|
|
public function __construct(ThirdPartyRender $thirdPartyRender)
|
|
{
|
|
$this->thirdPartyRender = $thirdPartyRender;
|
|
}
|
|
|
|
/**
|
|
* @param ThirdParty $thirdParty
|
|
*/
|
|
public function normalize($thirdParty, ?string $format = null, array $context = [])
|
|
{
|
|
return [
|
|
'type' => 'thirdparty',
|
|
'text' => $this->thirdPartyRender->renderString($thirdParty, []),
|
|
'id' => $thirdParty->getId(),
|
|
'kind' => $thirdParty->getKind(),
|
|
'address' => $this->normalizer->normalize($thirdParty->getAddress(), $format, ['address_rendering' => 'short']),
|
|
'phonenumber' => $thirdParty->getTelephone(),
|
|
'email' => $thirdParty->getEmail(),
|
|
'isChild' => $thirdParty->isChild(),
|
|
'parent' => $this->normalizer->normalize($thirdParty->getParent(), $format, $context),
|
|
'civility' => $this->normalizer->normalize($thirdParty->getCivility(), $format, $context),
|
|
'contactDataAnonymous' => $thirdParty->isContactDataAnonymous(),
|
|
'comment' => $thirdParty->getComment(),
|
|
];
|
|
}
|
|
|
|
public function supportsNormalization($data, ?string $format = null)
|
|
{
|
|
return $data instanceof ThirdParty;
|
|
}
|
|
}
|