mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge branch 'master' into 111_exports_suite
This commit is contained in:
@@ -11,8 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Service\DocGenerator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
|
||||
@@ -34,6 +32,7 @@ use Doctrine\ORM\EntityRepository;
|
||||
use LogicException;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
@@ -42,7 +41,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
|
||||
class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
|
||||
final class PersonContext implements PersonContextInterface
|
||||
{
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
@@ -129,6 +128,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
||||
'choice_label' => function ($entity = null) {
|
||||
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
|
||||
},
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -137,11 +137,19 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
||||
*/
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||
{
|
||||
$builder->add('scope', ScopePickerType::class, [
|
||||
'center' => $this->centerResolverManager->resolveCenters($entity),
|
||||
'role' => PersonDocumentVoter::CREATE,
|
||||
'label' => 'Scope',
|
||||
$builder->add('title', TextType::class, [
|
||||
'required' => true,
|
||||
'label' => 'docgen.Document title',
|
||||
'data' => $this->translatableStringHelper->localize($template->getName()),
|
||||
]);
|
||||
|
||||
if ($this->isScopeNecessary($entity)) {
|
||||
$builder->add('scope', ScopePickerType::class, [
|
||||
'center' => $this->centerResolverManager->resolveCenters($entity),
|
||||
'role' => PersonDocumentVoter::CREATE,
|
||||
'label' => 'Scope',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
|
||||
@@ -200,7 +208,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
||||
*/
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
|
||||
{
|
||||
return $this->isScopeNecessary($entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +218,9 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
||||
{
|
||||
$doc = new PersonDocument();
|
||||
$doc->setTemplate($template)
|
||||
->setTitle($this->translatableStringHelper->localize($template->getName()))
|
||||
->setTitle(
|
||||
$contextGenerationData['title'] ?? $this->translatableStringHelper->localize($template->getName())
|
||||
)
|
||||
->setDate(new DateTime())
|
||||
->setDescription($this->translatableStringHelper->localize($template->getName()))
|
||||
->setPerson($entity)
|
||||
|
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Service\DocGenerator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
|
||||
{
|
||||
public function adminFormReverseTransform(array $data): array;
|
||||
|
||||
public function adminFormTransform(array $data): array;
|
||||
|
||||
public function buildAdminForm(FormBuilderInterface $builder): void;
|
||||
|
||||
/**
|
||||
* @param Person $entity
|
||||
*/
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
|
||||
|
||||
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array;
|
||||
|
||||
public function getDescription(): string;
|
||||
|
||||
public function getEntityClass(): string;
|
||||
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array;
|
||||
|
||||
public function getName(): string;
|
||||
|
||||
public function hasAdminForm(): bool;
|
||||
|
||||
/**
|
||||
* @param Person $entity
|
||||
*/
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
|
||||
|
||||
/**
|
||||
* @param Person $entity
|
||||
*/
|
||||
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void;
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Service\DocGenerator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
/**
|
||||
* Context to generate a document with a destinee (i.e. generate a letter).
|
||||
*/
|
||||
class PersonContextWithThirdParty implements DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
private PersonContextInterface $personContext;
|
||||
|
||||
public function __construct(
|
||||
PersonContextInterface $personContext,
|
||||
NormalizerInterface $normalizer
|
||||
) {
|
||||
$this->personContext = $personContext;
|
||||
$this->normalizer = $normalizer;
|
||||
}
|
||||
|
||||
public function adminFormReverseTransform(array $data): array
|
||||
{
|
||||
return array_merge(
|
||||
$this->personContext->adminFormReverseTransform($data),
|
||||
['label' => $data['label']]
|
||||
);
|
||||
}
|
||||
|
||||
public function adminFormTransform(array $data): array
|
||||
{
|
||||
return array_merge(
|
||||
$this->personContext->adminFormTransform($data),
|
||||
['label' => $data['label'] ?? '']
|
||||
);
|
||||
}
|
||||
|
||||
public function buildAdminForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
$this->personContext->buildAdminForm($builder);
|
||||
|
||||
$builder->add('label', TextType::class, [
|
||||
'label' => 'docgen.Label for third party',
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||
{
|
||||
$this->personContext->buildPublicForm($builder, $template, $entity);
|
||||
|
||||
$builder->add('thirdParty', PickThirdpartyDynamicType::class, [
|
||||
'multiple' => false,
|
||||
'label' => $template->getOptions()['label'] ?? 'ThirdParty',
|
||||
'validation_groups' => ['__none__'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
|
||||
{
|
||||
$data = $this->personContext->getData($template, $entity, $contextGenerationData);
|
||||
|
||||
$data['thirdParty'] = $this->normalizer->normalize(
|
||||
$contextGenerationData['thirdParty'],
|
||||
'docgen',
|
||||
['docgen:expects' => ThirdParty::class, 'groups' => ['docgen:read']]
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'docgen.A context for person with a third party (for sending mail)';
|
||||
}
|
||||
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return $this->personContext->getEntityClass();
|
||||
}
|
||||
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array
|
||||
{
|
||||
return $this->personContext->getFormData($template, $entity);
|
||||
}
|
||||
|
||||
public static function getKey(): string
|
||||
{
|
||||
return self::class;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'docgen.Person with third party';
|
||||
}
|
||||
|
||||
public function hasAdminForm(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
|
||||
{
|
||||
$this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData);
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Serializer\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AccompanyingPeriodResourceNormalizerTest extends KernelTestCase
|
||||
{
|
||||
private NormalizerInterface $normalizer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||
}
|
||||
|
||||
public function testNormalizeNullHasSameValueAsNotNull()
|
||||
{
|
||||
$nullResource = $this->normalizer->normalize(null, 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
|
||||
$notNull = $this->normalizer->normalize(new Resource(), 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
|
||||
|
||||
$this->assertEqualsCanonicalizing(array_keys($notNull), array_keys($nullResource));
|
||||
}
|
||||
|
||||
public function testNormalizeResource()
|
||||
{
|
||||
$resource = new Resource();
|
||||
$resource
|
||||
->setComment('blabla')
|
||||
->setResource(new ThirdParty());
|
||||
|
||||
$expected = [
|
||||
'type' => 'accompanying_period_resource',
|
||||
'isNull' => false,
|
||||
'comment' => 'blabla',
|
||||
];
|
||||
|
||||
$actual = $this->normalizer->normalize($resource, 'docgen', ['groups' => 'docgen:read', 'docgen:expects' => Resource::class]);
|
||||
|
||||
// we do not test for sub array (person, thirdparty). We then check first for base value...
|
||||
foreach ($expected as $key => $value) {
|
||||
$this->assertArrayHasKey($key, $actual);
|
||||
$this->assertEquals($value, $actual[$key]);
|
||||
}
|
||||
|
||||
// ... and then for the existence of some values
|
||||
$this->assertArrayHasKey('person', $actual);
|
||||
$this->assertArrayHasKey('thirdParty', $actual);
|
||||
}
|
||||
}
|
@@ -21,6 +21,7 @@ use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\Type\ScopePickerType;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
@@ -33,6 +34,8 @@ use Prophecy\Exception\Prediction\FailedPredictionException;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
@@ -82,7 +85,7 @@ final class PersonContextTest extends TestCase
|
||||
$parameter
|
||||
);
|
||||
|
||||
$this->assertFalse($personContext->hasPublicForm($docGen, $person));
|
||||
$personContext->buildPublicForm($this->buildFormBuilder(false), $docGen, $person);
|
||||
|
||||
$personContext->storeGenerated(
|
||||
$docGen,
|
||||
@@ -126,7 +129,7 @@ final class PersonContextTest extends TestCase
|
||||
$em->reveal(),
|
||||
);
|
||||
|
||||
$this->assertTrue($personContext->hasPublicForm($docGen, $person));
|
||||
$personContext->buildPublicForm($this->buildFormBuilder(true), $docGen, $person);
|
||||
|
||||
$personContext->storeGenerated(
|
||||
$docGen,
|
||||
@@ -170,7 +173,7 @@ final class PersonContextTest extends TestCase
|
||||
$em->reveal(),
|
||||
);
|
||||
|
||||
$this->assertTrue($personContext->hasPublicForm($docGen, $person));
|
||||
$personContext->buildPublicForm($this->buildFormBuilder(true), $docGen, $person);
|
||||
|
||||
$personContext->storeGenerated(
|
||||
$docGen,
|
||||
@@ -180,6 +183,24 @@ final class PersonContextTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
private function buildFormBuilder(bool $withScope): FormBuilderInterface
|
||||
{
|
||||
$builder = $this->prophesize(FormBuilderInterface::class);
|
||||
|
||||
$builder->add('title', TextType::class, Argument::type('array'))
|
||||
->shouldBeCalled(1);
|
||||
|
||||
if ($withScope) {
|
||||
$builder->add('scope', ScopePickerType::class, Argument::type('array'))
|
||||
->shouldBeCalled();
|
||||
} else {
|
||||
$builder->add('scope', ScopePickerType::class, Argument::type('array'))
|
||||
->shouldNotBeCalled();
|
||||
}
|
||||
|
||||
return $builder->reveal();
|
||||
}
|
||||
|
||||
private function buildPersonContext(
|
||||
?AuthorizationHelperInterface $authorizationHelper = null,
|
||||
?BaseContextData $baseContextData = null,
|
||||
|
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Service\DocGenerator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Service\DocGenerator\PersonContextInterface;
|
||||
use Chill\PersonBundle\Service\DocGenerator\PersonContextWithThirdParty;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PersonContextWithThirdPartyTest extends KernelTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testAdminFormReverseTransform()
|
||||
{
|
||||
$personContext = $this->buildPersonContextWithThirdParty();
|
||||
|
||||
$actual = $personContext->adminFormReverseTransform(['label' => 'bloup']);
|
||||
|
||||
$this->assertArrayHasKey('category', $actual);
|
||||
$this->assertArrayHasKey('label', $actual);
|
||||
$this->assertEquals('bloup', $actual['label']);
|
||||
}
|
||||
|
||||
public function testAdminFormTransform()
|
||||
{
|
||||
$personContext = $this->buildPersonContextWithThirdParty();
|
||||
|
||||
$actual = $personContext->adminFormTransform(['label' => 'bloup']);
|
||||
|
||||
$this->assertArrayHasKey('from_person', $actual);
|
||||
$this->assertArrayHasKey('label', $actual);
|
||||
$this->assertEquals('bloup', $actual['label']);
|
||||
}
|
||||
|
||||
public function testGetData()
|
||||
{
|
||||
$personContext = $this->buildPersonContextWithThirdParty();
|
||||
|
||||
$actual = $personContext->getData(
|
||||
(new DocGeneratorTemplate())->setOptions(['label' => 'bloup']),
|
||||
new Person(),
|
||||
['thirdParty' => $tp = new ThirdParty()]
|
||||
);
|
||||
|
||||
$this->assertArrayHasKey('person', $actual);
|
||||
$this->assertArrayHasKey('thirdParty', $actual);
|
||||
$this->assertEquals(spl_object_hash($tp), $actual['thirdParty']['hash']);
|
||||
}
|
||||
|
||||
private function buildPersonContextWithThirdParty(): PersonContextWithThirdParty
|
||||
{
|
||||
$normalizer = $this->prophesize(NormalizerInterface::class);
|
||||
$normalizer->normalize(Argument::type(ThirdParty::class), 'docgen', Argument::type('array'))
|
||||
->will(static function ($args): array {
|
||||
return ['class' => '3party', 'hash' => spl_object_hash($args[0])];
|
||||
});
|
||||
|
||||
$personContext = $this->prophesize(PersonContextInterface::class);
|
||||
|
||||
$personContext->adminFormReverseTransform(Argument::type('array'))->willReturn(
|
||||
['category' => ['idInsideBundle' => 1, 'bundleId' => 'abc']]
|
||||
);
|
||||
$personContext->adminFormTransform(Argument::type('array'))->willReturn(
|
||||
['from_person' => 'kept']
|
||||
);
|
||||
$personContext->getData(Argument::type(DocGeneratorTemplate::class), Argument::type(Person::class), Argument::type('array'))
|
||||
->willReturn(['person' => 'data']);
|
||||
|
||||
return new PersonContextWithThirdParty(
|
||||
$personContext->reveal(),
|
||||
$normalizer->reveal()
|
||||
);
|
||||
}
|
||||
}
|
@@ -889,6 +889,10 @@ docgen:
|
||||
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
|
||||
Person with third party: Personne avec choix d'un tiers
|
||||
A context for person with a third party (for sending mail): Un contexte d'une personne avec un tiers (pour envoyer un courrier à ce tiers, par exemple)
|
||||
Label for third party: Label à afficher aux utilisateurs
|
||||
Document title: Titre du document généré
|
||||
|
||||
period_notification:
|
||||
period_designated_subject: Vous êtes référent d'un parcours d'accompagnement
|
||||
|
Reference in New Issue
Block a user