mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Chill\PersonBundle\Serializer\Normalizer;
|
|
|
|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
|
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
|
|
|
class SocialIssueNormalizer implements NormalizerInterface, NormalizerAwareInterface
|
|
{
|
|
private SocialIssueRender $render;
|
|
|
|
use NormalizerAwareTrait;
|
|
|
|
public function __construct(SocialIssueRender $render)
|
|
{
|
|
$this->render = $render;
|
|
}
|
|
|
|
public function normalize($socialIssue, string $format = null, array $context = [])
|
|
{
|
|
/** @var SocialIssue $socialIssue */
|
|
return [
|
|
'type' => 'social_issue',
|
|
'id' => $socialIssue->getId(),
|
|
'parent_id' => $socialIssue->hasParent() ? $socialIssue->getParent()->getId() : null,
|
|
'children_ids' => $socialIssue->getChildren()->map(function (SocialIssue $si) { return $si->getId(); }),
|
|
'title' => $socialIssue->getTitle(),
|
|
'text' => $this->render->renderString($socialIssue, [])
|
|
];
|
|
}
|
|
|
|
public function supportsNormalization($data, string $format = null): bool
|
|
{
|
|
return $data instanceof SocialIssue;
|
|
}
|
|
}
|