diff --git a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithAdminFormInterface.php b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithAdminFormInterface.php index 28ad70170..3b606ccb5 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithAdminFormInterface.php +++ b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithAdminFormInterface.php @@ -13,7 +13,7 @@ namespace Chill\DocGeneratorBundle\Context; use Symfony\Component\Form\FormBuilderInterface; -interface DocGeneratorContextWithAdminFormInterface +interface DocGeneratorContextWithAdminFormInterface extends DocGeneratorContextInterface { public function adminFormReverseTransform(array $data): array; diff --git a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php index 391dff580..402802501 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php +++ b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php @@ -14,7 +14,7 @@ namespace Chill\DocGeneratorBundle\Context; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Symfony\Component\Form\FormBuilderInterface; -interface DocGeneratorContextWithPublicFormInterface +interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContextInterface { /** * Generate the form that display. diff --git a/src/Bundle/ChillDocGeneratorBundle/Form/DocGeneratorTemplateType.php b/src/Bundle/ChillDocGeneratorBundle/Form/DocGeneratorTemplateType.php index f52962a41..4275cf53e 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Form/DocGeneratorTemplateType.php +++ b/src/Bundle/ChillDocGeneratorBundle/Form/DocGeneratorTemplateType.php @@ -18,6 +18,7 @@ use Chill\DocStoreBundle\Form\StoredObjectType; use Chill\MainBundle\Form\Type\TranslatableStringFormType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\CallbackTransformer; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -43,6 +44,14 @@ class DocGeneratorTemplateType extends AbstractType ->add('description') ->add('file', StoredObjectType::class, [ 'error_bubbling' => true, + ]) + ->add('active', ChoiceType::class, [ + 'label' => 'Active', + 'choices' => [ + 'Yes' => true, + 'No' => false, + ], + 'required' => true, ]); if ($context instanceof DocGeneratorContextWithAdminFormInterface diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php index 26dc29b25..5227770eb 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php @@ -64,26 +64,36 @@ class AccompanyingPeriodContext implements public function adminFormReverseTransform(array $data): array { - return [ + $data = [ 'mainPerson' => $data['mainPerson'], 'person1' => $data['person1'], 'person2' => $data['person2'], - 'category' => [ + ]; + + if (array_key_exists('category', $data)) { + $data['category'] = [ 'idInsideBundle' => $data['category']->getIdInsideBundle(), 'bundleId' => $data['category']->getBundleId(), - ], - ]; + ]; + } + + return $data; } public function adminFormTransform(array $data): array { - return [ + $data = [ 'mainPerson' => $data['mainPerson'] ?? false, 'person1' => $data['person1'] ?? false, 'person2' => $data['person2'] ?? false, - 'category' => array_key_exists('category', $data) ? - $this->documentCategoryRepository->find($data['category']) : null, ]; + + if (array_key_exists('category', $data)) { + $data['category'] = array_key_exists('category', $data) ? + $this->documentCategoryRepository->find($data['category']) : null; + } + + return $data; } public function buildAdminForm(FormBuilderInterface $builder): void diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php index 7f6b47971..22c898f9d 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php @@ -1,5 +1,14 @@ normalizer = $normalizer; } + 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 buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void + { + $this->periodContext->buildPublicForm($builder, $template, $entity); + } + /** * @param AccompanyingPeriodWork $entity */ @@ -45,7 +74,7 @@ class AccompanyingPeriodWorkContext implements public function getDescription(): string { - return "A context for work"; + return 'A context for work'; } public function getEntityClass(): string @@ -60,27 +89,7 @@ class AccompanyingPeriodWorkContext implements 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); + return 'Accompanying period work'; } public function hasAdminForm(): bool @@ -88,13 +97,13 @@ class AccompanyingPeriodWorkContext implements 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); } + + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void + { + // TODO: Implement storeGenerated() method. + } } diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php new file mode 100644 index 000000000..1f17ce48a --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -0,0 +1,143 @@ +accompanyingPeriodWorkContext = $accompanyingPeriodWorkContext; + $this->em = $em; + $this->evaluationRepository = $evaluationRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function adminFormReverseTransform(array $data): array + { + return array_merge( + $this->accompanyingPeriodWorkContext->adminFormReverseTransform($data), + [ + 'evaluations' => array_map( + static function (Evaluation $e) { return $e->getId(); }, + $data['evaluations'] + ), + ] + ); + } + + public function adminFormTransform(array $data): array + { + return array_merge( + $this->accompanyingPeriodWorkContext->adminFormTransform($data), + [ + 'evaluations' => array_map( + function ($id) { return $this->evaluationRepository->find($id); }, + $data['evaluations'] ?? [] + ), + ] + ); + } + + public function buildAdminForm(FormBuilderInterface $builder): void + { + $this->accompanyingPeriodWorkContext->buildAdminForm($builder); + + $builder->remove('category'); + + $builder->add('evaluations', EntityType::class, [ + 'class' => Evaluation::class, + 'label' => 'Linked evaluations', + 'choices' => $this->evaluationRepository->findAll(), + 'choice_label' => function (Evaluation $e) { + return $this->translatableStringHelper->localize($e->getTitle()); + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void + { + // TODO: Implement buildPublicForm() method. + } + + public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array + { + // TODO: Implement getData() method. + } + + public function getDescription(): string + { + return 'Context for accompanying period work'; + } + + public function getEntityClass(): string + { + return AccompanyingPeriodWorkEvaluation::class; + } + + public static function getKey(): string + { + return 'accompanying_period_work_evaluation_regular'; + } + + public function getName(): string + { + return 'Accompanying period work context'; + } + + public function hasAdminForm(): bool + { + return true; + } + + public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool + { + // TODO: Implement hasPublicForm() method. + } + + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void + { + $doc = new AccompanyingPeriodWorkEvaluationDocument(); + $doc->setStoredObject($storedObject) + ->setAccompanyingPeriodWorkEvaluation($entity) + ->setTemplate($template); + $this->em->persist($doc); + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkDocGenNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkDocGenNormalizerTest.php index 025dc73ae..2417e93da 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkDocGenNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodWorkDocGenNormalizerTest.php @@ -1,5 +1,14 @@ normalizer = self::$container->get(NormalizerInterface::class); } + 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]); + } + } + public function testNormlalize() { $work = new AccompanyingPeriodWork(); @@ -29,24 +68,22 @@ class AccompanyingPeriodWorkDocGenNormalizerTest extends KernelTestCase ->addPerson((new Person())->setFirstName('hello')->setLastName('name')) ->addGoal($g = new AccompanyingPeriodWorkGoal()) ->addResult($r = new Result()) - ->setCreatedAt(new \DateTimeImmutable()) - ->setUpdatedAt(new \DateTimeImmutable()) + ->setCreatedAt(new DateTimeImmutable()) + ->setUpdatedAt(new DateTimeImmutable()) ->setCreatedBy($user = new User()) - ->setUpdatedBy($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'] + AbstractNormalizer::GROUPS => ['docgen:read'], ]); var_dump($actual); $expected = [ 'id' => 0, - ]; $this->assertIsArray($actual); @@ -60,33 +97,4 @@ class AccompanyingPeriodWorkDocGenNormalizerTest extends KernelTestCase $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]); - } - - - - } - }