diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index 2d0bfe918..0e7b27cef 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -53,7 +53,7 @@ use Symfony\Component\Validator\Constraints as Assert; * cascade={"remove", "persist"}, * orphanRemoval=true * ) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * * @internal /!\ the serialization for write evaluations is handled in `AccompanyingPeriodWorkDenormalizer` */ @@ -61,24 +61,26 @@ use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Column(type="datetime_immutable") - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?DateTimeImmutable $createdAt = null; /** * @ORM\Column(type="boolean") + * @Serializer\Groups({"read", "docgen:read"}) */ private bool $createdAutomatically = false; /** * @ORM\Column(type="text") + * @Serializer\Groups({"read", "docgen:read"}) */ private string $createdAutomaticallyReason = ''; /** * @ORM\ManyToOne(targetEntity=User::class) * @ORM\JoinColumn(nullable=false) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?User $createdBy = null; @@ -86,7 +88,7 @@ use Symfony\Component\Validator\Constraints as Assert; * @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) * @Serializer\Groups({"accompanying_period_work:create"}) * @Serializer\Groups({"accompanying_period_work:edit"}) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Assert\GreaterThan(propertyPath="startDate", * message="accompanying_course_work.The endDate should be greater than the start date" * ) @@ -100,14 +102,14 @@ use Symfony\Component\Validator\Constraints as Assert; * cascade={"persist"}, * orphanRemoval=true * ) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"accompanying_period_work:edit"}) */ private Collection $goals; /** * @ORM\ManyToOne(targetEntity=ThirdParty::class) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"accompanying_period_work:edit"}) * * In schema : traitant @@ -118,20 +120,20 @@ use Symfony\Component\Validator\Constraints as Assert; * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ - private ?int $id; + private ?int $id = null; /** * @ORM\Column(type="text") - * @Serializer\Groups({"read", "accompanying_period_work:edit"}) + * @Serializer\Groups({"read", "accompanying_period_work:edit", "docgen:read"}) */ private string $note = ''; /** * @ORM\ManyToMany(targetEntity=Person::class) * @ORM\JoinTable(name="chill_person_accompanying_period_work_person") - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"accompanying_period_work:edit"}) * @Serializer\Groups({"accompanying_period_work:create"}) */ @@ -140,14 +142,14 @@ use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorks") * @ORM\JoinTable(name="chill_person_accompanying_period_work_result") - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"accompanying_period_work:edit"}) */ private Collection $results; /** * @ORM\ManyToOne(targetEntity=SocialAction::class) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"accompanying_period_work:create"}) */ private ?SocialAction $socialAction = null; @@ -156,30 +158,30 @@ use Symfony\Component\Validator\Constraints as Assert; * @ORM\Column(type="date_immutable") * @Serializer\Groups({"accompanying_period_work:create"}) * @Serializer\Groups({"accompanying_period_work:edit"}) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ - private DateTimeImmutable $startDate; + private ?DateTimeImmutable $startDate = null; /** * @ORM\ManyToMany(targetEntity=ThirdParty::class) * @ORM\JoinTable(name="chill_person_accompanying_period_work_third_party") * * In schema : intervenants - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"accompanying_period_work:edit"}) */ private Collection $thirdParties; /** * @ORM\Column(type="datetime_immutable") - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?DateTimeImmutable $updatedAt = null; /** * @ORM\ManyToOne(targetEntity=User::class) * @ORM\JoinColumn(nullable=false) - * @Serializer\Groups({"read"}) + * @Serializer\Groups({"read", "docgen:read"}) */ private ?User $updatedBy = null; diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php index 3478b2631..862d268d2 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php @@ -36,7 +36,7 @@ class AccompanyingPeriodParticipation /** * @ORM\Column(type="date", nullable=true) - * @Groups({"read"}) + * @Groups({"read", "read:docgen"}) */ private $endDate; @@ -44,14 +44,14 @@ class AccompanyingPeriodParticipation * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") - * @Groups({"read"}) + * @Groups({"read", "read:docgen"}) */ private $id; /** * @ORM\ManyToOne(targetEntity=Person::class, inversedBy="accompanyingPeriodParticipations") * @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false) - * @Groups({"read"}) + * @Groups({"read", "read:docgen"}) */ private $person; diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php new file mode 100644 index 000000000..7f6b47971 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php @@ -0,0 +1,100 @@ +periodContext = $periodContext; + $this->normalizer = $normalizer; + } + + /** + * @param AccompanyingPeriodWork $entity + */ + public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array + { + $data = $this->periodContext->getData($template, $entity->getAccompanyingPeriod(), $contextGenerationData); + $data['work'] = $this->normalizer->normalize($entity, 'docgen', [ + AbstractNormalizer::GROUPS => ['docgen:read'], + 'docgen:expects' => AccompanyingPeriodWork::class, + ]); + + return $data; + } + + public function getDescription(): string + { + return "A context for work"; + } + + public function getEntityClass(): string + { + return AccompanyingPeriodWork::class; + } + + public static function getKey(): string + { + return 'accompanying_period_work_regular'; + } + + public function getName(): string + { + return "Accompanying period work"; + } + + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void + { + // TODO: Implement storeGenerated() method. + } + + public function adminFormReverseTransform(array $data): array + { + return $this->periodContext->adminFormReverseTransform($data); + } + + public function adminFormTransform(array $data): array + { + return $this->periodContext->adminFormTransform($data); + } + + public function buildAdminForm(FormBuilderInterface $builder): void + { + $this->periodContext->buildAdminForm($builder); + } + + public function hasAdminForm(): bool + { + return $this->periodContext->hasAdminForm(); + } + + public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void + { + $this->periodContext->buildPublicForm($builder, $template, $entity); + } + + public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool + { + return $this->periodContext->hasPublicForm($template, $entity); + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkDocGenNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkDocGenNormalizerTest.php new file mode 100644 index 000000000..025dc73ae --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkDocGenNormalizerTest.php @@ -0,0 +1,92 @@ +normalizer = self::$container->get(NormalizerInterface::class); + } + + public function testNormlalize() + { + $work = new AccompanyingPeriodWork(); + $work + ->addPerson((new Person())->setFirstName('hello')->setLastName('name')) + ->addGoal($g = new AccompanyingPeriodWorkGoal()) + ->addResult($r = new Result()) + ->setCreatedAt(new \DateTimeImmutable()) + ->setUpdatedAt(new \DateTimeImmutable()) + ->setCreatedBy($user = new User()) + ->setUpdatedBy($user) + ; + $g->addResult($r)->setGoal($goal = new Goal()); + $goal->addResult($r); + + $actual = $this->normalizer->normalize($work, 'docgen', [ + 'docgen:expects' => AccompanyingPeriodWork::class, + AbstractNormalizer::GROUPS => ['docgen:read'] + ]); + + var_dump($actual); + + $expected = [ + 'id' => 0, + + ]; + + $this->assertIsArray($actual); + $this->assertEqualsCanonicalizing(array_keys($expected), array_keys($actual)); + + foreach ($expected as $key => $item) { + if ('@ignored' === $item) { + continue; + } + + $this->assertEquals($item, $actual[$key]); + } + } + + public function testNormalizationNull() + { + $actual = $this->normalizer->normalize(null, 'docgen', [ + 'docgen:expects' => AccompanyingPeriodWork::class, + AbstractNormalizer::GROUPS => ['docgen:read'] + ]); + + dump($actual); + + $expected = [ + 'id' => "" + ]; + + $this->assertIsArray($actual); + $this->assertEqualsCanonicalizing(array_keys($expected), array_keys($actual)); + + foreach ($expected as $key => $item) { + if ('@ignored' === $item) { + continue; + } + + $this->assertEquals($item, $actual[$key]); + } + + + + } + +}