mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'master' into 111_exports_suite
This commit is contained in:
commit
81c73f6acf
@ -265,7 +265,7 @@ Tests reside inside the installed bundles. You must `cd` into that directory, do
|
|||||||
|
|
||||||
**Note**: some bundle require the fixture to be executed. See the dedicated _how-tos_.
|
**Note**: some bundle require the fixture to be executed. See the dedicated _how-tos_.
|
||||||
|
|
||||||
Exemple, for running test inside `main` bundle:
|
Exemple, for running unit test inside `main` bundle:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
@ -280,6 +280,30 @@ Exemple, for running test inside `main` bundle:
|
|||||||
# run tests
|
# run tests
|
||||||
bin/phpunit src/Bundle/path/to/your/test
|
bin/phpunit src/Bundle/path/to/your/test
|
||||||
|
|
||||||
|
Or for running tests to check code style and php conventions with csfixer and phpstan:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
# run code style fixer
|
||||||
|
bin/grumphp run --tasks=phpcsfixer
|
||||||
|
# run phpstan
|
||||||
|
bin/grumphp run --tasks=phpstan
|
||||||
|
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
To avoid phpstan block your commits:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
git commit -n ...
|
||||||
|
|
||||||
|
To avoid phpstan block your commits permanently:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
./bin/grumphp git:deinit
|
||||||
|
|
||||||
How to run webpack interactively
|
How to run webpack interactively
|
||||||
================================
|
================================
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@ namespace Chill\DocGeneratorBundle\Controller;
|
|||||||
use Chill\DocGeneratorBundle\Context\ContextManager;
|
use Chill\DocGeneratorBundle\Context\ContextManager;
|
||||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||||
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
use Chill\MainBundle\CRUD\Controller\CRUDController;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
@ -84,4 +86,16 @@ class AdminDocGeneratorTemplateController extends CRUDController
|
|||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param QueryBuilder $query
|
||||||
|
*
|
||||||
|
* @return QueryBuilder|mixed
|
||||||
|
*/
|
||||||
|
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
|
||||||
|
{
|
||||||
|
return $query->addSelect('JSON_EXTRACT(e.name, :lang) AS HIDDEN name_lang')
|
||||||
|
->setParameter('lang', $request->getLocale())
|
||||||
|
->addOrderBy('name_lang', 'ASC');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,18 @@ use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
|
||||||
final class DocGeneratorTemplateRepository implements ObjectRepository
|
final class DocGeneratorTemplateRepository implements ObjectRepository
|
||||||
{
|
{
|
||||||
private EntityRepository $repository;
|
private EntityRepository $repository;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $entityManager)
|
private RequestStack $requestStack;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $entityManager, RequestStack $requestStack)
|
||||||
{
|
{
|
||||||
$this->repository = $entityManager->getRepository(DocGeneratorTemplate::class);
|
$this->repository = $entityManager->getRepository(DocGeneratorTemplate::class);
|
||||||
|
$this->requestStack = $requestStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countByEntity(string $entity): int
|
public function countByEntity(string $entity): int
|
||||||
@ -71,7 +75,10 @@ final class DocGeneratorTemplateRepository implements ObjectRepository
|
|||||||
$builder
|
$builder
|
||||||
->where('t.entity LIKE :entity')
|
->where('t.entity LIKE :entity')
|
||||||
->andWhere($builder->expr()->eq('t.active', "'TRUE'"))
|
->andWhere($builder->expr()->eq('t.active', "'TRUE'"))
|
||||||
->setParameter('entity', addslashes($entity));
|
->setParameter('entity', addslashes($entity))
|
||||||
|
->addSelect('JSON_EXTRACT(t.name, :lang) AS HIDDEN name_lang')
|
||||||
|
->setParameter('lang', $this->requestStack->getCurrentRequest()->getLocale())
|
||||||
|
->addOrderBy('name_lang', 'ASC');
|
||||||
|
|
||||||
return $builder
|
return $builder
|
||||||
->getQuery()
|
->getQuery()
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
{% block title 'docgen.Generate a document'|trans %}
|
{% block title 'docgen.Generate a document'|trans %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{{ encore_entry_script_tags('mod_pickentity_type') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block css %}
|
||||||
|
{{ encore_entry_link_tags('mod_pickentity_type') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="col-md-10 col-xxl">
|
<div class="col-md-10 col-xxl">
|
||||||
<h1>{{ block('title') }}</h1>
|
<h1>{{ block('title') }}</h1>
|
||||||
|
@ -42,6 +42,9 @@ class BaseContextData
|
|||||||
$data['createdAt'] = $this->normalizer->normalize(new DateTimeImmutable(), 'docgen', [
|
$data['createdAt'] = $this->normalizer->normalize(new DateTimeImmutable(), 'docgen', [
|
||||||
'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
|
'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
|
||||||
]);
|
]);
|
||||||
|
$data['createdAtDate'] = $this->normalizer->normalize(new DateTimeImmutable('today'), 'docgen', [
|
||||||
|
'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
|
||||||
|
]);
|
||||||
$data['location'] = $this->normalizer->normalize(
|
$data['location'] = $this->normalizer->normalize(
|
||||||
$user instanceof User ? $user->getCurrentLocation() : null,
|
$user instanceof User ? $user->getCurrentLocation() : null,
|
||||||
'docgen',
|
'docgen',
|
||||||
|
@ -77,6 +77,19 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
|||||||
$this->assertArrayNotHasKey('baz', $actual['child']);
|
$this->assertArrayNotHasKey('baz', $actual['child']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNormalizableBooleanPropertyOrMethodOnNull()
|
||||||
|
{
|
||||||
|
$actual = $this->normalizer->normalize(null, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => TestableClassWithBool::class]);
|
||||||
|
|
||||||
|
$expected = [
|
||||||
|
'foo' => null,
|
||||||
|
'thing' => null,
|
||||||
|
'isNull' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
public function testNormalizationBasic()
|
public function testNormalizationBasic()
|
||||||
{
|
{
|
||||||
$scope = new Scope();
|
$scope = new Scope();
|
||||||
@ -93,6 +106,22 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
|||||||
$this->assertEquals($expected, $normalized, 'test normalization fo a scope');
|
$this->assertEquals($expected, $normalized, 'test normalization fo a scope');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNormalizeBooleanPropertyOrMethod()
|
||||||
|
{
|
||||||
|
$testable = new TestableClassWithBool();
|
||||||
|
$testable->foo = false;
|
||||||
|
|
||||||
|
$actual = $this->normalizer->normalize($testable, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => TestableClassWithBool::class]);
|
||||||
|
|
||||||
|
$expected = [
|
||||||
|
'foo' => false,
|
||||||
|
'thing' => true,
|
||||||
|
'isNull' => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
public function testNormalizeNull()
|
public function testNormalizeNull()
|
||||||
{
|
{
|
||||||
$actual = $this->normalizer->normalize(null, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => Scope::class]);
|
$actual = $this->normalizer->normalize(null, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => Scope::class]);
|
||||||
@ -170,3 +199,19 @@ class TestableChildClass
|
|||||||
*/
|
*/
|
||||||
public string $foo = 'bar';
|
public string $foo = 'bar';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestableClassWithBool
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Serializer\Groups("docgen:read")
|
||||||
|
*/
|
||||||
|
public bool $foo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Serializer\Groups("docgen:read")
|
||||||
|
*/
|
||||||
|
public function getThing(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -28,6 +28,7 @@ use Chill\MainBundle\Doctrine\DQL\GetJsonFieldByKey;
|
|||||||
use Chill\MainBundle\Doctrine\DQL\JsonAggregate;
|
use Chill\MainBundle\Doctrine\DQL\JsonAggregate;
|
||||||
use Chill\MainBundle\Doctrine\DQL\JsonbArrayLength;
|
use Chill\MainBundle\Doctrine\DQL\JsonbArrayLength;
|
||||||
use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray;
|
use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray;
|
||||||
|
use Chill\MainBundle\Doctrine\DQL\JsonExtract;
|
||||||
use Chill\MainBundle\Doctrine\DQL\OverlapsI;
|
use Chill\MainBundle\Doctrine\DQL\OverlapsI;
|
||||||
use Chill\MainBundle\Doctrine\DQL\Replace;
|
use Chill\MainBundle\Doctrine\DQL\Replace;
|
||||||
use Chill\MainBundle\Doctrine\DQL\Similarity;
|
use Chill\MainBundle\Doctrine\DQL\Similarity;
|
||||||
@ -232,6 +233,7 @@ class ChillMainExtension extends Extension implements
|
|||||||
'GET_JSON_FIELD_BY_KEY' => GetJsonFieldByKey::class,
|
'GET_JSON_FIELD_BY_KEY' => GetJsonFieldByKey::class,
|
||||||
'AGGREGATE' => JsonAggregate::class,
|
'AGGREGATE' => JsonAggregate::class,
|
||||||
'REPLACE' => Replace::class,
|
'REPLACE' => Replace::class,
|
||||||
|
'JSON_EXTRACT' => JsonExtract::class,
|
||||||
],
|
],
|
||||||
'numeric_functions' => [
|
'numeric_functions' => [
|
||||||
'JSONB_EXISTS_IN_ARRAY' => JsonbExistsInArray::class,
|
'JSONB_EXISTS_IN_ARRAY' => JsonbExistsInArray::class,
|
||||||
|
43
src/Bundle/ChillMainBundle/Doctrine/DQL/JsonExtract.php
Normal file
43
src/Bundle/ChillMainBundle/Doctrine/DQL/JsonExtract.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?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\MainBundle\Doctrine\DQL;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
||||||
|
use Doctrine\ORM\Query\Lexer;
|
||||||
|
use Doctrine\ORM\Query\Parser;
|
||||||
|
use Doctrine\ORM\Query\SqlWalker;
|
||||||
|
|
||||||
|
class JsonExtract extends FunctionNode
|
||||||
|
{
|
||||||
|
private $element;
|
||||||
|
|
||||||
|
private $keyToExtract;
|
||||||
|
|
||||||
|
public function getSql(SqlWalker $sqlWalker)
|
||||||
|
{
|
||||||
|
return sprintf('%s->>%s', $this->element->dispatch($sqlWalker), $this->keyToExtract->dispatch($sqlWalker));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(Parser $parser)
|
||||||
|
{
|
||||||
|
$parser->match(Lexer::T_IDENTIFIER);
|
||||||
|
$parser->match(Lexer::T_OPEN_PARENTHESIS);
|
||||||
|
|
||||||
|
$this->element = $parser->ArithmeticPrimary();
|
||||||
|
|
||||||
|
$parser->match(Lexer::T_COMMA);
|
||||||
|
|
||||||
|
$this->keyToExtract = $parser->ArithmeticExpression();
|
||||||
|
|
||||||
|
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
<?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 Doctrine\DQL;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Country;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
final class JsonExtractTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
|
||||||
|
$this->em = self::$container->get(EntityManagerInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dataGenerateDql(): iterable
|
||||||
|
{
|
||||||
|
yield ['SELECT JSON_EXTRACT(c.name, \'fr\') FROM ' . Country::class . ' c', []];
|
||||||
|
|
||||||
|
yield ['SELECT JSON_EXTRACT(c.name, :lang) FROM ' . Country::class . ' c', ['lang' => 'fr']];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataGenerateDql
|
||||||
|
*/
|
||||||
|
public function testJsonExtract(string $dql, array $args)
|
||||||
|
{
|
||||||
|
$results = $this->em->createQuery($dql)
|
||||||
|
->setMaxResults(2)
|
||||||
|
->setParameters($args)
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
$this->assertIsArray($results, 'simply test that the query return a result');
|
||||||
|
}
|
||||||
|
}
|
@ -72,7 +72,7 @@ final class ValidPhonenumber extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (false === $isValid) {
|
if (false === $isValid) {
|
||||||
$this->context->addViolation($message, ['%phonenumber%' => $value]);
|
$this->context->addViolation($message, ['%phonenumber%' => $value, '%formatted%' => $this->phonenumberHelper->format($value)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Service\DocGenerator;
|
namespace Chill\PersonBundle\Service\DocGenerator;
|
||||||
|
|
||||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
|
||||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
|
||||||
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
|
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
|
||||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||||
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
|
use Chill\DocGeneratorBundle\Service\Context\BaseContextData;
|
||||||
@ -34,6 +32,7 @@ use Doctrine\ORM\EntityRepository;
|
|||||||
use LogicException;
|
use LogicException;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
@ -42,7 +41,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||||||
use function array_key_exists;
|
use function array_key_exists;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
|
final class PersonContext implements PersonContextInterface
|
||||||
{
|
{
|
||||||
private AuthorizationHelperInterface $authorizationHelper;
|
private AuthorizationHelperInterface $authorizationHelper;
|
||||||
|
|
||||||
@ -129,6 +128,7 @@ class PersonContext implements DocGeneratorContextWithAdminFormInterface, DocGen
|
|||||||
'choice_label' => function ($entity = null) {
|
'choice_label' => function ($entity = null) {
|
||||||
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
|
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
|
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||||
{
|
{
|
||||||
$builder->add('scope', ScopePickerType::class, [
|
$builder->add('title', TextType::class, [
|
||||||
'center' => $this->centerResolverManager->resolveCenters($entity),
|
'required' => true,
|
||||||
'role' => PersonDocumentVoter::CREATE,
|
'label' => 'docgen.Document title',
|
||||||
'label' => 'Scope',
|
'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
|
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
|
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 = new PersonDocument();
|
||||||
$doc->setTemplate($template)
|
$doc->setTemplate($template)
|
||||||
->setTitle($this->translatableStringHelper->localize($template->getName()))
|
->setTitle(
|
||||||
|
$contextGenerationData['title'] ?? $this->translatableStringHelper->localize($template->getName())
|
||||||
|
)
|
||||||
->setDate(new DateTime())
|
->setDate(new DateTime())
|
||||||
->setDescription($this->translatableStringHelper->localize($template->getName()))
|
->setDescription($this->translatableStringHelper->localize($template->getName()))
|
||||||
->setPerson($entity)
|
->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\Center;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Form\Type\ScopePickerType;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
@ -33,6 +34,8 @@ use Prophecy\Exception\Prediction\FailedPredictionException;
|
|||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
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\Security;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
@ -82,7 +85,7 @@ final class PersonContextTest extends TestCase
|
|||||||
$parameter
|
$parameter
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertFalse($personContext->hasPublicForm($docGen, $person));
|
$personContext->buildPublicForm($this->buildFormBuilder(false), $docGen, $person);
|
||||||
|
|
||||||
$personContext->storeGenerated(
|
$personContext->storeGenerated(
|
||||||
$docGen,
|
$docGen,
|
||||||
@ -126,7 +129,7 @@ final class PersonContextTest extends TestCase
|
|||||||
$em->reveal(),
|
$em->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertTrue($personContext->hasPublicForm($docGen, $person));
|
$personContext->buildPublicForm($this->buildFormBuilder(true), $docGen, $person);
|
||||||
|
|
||||||
$personContext->storeGenerated(
|
$personContext->storeGenerated(
|
||||||
$docGen,
|
$docGen,
|
||||||
@ -170,7 +173,7 @@ final class PersonContextTest extends TestCase
|
|||||||
$em->reveal(),
|
$em->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertTrue($personContext->hasPublicForm($docGen, $person));
|
$personContext->buildPublicForm($this->buildFormBuilder(true), $docGen, $person);
|
||||||
|
|
||||||
$personContext->storeGenerated(
|
$personContext->storeGenerated(
|
||||||
$docGen,
|
$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(
|
private function buildPersonContext(
|
||||||
?AuthorizationHelperInterface $authorizationHelper = null,
|
?AuthorizationHelperInterface $authorizationHelper = null,
|
||||||
?BaseContextData $baseContextData = 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
|
A context for accompanying period work evaluation: Contexte pour les évaluations dans les actions d'accompagnement
|
||||||
Person basic: Personne (basique)
|
Person basic: Personne (basique)
|
||||||
A basic context for person: Contexte pour les personnes
|
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_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
|
||||||
|
@ -214,7 +214,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(name="kind", type="string", length="20", options={"default": ""})
|
* @ORM\Column(name="kind", type="string", length="20", options={"default": ""})
|
||||||
* @Groups({"write"})
|
* @Groups({"write", "docgen:read", "docgen:read:3party:parent"})
|
||||||
*/
|
*/
|
||||||
private ?string $kind = '';
|
private ?string $kind = '';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user