Add docgen:read group on Person + 2 fields in PersonContext admin form

This commit is contained in:
nobohan 2022-02-28 12:33:38 +01:00
parent d163783ed3
commit 7aefa5014c
3 changed files with 36 additions and 17 deletions

View File

@ -38,6 +38,7 @@ use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Exception; use Exception;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
use function count; use function count;
@ -152,6 +153,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* *
* @ORM\Column(type="date", nullable=true) * @ORM\Column(type="date", nullable=true)
* @Birthdate * @Birthdate
* @Groups({"docgen:read"})
*/ */
private $birthdate; private $birthdate;
@ -200,6 +202,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* sf4 check: option inversedBy="birthsIn" return error mapping !! * sf4 check: option inversedBy="birthsIn" return error mapping !!
* *
* @ORM\JoinColumn(nullable=true) * @ORM\JoinColumn(nullable=true)
* @Groups({"docgen:read"})
*/ */
private $countryOfBirth; private $countryOfBirth;
@ -237,6 +240,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @Assert\Date * @Assert\Date
* @Assert\GreaterThanOrEqual(propertyPath="birthdate") * @Assert\GreaterThanOrEqual(propertyPath="birthdate")
* @Assert\LessThanOrEqual("today") * @Assert\LessThanOrEqual("today")
* @Groups({"docgen:read"})
*/ */
private ?DateTimeImmutable $deathdate = null; private ?DateTimeImmutable $deathdate = null;
@ -249,6 +253,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @Assert\Email( * @Assert\Email(
* checkMX=true * checkMX=true
* ) * )
* @Groups({"docgen:read"})
*/ */
private $email = ''; private $email = '';
@ -262,6 +267,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @Assert\Length( * @Assert\Length(
* max=255, * max=255,
* ) * )
* @Groups({"docgen:read"})
*/ */
private $firstName; private $firstName;
@ -282,6 +288,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* *
* @ORM\Column(type="string", length=9, nullable=true) * @ORM\Column(type="string", length=9, nullable=true)
* @Assert\NotNull(message="The gender must be set") * @Assert\NotNull(message="The gender must be set")
* @Groups({"docgen:read"})
*/ */
private $gender; private $gender;
@ -339,6 +346,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* *
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\MaritalStatus") * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\MaritalStatus")
* @ORM\JoinColumn(nullable=true) * @ORM\JoinColumn(nullable=true)
* @Groups({"docgen:read"})
*/ */
private $maritalStatus; private $maritalStatus;
@ -346,6 +354,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* Comment on marital status. * Comment on marital status.
* *
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="maritalStatusComment_") * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="maritalStatusComment_")
* @Groups({"docgen:read"})
*/ */
private CommentEmbeddable $maritalStatusComment; private CommentEmbeddable $maritalStatusComment;
@ -356,6 +365,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* *
* @ORM\Column(type="date", nullable=true) * @ORM\Column(type="date", nullable=true)
* @Assert\Date * @Assert\Date
* @Groups({"docgen:read"})
*/ */
private ?DateTime $maritalStatusDate = null; private ?DateTime $maritalStatusDate = null;
@ -378,6 +388,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @PhonenumberConstraint( * @PhonenumberConstraint(
* type="mobile", * type="mobile",
* ) * )
* @Groups({"docgen:read"})
*/ */
private string $mobilenumber = ''; private string $mobilenumber = '';
@ -391,6 +402,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* sf4 check: option inversedBy="nationals" return error mapping !! * sf4 check: option inversedBy="nationals" return error mapping !!
* *
* @ORM\JoinColumn(nullable=true) * @ORM\JoinColumn(nullable=true)
* @Groups({"docgen:read"})
*/ */
private $nationality; private $nationality;
@ -400,6 +412,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @var int * @var int
* *
* @ORM\Column(type="integer", nullable=true) * @ORM\Column(type="integer", nullable=true)
* @Groups({"docgen:read"})
*/ */
private ?int $numberOfChildren = null; private ?int $numberOfChildren = null;
@ -436,6 +449,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @PhonenumberConstraint( * @PhonenumberConstraint(
* type="landline", * type="landline",
* ) * )
* @Groups({"docgen:read"})
*/ */
private string $phonenumber = ''; private string $phonenumber = '';
@ -445,6 +459,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @var string * @var string
* *
* @ORM\Column(type="string", length=255, name="place_of_birth") * @ORM\Column(type="string", length=255, name="place_of_birth")
* @Groups({"docgen:read"})
*/ */
private $placeOfBirth = ''; private $placeOfBirth = '';

