mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
add many2many relation between socialIssue and accompanying period + api endpoint
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @param SocialIssueRender $render
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user