View File

@ -24,8 +24,11 @@ use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists; use function array_key_exists;
@ -41,11 +44,14 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
private TranslatorInterface $translator;
public function __construct( public function __construct(
DocumentCategoryRepository $documentCategoryRepository, DocumentCategoryRepository $documentCategoryRepository,
NormalizerInterface $normalizer, NormalizerInterface $normalizer,
TranslatableStringHelperInterface $translatableStringHelper, TranslatableStringHelperInterface $translatableStringHelper,
EntityManagerInterface $em, EntityManagerInterface $em,
TranslatorInterface $translator,
BaseContextData $baseContextData BaseContextData $baseContextData
) { ) {
$this->documentCategoryRepository = $documentCategoryRepository; $this->documentCategoryRepository = $documentCategoryRepository;
@ -53,6 +59,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->em = $em; $this->em = $em;
$this->baseContextData = $baseContextData; $this->baseContextData = $baseContextData;
$this->translator = $translator;
} }
public function adminFormReverseTransform(array $data): array public function adminFormReverseTransform(array $data): array
@ -69,14 +76,10 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
public function adminFormTransform(array $data): array public function adminFormTransform(array $data): array
{ {
// $r = [ $r = [
// 'mainPerson' => $data['mainPerson'] ?? false, 'mainPerson' => $data['mainPerson'] ?? false,
// 'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'), 'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
// 'person1' => $data['person1'] ?? false, ];
// 'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'),
// 'person2' => $data['person2'] ?? false,
// 'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
// ];
if (array_key_exists('category', $data)) { if (array_key_exists('category', $data)) {
$r['category'] = array_key_exists('category', $data) ? $r['category'] = array_key_exists('category', $data) ?
@ -89,14 +92,14 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
public function buildAdminForm(FormBuilderInterface $builder): void public function buildAdminForm(FormBuilderInterface $builder): void
{ {
$builder $builder
// ->add('mainPerson', CheckboxType::class, [ ->add('mainPerson', CheckboxType::class, [
// 'required' => false, 'required' => false,
// 'label' => 'docgen.Ask for main person', 'label' => 'docgen.Ask for main person',
// ]) ])
// ->add('mainPersonLabel', TextType::class, [ ->add('mainPersonLabel', TextType::class, [
// 'label' => 'main person label', 'label' => 'main person label',
// 'required' => true, 'required' => true,
// ]) ])
// ->add('person1', CheckboxType::class, [ // ->add('person1', CheckboxType::class, [
// 'required' => false, // 'required' => false,
// 'label' => 'docgen.Ask for person 1', // 'label' => 'docgen.Ask for person 1',
@ -140,7 +143,6 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface
'docgen:expects' => Person::class, 'docgen:expects' => Person::class,
'groups' => 'docgen:read' 'groups' => 'docgen:read'
]); ]);
// foreach (['mainPerson', 'person1', 'person2'] as $k) { // foreach (['mainPerson', 'person1', 'person2'] as $k) {
// if ($options[$k]) { // if ($options[$k]) {
// $data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', [ // $data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', [

View File

@ -541,6 +541,8 @@ docgen:
A basic context for accompanying period: Contexte pour les parcours A basic context for accompanying period: Contexte pour les parcours
A context for accompanying period work: Contexte pour les actions d'accompagnement A context for accompanying period work: Contexte pour les actions d'accompagnement
A context for accompanying period work evaluation: Contexte pour les évaluations dans les actions d'accompagnement A context for accompanying period work evaluation: Contexte pour les évaluations dans les actions d'accompagnement
Person basic: Personne (basique)
A basic context for person: Contexte pour les personnes
period_notification: period_notification:
period_designated_subject: Vous êtes référent d'un parcours d'accompagnement period_designated_subject: Vous êtes référent d'un parcours d'accompagnement