mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Merge branch 'master' into 292_activity_acl
This commit is contained in:
commit
6e1340be27
15
CHANGELOG.md
15
CHANGELOG.md
@ -11,8 +11,23 @@ and this project adheres to
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
<!-- write down unreleased development here -->
|
<!-- write down unreleased development here -->
|
||||||
|
* [main] change address format in case the country is France, in Address render box and address normalizer
|
||||||
* [person] add validator for accompanying period with a test on social issues (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/76)
|
* [person] add validator for accompanying period with a test on social issues (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/76)
|
||||||
* [activity] fix visibility for location
|
* [activity] fix visibility for location
|
||||||
|
* [origin] fix origin: use correctly the translatable strings
|
||||||
|
|
||||||
|
* /!\ everyone must update the origin table. As there is only one row, execute `update chill_person_accompanying_period_origin set label = jsonb_build_object('fr', 'appel téléphonique');`
|
||||||
|
* [person] redirect bug fixed.
|
||||||
|
* [action] add an unrelated issue within action creation.
|
||||||
|
* [origin] fix origin: use correctly the translatable strings
|
||||||
|
* /!\ everyone must update the origin table. As there is only one row, execute `update chill_person_accompanying_period_origin set label = jsonb_build_object('fr', 'appel téléphonique');`
|
||||||
|
* [main] change order of civilities in civility fixtures (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/191)
|
||||||
|
* [person] set min attr in the minimum of children field (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/191)
|
||||||
|
* [person] add marital status date in person view (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/191)
|
||||||
|
* [person] show number of children + allow set number of children to null (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/191)
|
||||||
|
* [person] show acceptSMS option (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/191)
|
||||||
|
* [person] add death information in person render box in twig and vue render boxes (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/191)
|
||||||
|
|
||||||
|
|
||||||
## Test releases
|
## Test releases
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
|||||||
use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException;
|
use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException;
|
||||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||||
use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface;
|
use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface;
|
||||||
|
use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
|
||||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
@ -28,10 +29,15 @@ use GuzzleHttp\Exception\TransferException;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||||
|
use Symfony\Component\HttpFoundation\File\File;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
// TODO à mettre dans services
|
// TODO à mettre dans services
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
@ -78,6 +84,27 @@ final class DocGeneratorTemplateController extends AbstractController
|
|||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "{_locale}/admin/doc/gen/generate/test/from/{template}/for/{entityClassName}/{entityId}",
|
||||||
|
* name="chill_docgenerator_test_generate_from_template"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function adminTestGenerateDocFromTemplateAction(
|
||||||
|
DocGeneratorTemplate $template,
|
||||||
|
string $entityClassName,
|
||||||
|
int $entityId,
|
||||||
|
Request $request
|
||||||
|
): Response {
|
||||||
|
return $this->generateDocFromTemplate(
|
||||||
|
$template,
|
||||||
|
$entityClassName,
|
||||||
|
$entityId,
|
||||||
|
$request,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route(
|
* @Route(
|
||||||
* "{_locale}/doc/gen/generate/from/{template}/for/{entityClassName}/{entityId}",
|
* "{_locale}/doc/gen/generate/from/{template}/for/{entityClassName}/{entityId}",
|
||||||
@ -89,6 +116,81 @@ final class DocGeneratorTemplateController extends AbstractController
|
|||||||
string $entityClassName,
|
string $entityClassName,
|
||||||
int $entityId,
|
int $entityId,
|
||||||
Request $request
|
Request $request
|
||||||
|
): Response {
|
||||||
|
return $this->generateDocFromTemplate(
|
||||||
|
$template,
|
||||||
|
$entityClassName,
|
||||||
|
$entityId,
|
||||||
|
$request,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "/api/1.0/docgen/templates/by-entity/{entityClassName}",
|
||||||
|
* name="chill_docgenerator_templates_for_entity_api"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function listTemplateApiAction(string $entityClassName): Response
|
||||||
|
{
|
||||||
|
$nb = $this->docGeneratorTemplateRepository->countByEntity($entityClassName);
|
||||||
|
$paginator = $this->paginatorFactory->create($nb);
|
||||||
|
$entities = $this->docGeneratorTemplateRepository->findByEntity(
|
||||||
|
$entityClassName,
|
||||||
|
$paginator->getCurrentPageFirstItemNumber(),
|
||||||
|
$paginator->getItemsPerPage()
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->json(
|
||||||
|
new Collection($entities, $paginator),
|
||||||
|
Response::HTTP_OK,
|
||||||
|
[],
|
||||||
|
[AbstractNormalizer::GROUPS => ['read']]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route(
|
||||||
|
* "{_locale}/admin/doc/gen/generate/test/redirect",
|
||||||
|
* name="chill_docgenerator_test_generate_redirect"
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function redirectToTestGenerate(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$template = $request->query->getInt('template');
|
||||||
|
|
||||||
|
if (null === $template) {
|
||||||
|
throw new BadRequestHttpException('template parameter is missing');
|
||||||
|
}
|
||||||
|
|
||||||
|
$entityClassName = $request->query->get('entityClassName');
|
||||||
|
|
||||||
|
if (null === $entityClassName) {
|
||||||
|
throw new BadRequestHttpException('entityClassName is missing');
|
||||||
|
}
|
||||||
|
|
||||||
|
$entityId = $request->query->get('entityId');
|
||||||
|
|
||||||
|
if (null === $entityId) {
|
||||||
|
throw new BadRequestHttpException('entityId is missing');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->redirectToRoute(
|
||||||
|
'chill_docgenerator_test_generate_from_template',
|
||||||
|
['template' => $template, 'entityClassName' => $entityClassName, 'entityId' => $entityId,
|
||||||
|
'returnPath' => $request->query->get('returnPath', '/'), ]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateDocFromTemplate(
|
||||||
|
DocGeneratorTemplate $template,
|
||||||
|
string $entityClassName,
|
||||||
|
int $entityId,
|
||||||
|
Request $request,
|
||||||
|
bool $isTest
|
||||||
): Response {
|
): Response {
|
||||||
try {
|
try {
|
||||||
$context = $this->contextManager->getContextByDocGeneratorTemplate($template);
|
$context = $this->contextManager->getContextByDocGeneratorTemplate($template);
|
||||||
@ -105,9 +207,29 @@ final class DocGeneratorTemplateController extends AbstractController
|
|||||||
$contextGenerationData = [];
|
$contextGenerationData = [];
|
||||||
|
|
||||||
if ($context instanceof DocGeneratorContextWithPublicFormInterface
|
if ($context instanceof DocGeneratorContextWithPublicFormInterface
|
||||||
&& $context->hasPublicForm($template, $entity)) {
|
&& $context->hasPublicForm($template, $entity) || $isTest) {
|
||||||
$builder = $this->createFormBuilder($context->getFormData($template, $entity));
|
if ($context instanceof DocGeneratorContextWithPublicFormInterface) {
|
||||||
|
$builder = $this->createFormBuilder(
|
||||||
|
array_merge(
|
||||||
|
$context->getFormData($template, $entity),
|
||||||
|
$isTest ? ['test_file' => null] : []
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$builder = $this->createFormBuilder(
|
||||||
|
['test_file' => null]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$context->buildPublicForm($builder, $template, $entity);
|
$context->buildPublicForm($builder, $template, $entity);
|
||||||
|
|
||||||
|
if ($isTest) {
|
||||||
|
$builder->add('test_file', FileType::class, [
|
||||||
|
'label' => 'Template file',
|
||||||
|
'required' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$form = $builder->getForm()->handleRequest($request);
|
$form = $builder->getForm()->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
@ -121,6 +243,11 @@ final class DocGeneratorTemplateController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($isTest && null !== $contextGenerationData['test_file']) {
|
||||||
|
/** @var File $file */
|
||||||
|
$file = $contextGenerationData['test_file'];
|
||||||
|
$templateResource = fopen($file->getPathname(), 'rb');
|
||||||
|
} else {
|
||||||
$getUrlGen = $this->tempUrlGenerator->generate(
|
$getUrlGen = $this->tempUrlGenerator->generate(
|
||||||
'GET',
|
'GET',
|
||||||
$template->getFile()->getFilename()
|
$template->getFile()->getFilename()
|
||||||
@ -147,17 +274,40 @@ final class DocGeneratorTemplateController extends AbstractController
|
|||||||
|
|
||||||
throw new HttpException(500);
|
throw new HttpException(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite($templateResource, $dataDecrypted);
|
fwrite($templateResource, $dataDecrypted);
|
||||||
rewind($templateResource);
|
rewind($templateResource);
|
||||||
|
}
|
||||||
|
|
||||||
$datas = $context->getData($template, $entity, $contextGenerationData);
|
$datas = $context->getData($template, $entity, $contextGenerationData);
|
||||||
dump('datas compiled', $datas);
|
|
||||||
|
|
||||||
|
try {
|
||||||
$generatedResource = $this->driver->generateFromResource($templateResource, $template->getFile()->getType(), $datas, $template->getFile()->getFilename());
|
$generatedResource = $this->driver->generateFromResource($templateResource, $template->getFile()->getType(), $datas, $template->getFile()->getFilename());
|
||||||
|
} catch (TemplateException $e) {
|
||||||
|
$msg = implode("\n", $e->getErrors());
|
||||||
|
|
||||||
|
return new Response($msg, 400, [
|
||||||
|
'Content-Type' => 'text/plain',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
fclose($templateResource);
|
fclose($templateResource);
|
||||||
|
|
||||||
|
if ($isTest) {
|
||||||
|
return new StreamedResponse(
|
||||||
|
static function () use ($generatedResource) {
|
||||||
|
fpassthru($generatedResource);
|
||||||
|
fclose($generatedResource);
|
||||||
|
},
|
||||||
|
Response::HTTP_OK,
|
||||||
|
[
|
||||||
|
'Content-Transfer-Encoding', 'binary',
|
||||||
|
'Content-Type' => 'application/vnd.oasis.opendocument.text',
|
||||||
|
'Content-Disposition' => sprintf('attachment; filename="%s.odt"', 'generated'),
|
||||||
|
'Content-Length' => fstat($generatedResource)['size'],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$genDocName = 'doc_' . sprintf('%010d', mt_rand()) . 'odt';
|
$genDocName = 'doc_' . sprintf('%010d', mt_rand()) . 'odt';
|
||||||
|
|
||||||
$getUrlGen = $this->tempUrlGenerator->generate(
|
$getUrlGen = $this->tempUrlGenerator->generate(
|
||||||
@ -206,28 +356,4 @@ final class DocGeneratorTemplateController extends AbstractController
|
|||||||
|
|
||||||
throw new Exception('Unable to generate document.');
|
throw new Exception('Unable to generate document.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @Route(
|
|
||||||
* "/api/1.0/docgen/templates/by-entity/{entityClassName}",
|
|
||||||
* name="chill_docgenerator_templates_for_entity_api"
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
public function listTemplateApiAction(string $entityClassName): Response
|
|
||||||
{
|
|
||||||
$nb = $this->docGeneratorTemplateRepository->countByEntity($entityClassName);
|
|
||||||
$paginator = $this->paginatorFactory->create($nb);
|
|
||||||
$entities = $this->docGeneratorTemplateRepository->findByEntity(
|
|
||||||
$entityClassName,
|
|
||||||
$paginator->getCurrentPageFirstItemNumber(),
|
|
||||||
$paginator->getItemsPerPage()
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->json(
|
|
||||||
new Collection($entities, $paginator),
|
|
||||||
Response::HTTP_OK,
|
|
||||||
[],
|
|
||||||
[AbstractNormalizer::GROUPS => ['read']]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\DocGeneratorBundle\GeneratorDriver\Exception;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A exception to throw when there are syntax errors in the
|
||||||
|
* template file.
|
||||||
|
*/
|
||||||
|
class TemplateException extends RuntimeException
|
||||||
|
{
|
||||||
|
private array $errors;
|
||||||
|
|
||||||
|
public function __construct(array $errors, $code = 0, ?Throwable $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct('Error while generating document from template', $code, $previous);
|
||||||
|
$this->errors = $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getErrors(): array
|
||||||
|
{
|
||||||
|
return $this->errors;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\DocGeneratorBundle\GeneratorDriver;
|
namespace Chill\DocGeneratorBundle\GeneratorDriver;
|
||||||
|
|
||||||
|
use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Mime\Part\DataPart;
|
use Symfony\Component\Mime\Part\DataPart;
|
||||||
@ -54,10 +55,21 @@ class RelatorioDriver implements DriverInterface
|
|||||||
|
|
||||||
return $response->toStream();
|
return $response->toStream();
|
||||||
} catch (HttpExceptionInterface $e) {
|
} catch (HttpExceptionInterface $e) {
|
||||||
|
$content = $e->getResponse()->getContent(false);
|
||||||
|
|
||||||
|
if (400 === $e->getResponse()->getStatusCode()) {
|
||||||
|
$content = json_decode($content, true);
|
||||||
|
$this->logger->error('relatorio: template error', [
|
||||||
|
'error' => $content['message'] ?? '_not defined',
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw new TemplateException([$content['message']]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->logger->error('relatorio: error while generating document', [
|
$this->logger->error('relatorio: error while generating document', [
|
||||||
'msg' => $e->getMessage(),
|
'msg' => $e->getMessage(),
|
||||||
'response' => $e->getResponse()->getStatusCode(),
|
'response' => $e->getResponse()->getStatusCode(),
|
||||||
'content' => $e->getResponse()->getContent(false),
|
'content' => $content,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<th></th>
|
<th></th>
|
||||||
<th>{{ 'Title'|trans }}</th>
|
<th>{{ 'Title'|trans }}</th>
|
||||||
<th>{{ 'docgen.Context'|trans }}</th>
|
<th>{{ 'docgen.Context'|trans }}</th>
|
||||||
|
<th>{{ 'docgen.test generate'|trans }}</th>
|
||||||
<th>{{ 'Edit'|trans }}</th>
|
<th>{{ 'Edit'|trans }}</th>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -15,6 +16,20 @@
|
|||||||
<td>{{ entity.id }}</td>
|
<td>{{ entity.id }}</td>
|
||||||
<td>{{ entity.name|localize_translatable_string}}</td>
|
<td>{{ entity.name|localize_translatable_string}}</td>
|
||||||
<td>{{ contextManager.getContextByKey(entity.context).name|trans }}</td>
|
<td>{{ contextManager.getContextByKey(entity.context).name|trans }}</td>
|
||||||
|
<td>
|
||||||
|
<form method="get" action="{{ path('chill_docgenerator_test_generate_redirect') }}">
|
||||||
|
<input type="hidden" name="returnPath" value="{{ app.request.query.get('returnPath', '/')|e('html_attr') }}" />
|
||||||
|
<input type="hidden" name="template" value="{{ entity.id|e('html_attr') }}" />
|
||||||
|
<input type="hidden" name="entityClassName" value="{{ contextManager.getContextByKey(entity.context).entityClass|e('html_attr') }}" />
|
||||||
|
<input type="text" name="entityId" />
|
||||||
|
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<button type="submit" class="btn btn-mini btn-neutral">{{ 'docgen.test generate'|trans }}</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ chill_path_add_return_path('chill_crud_docgen_template_edit', { 'id': entity.id }) }}" class="btn btn-edit">
|
<a href="{{ chill_path_add_return_path('chill_crud_docgen_template_edit', { 'id': entity.id }) }}" class="btn btn-edit">
|
||||||
{{ 'Edit'|trans }}
|
{{ 'Edit'|trans }}
|
||||||
|
@ -16,16 +16,27 @@ use function array_merge;
|
|||||||
|
|
||||||
class NormalizeNullValueHelper
|
class NormalizeNullValueHelper
|
||||||
{
|
{
|
||||||
|
private ?string $discriminatorType = null;
|
||||||
|
|
||||||
|
private ?string $discriminatorValue = null;
|
||||||
|
|
||||||
private NormalizerInterface $normalizer;
|
private NormalizerInterface $normalizer;
|
||||||
|
|
||||||
public function __construct(NormalizerInterface $normalizer)
|
public function __construct(NormalizerInterface $normalizer, $discriminatorType = null, $discriminatorValue = null)
|
||||||
{
|
{
|
||||||
$this->normalizer = $normalizer;
|
$this->normalizer = $normalizer;
|
||||||
|
$this->discriminatorType = $discriminatorType;
|
||||||
|
$this->discriminatorValue = $discriminatorValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function normalize(array $attributes, string $format = 'docgen', ?array $context = [])
|
public function normalize(array $attributes, string $format = 'docgen', ?array $context = [])
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
|
$data['isNull'] = true;
|
||||||
|
|
||||||
|
if (null !== $this->discriminatorType) {
|
||||||
|
$data[$this->discriminatorType] = $this->discriminatorValue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($attributes as $key => $class) {
|
foreach ($attributes as $key => $class) {
|
||||||
if (is_numeric($key)) {
|
if (is_numeric($key)) {
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\DocGeneratorBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use ArrayObject;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize a collection for docgen format.
|
||||||
|
*/
|
||||||
|
class CollectionDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||||
|
{
|
||||||
|
use NormalizerAwareTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $object
|
||||||
|
*
|
||||||
|
* @return array|ArrayObject|bool|float|int|string|void|null
|
||||||
|
*/
|
||||||
|
public function normalize($object, ?string $format = null, array $context = [])
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
if (null === $object || 0 === $object->count()) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($object->getIterator() as $item) {
|
||||||
|
$data[] = $this->normalizer->normalize($item, $format, $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsNormalization($data, ?string $format = null, array $context = [])
|
||||||
|
{
|
||||||
|
if ('docgen' !== $format) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data instanceof Collection
|
||||||
|
|| (null === $data && Collection::class === ($context['docgen:expects'] ?? null));
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\DocGeneratorBundle\Serializer\Normalizer;
|
namespace Chill\DocGeneratorBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||||
@ -42,10 +43,15 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
|
|
||||||
private PropertyAccessor $propertyAccess;
|
private PropertyAccessor $propertyAccess;
|
||||||
|
|
||||||
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory)
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||||
{
|
|
||||||
|
public function __construct(
|
||||||
|
ClassMetadataFactoryInterface $classMetadataFactory,
|
||||||
|
TranslatableStringHelperInterface $translatableStringHelper
|
||||||
|
) {
|
||||||
$this->classMetadataFactory = $classMetadataFactory;
|
$this->classMetadataFactory = $classMetadataFactory;
|
||||||
$this->propertyAccess = PropertyAccess::createPropertyAccessor();
|
$this->propertyAccess = PropertyAccess::createPropertyAccessor();
|
||||||
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function normalize($object, ?string $format = null, array $context = [])
|
public function normalize($object, ?string $format = null, array $context = [])
|
||||||
@ -57,7 +63,12 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->classMetadataFactory->hasMetadataFor($classMetadataKey)) {
|
if (!$this->classMetadataFactory->hasMetadataFor($classMetadataKey)) {
|
||||||
throw new LogicException(sprintf('This object does not have metadata: %s. Add groups on this entity to allow to serialize with the format %s and groups %s', is_object($object) ? get_class($object) : $context['docgen:expects'], $format, implode(', ', $context['groups'])));
|
throw new LogicException(sprintf(
|
||||||
|
'This object does not have metadata: %s. Add groups on this entity to allow to serialize with the format %s and groups %s',
|
||||||
|
is_object($object) ? get_class($object) : '(todo' /*$context['docgen:expects'],*/ ,
|
||||||
|
$format,
|
||||||
|
implode(', ', ($context['groups'] ?? []))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$metadata = $this->classMetadataFactory->getMetadataFor($classMetadataKey);
|
$metadata = $this->classMetadataFactory->getMetadataFor($classMetadataKey);
|
||||||
@ -98,8 +109,9 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
if ($reflection->hasProperty($attribute->getName())) {
|
if ($reflection->hasProperty($attribute->getName())) {
|
||||||
if (!$reflection->getProperty($attribute->getName())->hasType()) {
|
if (!$reflection->getProperty($attribute->getName())->hasType()) {
|
||||||
throw new \LogicException(sprintf(
|
throw new \LogicException(sprintf(
|
||||||
'Could not determine how the content is determined for the attribute %s. Add a type on this property',
|
'Could not determine how the content is determined for the attribute %s on class %s. Add a type on this property',
|
||||||
$attribute->getName()
|
$attribute->getName(),
|
||||||
|
$reflection->getName()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +119,9 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
} elseif ($reflection->hasMethod($method = 'get' . ucfirst($attribute->getName()))) {
|
} elseif ($reflection->hasMethod($method = 'get' . ucfirst($attribute->getName()))) {
|
||||||
if (!$reflection->getMethod($method)->hasReturnType()) {
|
if (!$reflection->getMethod($method)->hasReturnType()) {
|
||||||
throw new \LogicException(sprintf(
|
throw new \LogicException(sprintf(
|
||||||
'Could not determine how the content is determined for the attribute %s. Add a return type on the method',
|
'Could not determine how the content is determined for the attribute %s on class %s. Add a return type on the method',
|
||||||
$attribute->getName()
|
$attribute->getName(),
|
||||||
|
$reflection->getName()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +129,9 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
} elseif ($reflection->hasMethod($method = 'is' . ucfirst($attribute->getName()))) {
|
} elseif ($reflection->hasMethod($method = 'is' . ucfirst($attribute->getName()))) {
|
||||||
if (!$reflection->getMethod($method)->hasReturnType()) {
|
if (!$reflection->getMethod($method)->hasReturnType()) {
|
||||||
throw new \LogicException(sprintf(
|
throw new \LogicException(sprintf(
|
||||||
'Could not determine how the content is determined for the attribute %s. Add a return type on the method',
|
'Could not determine how the content is determined for the attribute %s on class %s. Add a return type on the method',
|
||||||
$attribute->getName()
|
$attribute->getName(),
|
||||||
|
$reflection->getName()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +139,9 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
} elseif ($reflection->hasMethod($attribute->getName())) {
|
} elseif ($reflection->hasMethod($attribute->getName())) {
|
||||||
if (!$reflection->getMethod($attribute->getName())->hasReturnType()) {
|
if (!$reflection->getMethod($attribute->getName())->hasReturnType()) {
|
||||||
throw new \LogicException(sprintf(
|
throw new \LogicException(sprintf(
|
||||||
'Could not determine how the content is determined for the attribute %s. Add a return type on the method',
|
'Could not determine how the content is determined for the attribute %s on class %s. Add a return type on the method',
|
||||||
$attribute->getName()
|
$attribute->getName(),
|
||||||
|
$reflection->getName()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,12 +168,32 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
{
|
{
|
||||||
$keys = [];
|
$keys = [];
|
||||||
|
|
||||||
|
// add a discriminator
|
||||||
|
if (null !== $discriminator = $metadata->getClassDiscriminatorMapping()) {
|
||||||
|
$typeKey = $discriminator->getTypeProperty();
|
||||||
|
$typeValue = null;
|
||||||
|
|
||||||
|
foreach ($discriminator->getTypesMapping() as $type => $typeClass) {
|
||||||
|
if ($typeClass === $context['docgen:expects']) {
|
||||||
|
$typeValue = $type;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $typeValue) {
|
||||||
|
$typeKey = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$typeKey = $typeValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
$key = $attribute->getSerializedName() ?? $attribute->getName();
|
$key = $attribute->getSerializedName() ?? $attribute->getName();
|
||||||
$keys[$key] = $this->getExpectedType($attribute, $metadata->getReflectionClass());
|
$keys[$key] = $this->getExpectedType($attribute, $metadata->getReflectionClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
$normalizer = new NormalizeNullValueHelper($this->normalizer);
|
$normalizer = new NormalizeNullValueHelper($this->normalizer, $typeKey, $typeValue);
|
||||||
|
|
||||||
return $normalizer->normalize($keys, $format, $context);
|
return $normalizer->normalize($keys, $format, $context);
|
||||||
}
|
}
|
||||||
@ -172,6 +207,10 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'array':
|
case 'array':
|
||||||
|
if (in_array('is-translatable', $attribute->getNormalizationContextForGroups(['docgen:read']), true)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
case 'bool':
|
case 'bool':
|
||||||
@ -208,14 +247,26 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
private function normalizeObject($object, $format, array $context, array $expectedGroups, ClassMetadata $metadata, array $attributes)
|
private function normalizeObject($object, $format, array $context, array $expectedGroups, ClassMetadata $metadata, array $attributes)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
|
$data['isNull'] = false;
|
||||||
$reflection = $metadata->getReflectionClass();
|
$reflection = $metadata->getReflectionClass();
|
||||||
|
|
||||||
|
// add a discriminator
|
||||||
|
if (null !== $discriminator = $metadata->getClassDiscriminatorMapping()) {
|
||||||
|
$data[$discriminator->getTypeProperty()] = $discriminator->getMappedObjectType($object);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($attributes as $attribute) {
|
foreach ($attributes as $attribute) {
|
||||||
/** @var AttributeMetadata $attribute */
|
/** @var AttributeMetadata $attribute */
|
||||||
$value = $this->propertyAccess->getValue($object, $attribute->getName());
|
$value = $this->propertyAccess->getValue($object, $attribute->getName());
|
||||||
$key = $attribute->getSerializedName() ?? $attribute->getName();
|
$key = $attribute->getSerializedName() ?? $attribute->getName();
|
||||||
|
$isTranslatable = $attribute->getNormalizationContextForGroups(
|
||||||
|
is_array($context['groups']) ? $context['groups'] : [$context['groups']]
|
||||||
|
)['is-translatable'] ?? false;
|
||||||
|
|
||||||
if (is_iterable($value)) {
|
if ($isTranslatable) {
|
||||||
|
$data[$key] = $this->translatableStringHelper
|
||||||
|
->localize($value);
|
||||||
|
} elseif (is_iterable($value)) {
|
||||||
$arr = [];
|
$arr = [];
|
||||||
|
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
|
@ -20,6 +20,9 @@ services:
|
|||||||
resource: '../Serializer/Normalizer/'
|
resource: '../Serializer/Normalizer/'
|
||||||
tags:
|
tags:
|
||||||
- { name: 'serializer.normalizer', priority: -152 }
|
- { name: 'serializer.normalizer', priority: -152 }
|
||||||
|
Chill\DocGeneratorBundle\Serializer\Normalizer\CollectionDocGenNormalizer:
|
||||||
|
tags:
|
||||||
|
- { name: 'serializer.normalizer', priority: -126 }
|
||||||
|
|
||||||
Chill\DocGeneratorBundle\Controller\:
|
Chill\DocGeneratorBundle\Controller\:
|
||||||
resource: "../Controller"
|
resource: "../Controller"
|
||||||
|
@ -11,7 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\DocGeneratorBundle\tests\Serializer\Normalizer;
|
namespace Chill\DocGeneratorBundle\tests\Serializer\Normalizer;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||||
@ -35,25 +35,36 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
|||||||
|
|
||||||
public function testNormalizationBasic()
|
public function testNormalizationBasic()
|
||||||
{
|
{
|
||||||
$user = new User();
|
$scope = new Scope();
|
||||||
$user->setUsername('User Test');
|
$scope->setName(['fr' => 'scope']);
|
||||||
$user->setMainCenter($center = new Center());
|
|
||||||
$center->setName('test');
|
|
||||||
|
|
||||||
$normalized = $this->normalizer->normalize($user, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => User::class]);
|
$normalized = $this->normalizer->normalize($scope, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => Scope::class]);
|
||||||
$expected = [
|
$expected = [
|
||||||
'label' => 'User Test',
|
'id' => null,
|
||||||
'email' => '',
|
'name' => 'scope',
|
||||||
'mainCenter' => [
|
'type' => 'scope',
|
||||||
'name' => 'test',
|
'isNull' => false,
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertEquals($expected, $normalized, 'test normalization fo an user');
|
$this->assertEquals($expected, $normalized, 'test normalization fo a scope');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormalizeNull()
|
||||||
|
{
|
||||||
|
$actual = $this->normalizer->normalize(null, 'docgen', [AbstractNormalizer::GROUPS => ['docgen:read'], 'docgen:expects' => Scope::class]);
|
||||||
|
$expected = [
|
||||||
|
'id' => '',
|
||||||
|
'name' => '',
|
||||||
|
'type' => 'scope',
|
||||||
|
'isNull' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual, 'test normalization for a null scope');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNormalizeNullObjectWithObjectEmbedded()
|
public function testNormalizeNullObjectWithObjectEmbedded()
|
||||||
{
|
{
|
||||||
|
$this->markTestIncomplete('test to implement');
|
||||||
$normalized = $this->normalizer->normalize(null, 'docgen', [
|
$normalized = $this->normalizer->normalize(null, 'docgen', [
|
||||||
AbstractNormalizer::GROUPS => ['docgen:read'],
|
AbstractNormalizer::GROUPS => ['docgen:read'],
|
||||||
'docgen:expects' => User::class,
|
'docgen:expects' => User::class,
|
||||||
@ -62,7 +73,7 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
|||||||
$expected = [
|
$expected = [
|
||||||
'label' => '',
|
'label' => '',
|
||||||
'email' => '',
|
'email' => '',
|
||||||
'mainCenter' => [
|
'main_center' => [
|
||||||
'name' => '',
|
'name' => '',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -72,6 +83,7 @@ final class DocGenObjectNormalizerTest extends KernelTestCase
|
|||||||
|
|
||||||
public function testNormalizeWithNullValueEmbedded()
|
public function testNormalizeWithNullValueEmbedded()
|
||||||
{
|
{
|
||||||
|
$this->markTestIncomplete('test to write');
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->setUsername('User Test');
|
$user->setUsername('User Test');
|
||||||
|
|
||||||
|
@ -11,8 +11,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\DocStoreBundle\Form;
|
namespace Chill\DocStoreBundle\Form;
|
||||||
|
|
||||||
|
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
||||||
use Chill\DocStoreBundle\Entity\Document;
|
use Chill\DocStoreBundle\Entity\Document;
|
||||||
use Chill\DocStoreBundle\Entity\PersonDocument;
|
use Chill\DocStoreBundle\Entity\DocumentCategory;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||||
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
use Chill\MainBundle\Form\Type\ChillTextareaType;
|
||||||
@ -70,11 +71,11 @@ class AccompanyingCourseDocumentType extends AbstractType
|
|||||||
//TODO : adapt to using AccompanyingCourseDocument categories. Currently there are none...
|
//TODO : adapt to using AccompanyingCourseDocument categories. Currently there are none...
|
||||||
->add('category', EntityType::class, [
|
->add('category', EntityType::class, [
|
||||||
'placeholder' => 'Choose a document category',
|
'placeholder' => 'Choose a document category',
|
||||||
'class' => 'ChillDocStoreBundle:DocumentCategory',
|
'class' => DocumentCategory::class,
|
||||||
'query_builder' => static function (EntityRepository $er) {
|
'query_builder' => static function (EntityRepository $er) {
|
||||||
return $er->createQueryBuilder('c')
|
return $er->createQueryBuilder('c')
|
||||||
->where('c.documentClass = :docClass')
|
->where('c.documentClass = :docClass')
|
||||||
->setParameter('docClass', PersonDocument::class);
|
->setParameter('docClass', AccompanyingCourseDocument::class);
|
||||||
},
|
},
|
||||||
'choice_label' => function ($entity = null) {
|
'choice_label' => function ($entity = null) {
|
||||||
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
|
return $entity ? $this->translatableStringHelper->localize($entity->getName()) : '';
|
||||||
|
@ -41,5 +41,6 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
|
{{ parent() }}
|
||||||
{{ encore_entry_link_tags('mod_async_upload') }}
|
{{ encore_entry_link_tags('mod_async_upload') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -42,5 +42,6 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block css %}
|
{% block css %}
|
||||||
|
{{ parent() }}
|
||||||
{{ encore_entry_link_tags('mod_async_upload') }}
|
{{ encore_entry_link_tags('mod_async_upload') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -14,6 +14,11 @@
|
|||||||
{{ encore_entry_script_tags('mod_async_upload') }}
|
{{ encore_entry_script_tags('mod_async_upload') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block css %}
|
||||||
|
{{ parent() }}
|
||||||
|
{{ encore_entry_link_tags('mod_async_upload') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h1>{{ 'Document %title%' | trans({ '%title%': document.title }) }}</h1>
|
<h1>{{ 'Document %title%' | trans({ '%title%': document.title }) }}</h1>
|
||||||
|
@ -26,8 +26,8 @@ class LoadCivility extends Fixture implements FixtureGroupInterface
|
|||||||
public function load(ObjectManager $manager): void
|
public function load(ObjectManager $manager): void
|
||||||
{
|
{
|
||||||
$civilities = [
|
$civilities = [
|
||||||
['name' => ['fr' => 'Monsieur'], 'abbrev' => ['fr' => 'M.']],
|
|
||||||
['name' => ['fr' => 'Madame'], 'abbrev' => ['fr' => 'Mme']],
|
['name' => ['fr' => 'Madame'], 'abbrev' => ['fr' => 'Mme']],
|
||||||
|
['name' => ['fr' => 'Monsieur'], 'abbrev' => ['fr' => 'M.']],
|
||||||
['name' => ['fr' => 'Docteur'], 'abbrev' => ['fr' => 'Dr']],
|
['name' => ['fr' => 'Docteur'], 'abbrev' => ['fr' => 'Dr']],
|
||||||
['name' => ['fr' => 'Professeur'], 'abbrev' => ['fr' => 'Pr']],
|
['name' => ['fr' => 'Professeur'], 'abbrev' => ['fr' => 'Pr']],
|
||||||
['name' => ['fr' => 'Madame la Directrice'], 'abbrev' => ['fr' => 'Mme']],
|
['name' => ['fr' => 'Madame la Directrice'], 'abbrev' => ['fr' => 'Mme']],
|
||||||
|
@ -38,8 +38,9 @@ class Center implements HasCenterInterface
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=255)
|
* @ORM\Column(type="string", length=255)
|
||||||
|
@ -22,7 +22,8 @@ class Civility
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private array $abbreviation = [];
|
private array $abbreviation = [];
|
||||||
|
|
||||||
@ -35,13 +36,14 @@ class Civility
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private array $name = [];
|
private array $name = [];
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\MainBundle\Entity;
|
namespace Chill\MainBundle\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation\Context;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,12 +26,11 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||||||
class Country
|
class Country
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="string", length=3)
|
* @ORM\Column(type="string", length=3)
|
||||||
* @groups({"read"})
|
* @groups({"read", "docgen:read"})
|
||||||
|
* @Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $countryCode;
|
private string $countryCode = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
@ -38,15 +38,16 @@ class Country
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
* @groups({"read"})
|
* @groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @groups({"read"})
|
* @groups({"read", "docgen:read"})
|
||||||
|
* @Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\MainBundle\Entity;
|
namespace Chill\MainBundle\Entity;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Language.
|
* Language.
|
||||||
@ -28,15 +29,18 @@ class Language
|
|||||||
*
|
*
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(type="string")
|
* @ORM\Column(type="string")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?string $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string array
|
* @var string array
|
||||||
*
|
*
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $name;
|
private array $name = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id.
|
* Get id.
|
||||||
|
@ -14,6 +14,7 @@ namespace Chill\MainBundle\Entity;
|
|||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation\Context;
|
||||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||||
use Symfony\Component\Serializer\Annotation\Groups;
|
use Symfony\Component\Serializer\Annotation\Groups;
|
||||||
|
|
||||||
@ -28,24 +29,21 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||||||
class Scope
|
class Scope
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var int
|
|
||||||
*
|
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
* @Groups({"read", "docgen:read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* translatable names.
|
* translatable names.
|
||||||
*
|
*
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Groups({"read", "docgen:read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
|
* @Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $name = [];
|
private array $name = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Collection
|
* @var Collection
|
||||||
@ -65,31 +63,27 @@ class Scope
|
|||||||
$this->roleScopes = new ArrayCollection();
|
$this->roleScopes = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRoleScope(RoleScope $roleScope)
|
public function addRoleScope(RoleScope $roleScope): self
|
||||||
{
|
{
|
||||||
$this->roleScopes->add($roleScope);
|
$this->roleScopes->add($roleScope);
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getId()
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getName(): array
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getRoleScopes(): Collection
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getRoleScopes()
|
|
||||||
{
|
{
|
||||||
return $this->roleScopes;
|
return $this->roleScopes;
|
||||||
}
|
}
|
||||||
@ -99,7 +93,7 @@ class Scope
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setName($name)
|
public function setName(array $name): self
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
|
||||||
|
@ -55,7 +55,6 @@ class User implements AdvancedUserInterface
|
|||||||
* @var string
|
* @var string
|
||||||
*
|
*
|
||||||
* @ORM\Column(type="string", length=150, nullable=true)
|
* @ORM\Column(type="string", length=150, nullable=true)
|
||||||
* @Serializer\Groups({"docgen:read"})
|
|
||||||
*/
|
*/
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
@ -83,7 +82,6 @@ class User implements AdvancedUserInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="string", length=200)
|
* @ORM\Column(type="string", length=200)
|
||||||
* @Serializer\Groups({"docgen:read"})
|
|
||||||
*/
|
*/
|
||||||
private string $label = '';
|
private string $label = '';
|
||||||
|
|
||||||
@ -95,7 +93,6 @@ class User implements AdvancedUserInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=Center::class)
|
* @ORM\ManyToOne(targetEntity=Center::class)
|
||||||
* @Serializer\Groups({"docgen:read"})
|
|
||||||
*/
|
*/
|
||||||
private ?Center $mainCenter = null;
|
private ?Center $mainCenter = null;
|
||||||
|
|
||||||
@ -189,7 +186,7 @@ class User implements AdvancedUserInterface
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getEmail()
|
public function getEmail(): ?string
|
||||||
{
|
{
|
||||||
return $this->email;
|
return $this->email;
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,14 @@ class UserJob
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
protected ?int $id = null;
|
protected ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array|string[]A
|
* @var array|string[]A
|
||||||
* @ORM\Column(name="label", type="json")
|
* @ORM\Column(name="label", type="json")
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
protected array $label = [];
|
protected array $label = [];
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ class ScopePickerType extends AbstractType
|
|||||||
{
|
{
|
||||||
$items = $this->authorizationHelper->getReachableScopes(
|
$items = $this->authorizationHelper->getReachableScopes(
|
||||||
$this->security->getUser(),
|
$this->security->getUser(),
|
||||||
$options['role'],
|
$options['role']->getRole(),
|
||||||
$options['center']
|
$options['center']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class UserPickerType extends AbstractType
|
|||||||
->setAllowedTypes('scope', [Scope::class, 'array', 'null'])
|
->setAllowedTypes('scope', [Scope::class, 'array', 'null'])
|
||||||
->setNormalizer('choices', function (Options $options) {
|
->setNormalizer('choices', function (Options $options) {
|
||||||
$users = $this->userACLAwareRepository
|
$users = $this->userACLAwareRepository
|
||||||
->findUsersByReachedACL($options['role'], $options['center'], $options['scope'], true);
|
->findUsersByReachedACL($options['role']->getRole(), $options['center'], $options['scope'], true);
|
||||||
|
|
||||||
if (null !== $options['having_permissions_group_flag']) {
|
if (null !== $options['having_permissions_group_flag']) {
|
||||||
return $this->userRepository
|
return $this->userRepository
|
||||||
|
@ -260,7 +260,7 @@ class PhonenumberHelper
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$validation = json_decode($response->getBody())->carrier->type;
|
$validation = json_decode($response->getBody()->getContents())->carrier->type;
|
||||||
|
|
||||||
$item
|
$item
|
||||||
->set($validation)
|
->set($validation)
|
||||||
|
@ -12,13 +12,11 @@
|
|||||||
* extended_infos bool add extra informations (step, floor, etc.)
|
* extended_infos bool add extra informations (step, floor, etc.)
|
||||||
|
|
||||||
#}
|
#}
|
||||||
{% macro raw(address, options) %}
|
|
||||||
|
{% macro raw(address, options, streetLine) %}
|
||||||
|
|
||||||
{% if address.street is not empty %}
|
{% if address.street is not empty %}
|
||||||
<p class="street">{{ address.street }}
|
<p>{{ streetLine }}</p>
|
||||||
{% if address.streetNumber is not empty %}
|
|
||||||
<span class="streetnumber">{{ address.streetNumber }}</span>
|
|
||||||
{% endif %}
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if options['extended_infos'] %}
|
{% if options['extended_infos'] %}
|
||||||
{{ _self.extended(address, options) }}
|
{{ _self.extended(address, options) }}
|
||||||
@ -56,7 +54,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro inline(address, options) %}
|
{% macro inline(address, options, streetLine) %}
|
||||||
{% if options['has_no_address'] == true and address.isNoAddress == true %}
|
{% if options['has_no_address'] == true and address.isNoAddress == true %}
|
||||||
{% if address.postCode is not empty %}
|
{% if address.postCode is not empty %}
|
||||||
<p class="postcode">
|
<p class="postcode">
|
||||||
@ -70,7 +68,7 @@
|
|||||||
</span>
|
</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
|
<span class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
|
||||||
{{ _self.raw(address, options) }}
|
{{ _self.raw(address, options, streetLine) }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ _self.validity(address, options) }}
|
{{ _self.validity(address, options) }}
|
||||||
@ -99,7 +97,7 @@
|
|||||||
{% if options['with_picto'] %}
|
{% if options['with_picto'] %}
|
||||||
<i class="fa fa-li fa-map-marker"></i>
|
<i class="fa fa-li fa-map-marker"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ _self.inline(address, options) }}
|
{{ _self.inline(address, options, streetLine) }}
|
||||||
</li>
|
</li>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
@ -108,7 +106,7 @@
|
|||||||
{% if options['with_picto'] %}
|
{% if options['with_picto'] %}
|
||||||
<i class="fa fa-fw fa-map-marker"></i>
|
<i class="fa fa-fw fa-map-marker"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ _self.inline(address, options) }}
|
{{ _self.inline(address, options, streetLine) }}
|
||||||
</span>
|
</span>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
@ -133,7 +131,7 @@
|
|||||||
{% if options['with_picto'] %}
|
{% if options['with_picto'] %}
|
||||||
<i class="fa fa-fw fa-map-marker"></i>
|
<i class="fa fa-fw fa-map-marker"></i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ _self.raw(address, options) }}
|
{{ _self.raw(address, options, streetLine) }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ _self.validity(address, options) }}
|
{{ _self.validity(address, options) }}
|
||||||
|
@ -11,24 +11,60 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
||||||
use Chill\MainBundle\Entity\Address;
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
use DateTimeInterface;
|
||||||
|
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
||||||
|
|
||||||
class AddressNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||||
{
|
{
|
||||||
use NormalizerAwareTrait;
|
use NormalizerAwareTrait;
|
||||||
|
|
||||||
|
private const NULL_POSTCODE_COUNTRY = [
|
||||||
|
'id', 'name', 'code',
|
||||||
|
];
|
||||||
|
|
||||||
|
private const NULL_VALUE = [
|
||||||
|
'address_id',
|
||||||
|
'text',
|
||||||
|
'street',
|
||||||
|
'streetNumber',
|
||||||
|
'postcode',
|
||||||
|
'country',
|
||||||
|
'floor',
|
||||||
|
'corridor',
|
||||||
|
'steps',
|
||||||
|
'flat',
|
||||||
|
'buildingName',
|
||||||
|
'distribution',
|
||||||
|
'extra',
|
||||||
|
'validFrom' => DateTimeInterface::class,
|
||||||
|
'validTo' => DateTimeInterface::class,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Address $address
|
* @param Address $address
|
||||||
*/
|
*/
|
||||||
public function normalize($address, ?string $format = null, array $context = [])
|
public function normalize($address, ?string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
return [
|
if ($address instanceof Address) {
|
||||||
|
$text = $address->isNoAddress() ? '' : $address->getStreet() . ', ' . $address->getStreetNumber();
|
||||||
|
|
||||||
|
if (null !== $address->getPostCode()->getCountry()->getCountryCode()) {
|
||||||
|
if ($address->getPostCode()->getCountry()->getCountryCode() === 'FR') {
|
||||||
|
$text = $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet();
|
||||||
|
} else {
|
||||||
|
$text = $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
'address_id' => $address->getId(),
|
'address_id' => $address->getId(),
|
||||||
'text' => $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet(),
|
'text' => $text,
|
||||||
'street' => $address->getStreet(),
|
'street' => $address->getStreet(),
|
||||||
'streetNumber' => $address->getStreetNumber(),
|
'streetNumber' => $address->getStreetNumber(),
|
||||||
'postcode' => [
|
'postcode' => [
|
||||||
@ -48,18 +84,52 @@ class AddressNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
|||||||
'buildingName' => $address->getBuildingName(),
|
'buildingName' => $address->getBuildingName(),
|
||||||
'distribution' => $address->getDistribution(),
|
'distribution' => $address->getDistribution(),
|
||||||
'extra' => $address->getExtra(),
|
'extra' => $address->getExtra(),
|
||||||
'validFrom' => $address->getValidFrom(),
|
];
|
||||||
'validTo' => $address->getValidTo(),
|
|
||||||
'addressReference' => $this->normalizer->normalize(
|
if ('json' === $format) {
|
||||||
|
$data['addressReference'] = $this->normalizer->normalize(
|
||||||
$address->getAddressReference(),
|
$address->getAddressReference(),
|
||||||
$format,
|
$format,
|
||||||
[AbstractNormalizer::GROUPS => ['read']]
|
[AbstractNormalizer::GROUPS => ['read']]
|
||||||
),
|
);
|
||||||
];
|
$data['validFrom'] = $address->getValidFrom();
|
||||||
|
$data['validTo'] = $address->getValidTo();
|
||||||
|
} elseif ('docgen' === $format) {
|
||||||
|
$dateContext = array_merge($context, ['docgen:expects' => DateTimeInterface::class]);
|
||||||
|
$data['validFrom'] = $this->normalizer->normalize($address->getValidFrom(), $format, $dateContext);
|
||||||
|
$data['validTo'] = $this->normalizer->normalize($address->getValidTo(), $format, $dateContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsNormalization($data, ?string $format = null)
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $address) {
|
||||||
|
$helper = new NormalizeNullValueHelper($this->normalizer);
|
||||||
|
|
||||||
|
return array_merge(
|
||||||
|
$helper->normalize(self::NULL_VALUE, $format, $context),
|
||||||
|
[
|
||||||
|
'postcode' => $helper->normalize(self::NULL_POSTCODE_COUNTRY, $format, $context),
|
||||||
|
'country' => $helper->normalize(self::NULL_POSTCODE_COUNTRY, $format, $context),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new UnexpectedValueException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||||
{
|
{
|
||||||
|
if ('json' === $format) {
|
||||||
return $data instanceof Address;
|
return $data instanceof Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('docgen' === $format) {
|
||||||
|
return
|
||||||
|
$data instanceof Address
|
||||||
|
|| (null === $data && Address::class === ($context['docgen:expects'] ?? null));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,28 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Center;
|
||||||
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Entity\UserJob;
|
||||||
use Chill\MainBundle\Templating\Entity\UserRender;
|
use Chill\MainBundle\Templating\Entity\UserRender;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
||||||
|
|
||||||
class UserNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||||
{
|
{
|
||||||
use NormalizerAwareTrait;
|
use NormalizerAwareTrait;
|
||||||
|
|
||||||
|
public const NULL_USER = [
|
||||||
|
'type' => 'user',
|
||||||
|
'id' => '',
|
||||||
|
'username' => '',
|
||||||
|
'text' => '',
|
||||||
|
'label' => '',
|
||||||
|
'email' => '',
|
||||||
|
];
|
||||||
|
|
||||||
private UserRender $userRender;
|
private UserRender $userRender;
|
||||||
|
|
||||||
public function __construct(UserRender $userRender)
|
public function __construct(UserRender $userRender)
|
||||||
@ -31,20 +43,50 @@ class UserNormalizer implements NormalizerAwareInterface, NormalizerInterface
|
|||||||
public function normalize($user, ?string $format = null, array $context = [])
|
public function normalize($user, ?string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
|
$userJobContext = array_merge(
|
||||||
|
$context,
|
||||||
|
['docgen:expects' => UserJob::class, 'groups' => 'docgen:read']
|
||||||
|
);
|
||||||
|
$scopeContext = array_merge(
|
||||||
|
$context,
|
||||||
|
['docgen:expects' => Scope::class, 'groups' => 'docgen:read']
|
||||||
|
);
|
||||||
|
$centerContext = array_merge(
|
||||||
|
$context,
|
||||||
|
['docgen:expects' => Center::class, 'groups' => 'docgen:read']
|
||||||
|
);
|
||||||
|
|
||||||
|
if (null === $user && 'docgen' === $format) {
|
||||||
|
return array_merge(self::NULL_USER, [
|
||||||
|
'user_job' => $this->normalizer->normalize(null, $format, $userJobContext),
|
||||||
|
'main_center' => $this->normalizer->normalize(null, $format, $centerContext),
|
||||||
|
'main_scope' => $this->normalizer->normalize(null, $format, $scopeContext),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'type' => 'user',
|
'type' => 'user',
|
||||||
'id' => $user->getId(),
|
'id' => $user->getId(),
|
||||||
'username' => $user->getUsername(),
|
'username' => $user->getUsername(),
|
||||||
'text' => $this->userRender->renderString($user, []),
|
'text' => $this->userRender->renderString($user, []),
|
||||||
'label' => $user->getLabel(),
|
'label' => $user->getLabel(),
|
||||||
'user_job' => $this->normalizer->normalize($user->getUserJob(), $format, $context),
|
'email' => (string) $user->getEmail(),
|
||||||
'main_center' => $this->normalizer->normalize($user->getMainCenter(), $format, $context),
|
'user_job' => $this->normalizer->normalize($user->getUserJob(), $format, $userJobContext),
|
||||||
'main_scope' => $this->normalizer->normalize($user->getMainScope(), $format, $context),
|
'main_center' => $this->normalizer->normalize($user->getMainCenter(), $format, $centerContext),
|
||||||
|
'main_scope' => $this->normalizer->normalize($user->getMainScope(), $format, $scopeContext),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsNormalization($data, ?string $format = null): bool
|
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||||
{
|
{
|
||||||
return $data instanceof User && ('json' === $format || 'docgen' === $format);
|
if ($data instanceof User && ('json' === $format || 'docgen' === $format)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $data && 'docgen' === $format && User::class === ($context['docgen:expects'] ?? null)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ class AddressRender implements ChillEntityRenderInterface
|
|||||||
return $this->templating
|
return $this->templating
|
||||||
->render('@ChillMain/Entity/address.html.twig', [
|
->render('@ChillMain/Entity/address.html.twig', [
|
||||||
'address' => $addr,
|
'address' => $addr,
|
||||||
|
'streetLine' => $this->renderStreetLine($addr),
|
||||||
'render' => $options['render'] ?? 'bloc',
|
'render' => $options['render'] ?? 'bloc',
|
||||||
'options' => $options,
|
'options' => $options,
|
||||||
]);
|
]);
|
||||||
@ -59,13 +60,7 @@ class AddressRender implements ChillEntityRenderInterface
|
|||||||
{
|
{
|
||||||
$lines = [];
|
$lines = [];
|
||||||
|
|
||||||
if (!empty($addr->getStreet())) {
|
$lines[0] = $this->renderStreetLine($addr);
|
||||||
$lines[0] = $addr->getStreet();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($addr->getStreetNumber())) {
|
|
||||||
$lines[0] .= ', ' . $addr->getStreetNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($addr->getPostcode())) {
|
if (!empty($addr->getPostcode())) {
|
||||||
$lines[1] = strtr('{postcode} {label}', [
|
$lines[1] = strtr('{postcode} {label}', [
|
||||||
@ -81,4 +76,33 @@ class AddressRender implements ChillEntityRenderInterface
|
|||||||
{
|
{
|
||||||
return $entity instanceof Address;
|
return $entity instanceof Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function renderStreetLine($addr): string
|
||||||
|
{
|
||||||
|
if (!empty($addr->getStreet())) {
|
||||||
|
$street = $addr->getStreet();
|
||||||
|
} else {
|
||||||
|
$street = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($addr->getStreetNumber())) {
|
||||||
|
$streetNumber = $addr->getStreetNumber();
|
||||||
|
} else {
|
||||||
|
$streetNumber = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = trim($street . ', ' . $streetNumber, ', ');
|
||||||
|
|
||||||
|
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
|
||||||
|
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
|
||||||
|
$res = trim($streetNumber . ', ' . $street, ', ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (',' === $res) {
|
||||||
|
$res = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\Serializer\Exception\RuntimeException;
|
use Symfony\Component\Serializer\Exception\RuntimeException;
|
||||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Symfony\Component\Workflow\Registry;
|
use Symfony\Component\Workflow\Registry;
|
||||||
use function array_values;
|
use function array_values;
|
||||||
@ -294,4 +296,17 @@ final class AccompanyingCourseApiController extends ApiController
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function validate(string $action, Request $request, string $_format, $entity, array $more = []): ConstraintViolationListInterface
|
||||||
|
{
|
||||||
|
if ('work' !== $action) {
|
||||||
|
return parent::validate($action, $request, $_format, $entity, $more);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Request::METHOD_POST === $request->getMethod()) {
|
||||||
|
return $this->getValidator()->validate($more[0], null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ConstraintViolationList([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,9 +222,7 @@ final class PersonController extends AbstractController
|
|||||||
'label' => 'Add the person',
|
'label' => 'Add the person',
|
||||||
])->add('createPeriod', SubmitType::class, [
|
])->add('createPeriod', SubmitType::class, [
|
||||||
'label' => 'Add the person and create an accompanying period',
|
'label' => 'Add the person and create an accompanying period',
|
||||||
])->add('createHousehold', SubmitType::class, [
|
]);
|
||||||
'label' => 'Add the person and create an household',
|
|
||||||
]); // TODO createHousehold form action
|
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ namespace Chill\PersonBundle\Controller;
|
|||||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
|
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use function array_values;
|
|
||||||
|
|
||||||
class RelationshipApiController extends ApiController
|
class RelationshipApiController extends ApiController
|
||||||
{
|
{
|
||||||
@ -36,9 +36,10 @@ class RelationshipApiController extends ApiController
|
|||||||
*/
|
*/
|
||||||
public function getRelationshipsByPerson(Person $person)
|
public function getRelationshipsByPerson(Person $person)
|
||||||
{
|
{
|
||||||
//TODO: add permissions? (voter?)
|
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person);
|
||||||
|
|
||||||
$relationships = $this->repository->findByPerson($person);
|
$relationships = $this->repository->findByPerson($person);
|
||||||
|
|
||||||
return $this->json(array_values($relationships), Response::HTTP_OK, [], ['groups' => ['read']]);
|
return $this->json($relationships, Response::HTTP_OK, [], ['groups' => ['read']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
$loader->load('services/serializer.yaml');
|
$loader->load('services/serializer.yaml');
|
||||||
$loader->load('services/security.yaml');
|
$loader->load('services/security.yaml');
|
||||||
$loader->load('services/doctrineEventListener.yaml');
|
$loader->load('services/doctrineEventListener.yaml');
|
||||||
|
$loader->load('services/accompanyingPeriodConsistency.yaml');
|
||||||
|
|
||||||
if ($container->getParameter('chill_person.accompanying_period') !== 'hidden') {
|
if ($container->getParameter('chill_person.accompanying_period') !== 'hidden') {
|
||||||
$loader->load('services/exports_accompanying_period.yaml');
|
$loader->load('services/exports_accompanying_period.yaml');
|
||||||
|
@ -80,6 +80,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->append($this->addFieldNode('memo'))
|
->append($this->addFieldNode('memo'))
|
||||||
->append($this->addFieldNode('number_of_children'))
|
->append($this->addFieldNode('number_of_children'))
|
||||||
->append($this->addFieldNode('acceptEmail'))
|
->append($this->addFieldNode('acceptEmail'))
|
||||||
|
->append($this->addFieldNode('deathdate'))
|
||||||
->arrayNode('alt_names')
|
->arrayNode('alt_names')
|
||||||
->defaultValue([])
|
->defaultValue([])
|
||||||
->arrayPrototype()
|
->arrayPrototype()
|
||||||
|
@ -789,6 +789,22 @@ class AccompanyingPeriod implements
|
|||||||
return $this->requestorPerson ?? $this->requestorThirdParty;
|
return $this->requestorPerson ?? $this->requestorThirdParty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string 'person' if requestor is an instanceof @see{Person::class}, 'thirdparty' if this is an instanceof @see{ThirdParty::class}, or 'none'
|
||||||
|
*/
|
||||||
|
public function getRequestorKind(): string
|
||||||
|
{
|
||||||
|
if ($this->getRequestor() instanceof ThirdParty) {
|
||||||
|
return 'thirdparty';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getRequestor() instanceof Person) {
|
||||||
|
return 'person';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'none';
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequestorPerson(): ?Person
|
public function getRequestorPerson(): ?Person
|
||||||
{
|
{
|
||||||
return $this->requestorPerson;
|
return $this->requestorPerson;
|
||||||
|
@ -14,10 +14,12 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|||||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodLinkedWithSocialIssuesEntityInterface;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\SocialWork\Result;
|
use Chill\PersonBundle\Entity\SocialWork\Result;
|
||||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||||
|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
@ -38,7 +40,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
* }
|
* }
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
class AccompanyingPeriodWork implements TrackCreationInterface, TrackUpdateInterface
|
class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterface, TrackCreationInterface, TrackUpdateInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
|
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
|
||||||
@ -320,6 +322,11 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
return $this->socialAction;
|
return $this->socialAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSocialIssues(): Collection
|
||||||
|
{
|
||||||
|
return new ArrayCollection([$this->getSocialAction()->getIssue()]);
|
||||||
|
}
|
||||||
|
|
||||||
public function getStartDate(): ?DateTimeInterface
|
public function getStartDate(): ?DateTimeInterface
|
||||||
{
|
{
|
||||||
return $this->startDate;
|
return $this->startDate;
|
||||||
@ -383,6 +390,13 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeSocialIssue(SocialIssue $issue): AccompanyingPeriodLinkedWithSocialIssuesEntityInterface
|
||||||
|
{
|
||||||
|
$this->getSocialIssues()->removeElement($issue);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function removeThirdParty(ThirdParty $thirdParty): self
|
public function removeThirdParty(ThirdParty $thirdParty): self
|
||||||
{
|
{
|
||||||
$this->thirdParties->removeElement($thirdParty);
|
$this->thirdParties->removeElement($thirdParty);
|
||||||
|
@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClosingMotive give an explanation why we closed the Accompanying period.
|
* ClosingMotive give an explanation why we closed the Accompanying period.
|
||||||
@ -24,22 +25,18 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
class ClosingMotive
|
class ClosingMotive
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var bool
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="boolean")
|
* @ORM\Column(type="boolean")
|
||||||
*/
|
*/
|
||||||
private $active = true;
|
private bool $active = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Child Accompanying periods.
|
* Child Accompanying periods.
|
||||||
*
|
*
|
||||||
* @var Collection
|
|
||||||
*
|
|
||||||
* @ORM\OneToMany(
|
* @ORM\OneToMany(
|
||||||
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
|
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
|
||||||
* mappedBy="parent")
|
* mappedBy="parent")
|
||||||
*/
|
*/
|
||||||
private $children;
|
private Collection $children;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
@ -47,22 +44,21 @@ class ClosingMotive
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $name;
|
private array $name = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var float
|
|
||||||
*
|
|
||||||
* @ORM\Column(type="float")
|
* @ORM\Column(type="float")
|
||||||
*/
|
*/
|
||||||
private $ordering = 0.0;
|
private float $ordering = 0.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var self
|
* @var self
|
||||||
@ -71,7 +67,7 @@ class ClosingMotive
|
|||||||
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
|
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
|
||||||
* inversedBy="children")
|
* inversedBy="children")
|
||||||
*/
|
*/
|
||||||
private $parent;
|
private ?ClosingMotive $parent = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClosingMotive constructor.
|
* ClosingMotive constructor.
|
||||||
|
@ -31,15 +31,16 @@ class Origin
|
|||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $label;
|
private array $label = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="date_immutable", nullable=true)
|
* @ORM\Column(type="date_immutable", nullable=true)
|
||||||
@ -52,7 +53,7 @@ class Origin
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLabel()
|
public function getLabel(): array
|
||||||
{
|
{
|
||||||
return $this->label;
|
return $this->label;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ class HouseholdMember
|
|||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Person
|
* @var Person
|
||||||
@ -73,6 +73,7 @@ class HouseholdMember
|
|||||||
* targetEntity="\Chill\PersonBundle\Entity\Person"
|
* targetEntity="\Chill\PersonBundle\Entity\Person"
|
||||||
* )
|
* )
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"docgen:person:with-household": false})
|
||||||
* @Assert\Valid(groups={"household_memberships"})
|
* @Assert\Valid(groups={"household_memberships"})
|
||||||
* @Assert\NotNull(groups={"household_memberships"})
|
* @Assert\NotNull(groups={"household_memberships"})
|
||||||
*/
|
*/
|
||||||
|
@ -35,11 +35,12 @@ class Position
|
|||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?int $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private array $label = [];
|
private array $label = [];
|
||||||
|
|
||||||
|
@ -244,6 +244,8 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
* @Assert\Date(
|
* @Assert\Date(
|
||||||
* groups={"general", "creation"}
|
* groups={"general", "creation"}
|
||||||
* )
|
* )
|
||||||
|
* @Assert\GreaterThan(propertyPath="birthDate")
|
||||||
|
* @Assert\LessThanOrEqual("today")
|
||||||
*/
|
*/
|
||||||
private ?DateTimeImmutable $deathdate = null;
|
private ?DateTimeImmutable $deathdate = null;
|
||||||
|
|
||||||
@ -588,8 +590,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// a period opened and another one after it
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function used for validation that check if the accompanying periods of
|
* Function used for validation that check if the accompanying periods of
|
||||||
* the person are not collapsing (i.e. have not shared days) or having
|
* the person are not collapsing (i.e. have not shared days) or having
|
||||||
@ -1776,7 +1776,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setNumberOfChildren(int $numberOfChildren): self
|
public function setNumberOfChildren(?int $numberOfChildren): self
|
||||||
{
|
{
|
||||||
$this->numberOfChildren = $numberOfChildren;
|
$this->numberOfChildren = $numberOfChildren;
|
||||||
|
|
||||||
|
@ -41,12 +41,14 @@ class Relation
|
|||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json", nullable=true)
|
* @ORM\Column(type="json", nullable=true)
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private array $reverseTitle = [];
|
private array $reverseTitle = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json", nullable=true)
|
* @ORM\Column(type="json", nullable=true)
|
||||||
* @Serializer\Groups({"read"})
|
* @Serializer\Groups({"read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private array $title = [];
|
private array $title = [];
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ use DateTimeImmutable;
|
|||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
use Doctrine\ORM\Mapping\DiscriminatorColumn;
|
||||||
|
use RuntimeException;
|
||||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
@ -116,6 +117,27 @@ class Relationship implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the opposite person of the @see{counterpart} person.
|
||||||
|
*
|
||||||
|
* this is the from person if the given is associated to the To,
|
||||||
|
* or the To person otherwise.
|
||||||
|
*
|
||||||
|
* @throw RuntimeException if the counterpart is neither in the from or to person
|
||||||
|
*/
|
||||||
|
public function getOpposite(Person $counterpart): Person
|
||||||
|
{
|
||||||
|
if ($this->fromPerson !== $counterpart && $this->toPerson !== $counterpart) {
|
||||||
|
throw new RuntimeException('the counterpart is neither the from nor to person for this relationship');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->fromPerson === $counterpart) {
|
||||||
|
return $this->toPerson;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fromPerson;
|
||||||
|
}
|
||||||
|
|
||||||
public function getRelation(): ?Relation
|
public function getRelation(): ?Relation
|
||||||
{
|
{
|
||||||
return $this->relation;
|
return $this->relation;
|
||||||
|
@ -55,6 +55,7 @@ class Evaluation
|
|||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private array $title = [];
|
private array $title = [];
|
||||||
|
|
||||||
|
@ -40,24 +40,25 @@ class Goal
|
|||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="goals")
|
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="goals")
|
||||||
* @ORM\JoinTable(name="chill_person_social_work_goal_result")
|
* @ORM\JoinTable(name="chill_person_social_work_goal_result")
|
||||||
*/
|
*/
|
||||||
private $results;
|
private Collection $results;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=SocialAction::class, mappedBy="goals")
|
* @ORM\ManyToMany(targetEntity=SocialAction::class, mappedBy="goals")
|
||||||
*/
|
*/
|
||||||
private $socialActions;
|
private Collection $socialActions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $title = [];
|
private array $title = [];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Entity\SocialWork;
|
|||||||
|
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal;
|
||||||
|
use DateTime;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
@ -34,22 +35,22 @@ class Result
|
|||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=AccompanyingPeriodWorkGoal::class, mappedBy="results")
|
* @ORM\ManyToMany(targetEntity=AccompanyingPeriodWorkGoal::class, mappedBy="results")
|
||||||
*/
|
*/
|
||||||
private $accompanyingPeriodWorkGoals;
|
private Collection $accompanyingPeriodWorkGoals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=AccompanyingPeriodWork::class, mappedBy="results")
|
* @ORM\ManyToMany(targetEntity=AccompanyingPeriodWork::class, mappedBy="results")
|
||||||
*/
|
*/
|
||||||
private $accompanyingPeriodWorks;
|
private Collection $accompanyingPeriodWorks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="datetime", nullable=true)
|
* @ORM\Column(type="datetime", nullable=true)
|
||||||
*/
|
*/
|
||||||
private $desactivationDate;
|
private DateTime $desactivationDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=Goal::class, mappedBy="results")
|
* @ORM\ManyToMany(targetEntity=Goal::class, mappedBy="results")
|
||||||
*/
|
*/
|
||||||
private $goals;
|
private Collection $goals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
@ -57,18 +58,19 @@ class Result
|
|||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToMany(targetEntity=SocialAction::class, mappedBy="results")
|
* @ORM\ManyToMany(targetEntity=SocialAction::class, mappedBy="results")
|
||||||
*/
|
*/
|
||||||
private $socialActions;
|
private Collection $socialActions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
* @Serializer\Groups({"read", "docgen:read"})
|
* @Serializer\Groups({"read", "docgen:read"})
|
||||||
|
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $title = [];
|
private array $title = [];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -93,6 +93,7 @@ class PersonType extends AbstractType
|
|||||||
])
|
])
|
||||||
->add('numberOfChildren', IntegerType::class, [
|
->add('numberOfChildren', IntegerType::class, [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
|
'attr' => ['min' => 0],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($this->configAltNamesHelper->hasAltNames()) {
|
if ($this->configAltNamesHelper->hasAltNames()) {
|
||||||
|
@ -11,18 +11,31 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Repository\Relationships;
|
namespace Chill\PersonBundle\Repository\Relationships;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
|
|
||||||
class RelationshipRepository implements ObjectRepository
|
class RelationshipRepository implements ObjectRepository
|
||||||
{
|
{
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
private EntityRepository $repository;
|
private EntityRepository $repository;
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$this->repository = $em->getRepository(Relationship::class);
|
$this->repository = $em->getRepository(Relationship::class);
|
||||||
|
$this->em = $em;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function countByPerson(Person $person): int
|
||||||
|
{
|
||||||
|
return $this->buildQueryByPerson($person)
|
||||||
|
->select('COUNT(p)')
|
||||||
|
->getQuery()
|
||||||
|
->getSingleScalarResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find($id): ?Relationship
|
public function find($id): ?Relationship
|
||||||
@ -40,15 +53,13 @@ class RelationshipRepository implements ObjectRepository
|
|||||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findByPerson($personId): array
|
/**
|
||||||
|
* @return array|Relationship[]
|
||||||
|
*/
|
||||||
|
public function findByPerson(Person $person): array
|
||||||
{
|
{
|
||||||
// return all relationships of which person is part? or only where person is the fromPerson?
|
return $this->buildQueryByPerson($person)
|
||||||
return $this->repository->createQueryBuilder('r')
|
->select('r')
|
||||||
->select('r, t') // entity Relationship
|
|
||||||
->join('r.relation', 't')
|
|
||||||
->where('r.fromPerson = :val')
|
|
||||||
->orWhere('r.toPerson = :val')
|
|
||||||
->setParameter('val', $personId)
|
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
}
|
}
|
||||||
@ -62,4 +73,20 @@ class RelationshipRepository implements ObjectRepository
|
|||||||
{
|
{
|
||||||
return Relationship::class;
|
return Relationship::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildQueryByPerson(Person $person): QueryBuilder
|
||||||
|
{
|
||||||
|
$qb = $this->em->createQueryBuilder();
|
||||||
|
$qb
|
||||||
|
->from(Relationship::class, 'r')
|
||||||
|
->where(
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->eq('r.fromPerson', ':person'),
|
||||||
|
$qb->expr()->eq('r.toPerson', ':person')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setParameter('person', $person);
|
||||||
|
|
||||||
|
return $qb;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<label for="selectOrigin">
|
<label for="selectOrigin">
|
||||||
{{ $t('origin.label') }}
|
{{ $t('origin.label.fr') }}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<VueMultiselect
|
<VueMultiselect
|
||||||
@ -75,8 +75,7 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
transText ({ text }) {
|
transText ({ text }) {
|
||||||
const parsedText = JSON.parse(text);
|
return text.fr;
|
||||||
return parsedText.fr;
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,10 @@ const appMessages = {
|
|||||||
sure_description: "Une fois le changement confirmé, il ne sera plus possible de le remettre à l'état de brouillon !",
|
sure_description: "Une fois le changement confirmé, il ne sera plus possible de le remettre à l'état de brouillon !",
|
||||||
ok: "Confirmer le parcours"
|
ok: "Confirmer le parcours"
|
||||||
},
|
},
|
||||||
|
action: {
|
||||||
|
choose_other_social_issue: "Veuillez choisir un autre problématique",
|
||||||
|
cancel: "Annuler",
|
||||||
|
},
|
||||||
// catch errors
|
// catch errors
|
||||||
'Error while updating AccompanyingPeriod Course.': "Erreur du serveur lors de la mise à jour du parcours d'accompagnement.",
|
'Error while updating AccompanyingPeriod Course.': "Erreur du serveur lors de la mise à jour du parcours d'accompagnement.",
|
||||||
'Error while retriving AccompanyingPeriod Course.': "Erreur du serveur lors du chargement du parcours d'accompagnement.",
|
'Error while retriving AccompanyingPeriod Course.': "Erreur du serveur lors du chargement du parcours d'accompagnement.",
|
||||||
|
@ -7,13 +7,35 @@
|
|||||||
|
|
||||||
<div id="picking">
|
<div id="picking">
|
||||||
<p>{{ $t('pick_social_issue_linked_with_action') }}</p>
|
<p>{{ $t('pick_social_issue_linked_with_action') }}</p>
|
||||||
|
|
||||||
<div v-for="si in socialIssues">
|
<div v-for="si in socialIssues">
|
||||||
<input type="radio" v-bind:value="si.id" name="socialIssue" v-model="socialIssuePicked"><span class="badge bg-chill-l-gray text-dark">{{ si.text }}</span>
|
<input type="radio" checked v-bind:value="si.id" name="socialIssue" v-model="socialIssuePicked"><span class="badge bg-chill-l-gray text-dark">{{ si.text }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="my-3">
|
||||||
|
<div class="col-8">
|
||||||
|
<vue-multiselect
|
||||||
|
name="otherIssues"
|
||||||
|
label="text"
|
||||||
|
track-by="id"
|
||||||
|
open-direction="bottom"
|
||||||
|
:close-on-select="true"
|
||||||
|
:preserve-search="false"
|
||||||
|
:reset-after="true"
|
||||||
|
:hide-selected="true"
|
||||||
|
:taggable="false"
|
||||||
|
:multiple="false"
|
||||||
|
:searchable="true"
|
||||||
|
:allow-empty="true"
|
||||||
|
:show-labels="false"
|
||||||
|
:loading="issueIsLoading"
|
||||||
|
:placeholder="$t('action.choose_other_social_issue')"
|
||||||
|
:options="socialIssuesOther"
|
||||||
|
@select="addIssueInList">
|
||||||
|
</vue-multiselect>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="hasSocialIssuePicked">
|
<div v-if="hasSocialIssuePicked">
|
||||||
<h2>{{ $t('pick_an_action') }}</h2>
|
<h2>{{ $t('pick_an_action') }}</h2>
|
||||||
|
<div class="col-8">
|
||||||
<vue-multiselect
|
<vue-multiselect
|
||||||
v-model="socialActionPicked"
|
v-model="socialActionPicked"
|
||||||
label="text"
|
label="text"
|
||||||
@ -24,6 +46,7 @@
|
|||||||
track-by="id"
|
track-by="id"
|
||||||
></vue-multiselect>
|
></vue-multiselect>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="isLoadingSocialActions">
|
<div v-if="isLoadingSocialActions">
|
||||||
<i class="fa fa-circle-o-notch fa-spin fa-fw"></i>
|
<i class="fa fa-circle-o-notch fa-spin fa-fw"></i>
|
||||||
@ -63,9 +86,9 @@
|
|||||||
<div>
|
<div>
|
||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li class="cancel">
|
<li class="cancel">
|
||||||
<a href="#" class="btn btn-cancel">
|
<button class="btn btn-cancel" @click="goToPrevious">
|
||||||
{{ $t('action.cancel') }}
|
{{ $t('action.cancel') }}
|
||||||
</a>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li v-if="hasSocialActionPicked">
|
<li v-if="hasSocialActionPicked">
|
||||||
<button class="btn btn-save" v-show="!isPostingWork" @click="submit">
|
<button class="btn btn-save" v-show="!isPostingWork" @click="submit">
|
||||||
@ -82,43 +105,7 @@
|
|||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
|
|
||||||
#awc_create_form {
|
|
||||||
display: grid;
|
|
||||||
grid-template-areas:
|
|
||||||
"picking picking"
|
|
||||||
"start_date end_date"
|
|
||||||
"confirm confirm"
|
|
||||||
;
|
|
||||||
grid-template-columns: 50% 50%;
|
|
||||||
column-gap: 1.5rem;
|
|
||||||
|
|
||||||
#picking {
|
|
||||||
grid-area: picking;
|
|
||||||
|
|
||||||
#persons {
|
|
||||||
ul {
|
|
||||||
padding: 0;
|
|
||||||
|
|
||||||
list-style-type: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#start_date {
|
|
||||||
grid-area: start_date;
|
|
||||||
}
|
|
||||||
|
|
||||||
#end_date {
|
|
||||||
grid-area: end_date;
|
|
||||||
}
|
|
||||||
|
|
||||||
#confirm {
|
|
||||||
grid-area: confirm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapState, mapActions, mapGetters } from 'vuex';
|
import { mapState, mapActions, mapGetters } from 'vuex';
|
||||||
@ -149,13 +136,34 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
submit() {
|
submit() {
|
||||||
this.$store.dispatch('submit');
|
this.$store.dispatch('submit')
|
||||||
|
.catch(({name, violations}) => {
|
||||||
|
if (name === 'ValidationException' || name === 'AccessException') {
|
||||||
|
violations.forEach((violation) => this.$toast.open({message: violation}));
|
||||||
|
} else {
|
||||||
|
this.$toast.open({message: 'An error occurred'})
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
addIssueInList(value) {
|
||||||
|
this.$store.commit('addIssueInList', value);
|
||||||
|
this.$store.commit('removeIssueInOther', value);
|
||||||
|
this.$store.dispatch('pickSocialIssue', value.id);
|
||||||
|
},
|
||||||
|
goToPrevious() {
|
||||||
|
let params = new URLSearchParams(window.location.search);
|
||||||
|
if (params.has('returnPath')) {
|
||||||
|
window.location.replace(params.get('returnPath'));
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
i18n,
|
i18n,
|
||||||
computed: {
|
computed: {
|
||||||
...mapState([
|
...mapState([
|
||||||
'socialIssues',
|
'socialIssues',
|
||||||
|
'socialIssuesOther',
|
||||||
'socialActionsReachables',
|
'socialActionsReachables',
|
||||||
'errors',
|
'errors',
|
||||||
'personsReachables',
|
'personsReachables',
|
||||||
@ -170,12 +178,12 @@ export default {
|
|||||||
personsPicked: {
|
personsPicked: {
|
||||||
get() {
|
get() {
|
||||||
let s = this.$store.state.personsPicked.map(p => p.id);
|
let s = this.$store.state.personsPicked.map(p => p.id);
|
||||||
console.log('persons picked', s);
|
// console.log('persons picked', s);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
},
|
},
|
||||||
set(v) {
|
set(v) {
|
||||||
console.log('persons picked', v);
|
// console.log('persons picked', v);
|
||||||
this.$store.commit('setPersonsPickedIds', v);
|
this.$store.commit('setPersonsPickedIds', v);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -235,3 +243,41 @@ span.badge {
|
|||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
|
||||||
|
#awc_create_form {
|
||||||
|
display: grid;
|
||||||
|
grid-template-areas:
|
||||||
|
"picking picking"
|
||||||
|
"start_date end_date"
|
||||||
|
"confirm confirm"
|
||||||
|
;
|
||||||
|
grid-template-columns: 50% 50%;
|
||||||
|
column-gap: 1.5rem;
|
||||||
|
|
||||||
|
#picking {
|
||||||
|
grid-area: picking;
|
||||||
|
|
||||||
|
#persons {
|
||||||
|
ul {
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#start_date {
|
||||||
|
grid-area: start_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
#end_date {
|
||||||
|
grid-area: end_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
#confirm {
|
||||||
|
grid-area: confirm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@ -2,7 +2,8 @@
|
|||||||
import { createStore } from 'vuex';
|
import { createStore } from 'vuex';
|
||||||
import { datetimeToISO } from 'ChillMainAssets/chill/js/date.js';
|
import { datetimeToISO } from 'ChillMainAssets/chill/js/date.js';
|
||||||
import { findSocialActionsBySocialIssue } from 'ChillPersonAssets/vuejs/_api/SocialWorkSocialAction.js';
|
import { findSocialActionsBySocialIssue } from 'ChillPersonAssets/vuejs/_api/SocialWorkSocialAction.js';
|
||||||
import { create } from 'ChillPersonAssets/vuejs/_api/AccompanyingCourseWork.js';
|
// import { create } from 'ChillPersonAssets/vuejs/_api/AccompanyingCourseWork.js';
|
||||||
|
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ const store = createStore({
|
|||||||
accompanyingCourse: window.accompanyingCourse,
|
accompanyingCourse: window.accompanyingCourse,
|
||||||
socialIssues: window.accompanyingCourse.socialIssues,
|
socialIssues: window.accompanyingCourse.socialIssues,
|
||||||
socialIssuePicked: null,
|
socialIssuePicked: null,
|
||||||
|
socialIssuesOther: [],
|
||||||
socialActionsReachables: [],
|
socialActionsReachables: [],
|
||||||
socialActionPicked: null,
|
socialActionPicked: null,
|
||||||
personsPicked: window.accompanyingCourse.participations.filter(p => p.endDate == null)
|
personsPicked: window.accompanyingCourse.participations.filter(p => p.endDate == null)
|
||||||
@ -26,7 +28,6 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
hasSocialActionPicked(state) {
|
hasSocialActionPicked(state) {
|
||||||
console.log(state.socialActionPicked);
|
|
||||||
return null !== state.socialActionPicked;
|
return null !== state.socialActionPicked;
|
||||||
},
|
},
|
||||||
hasSocialIssuePicked(state) {
|
hasSocialIssuePicked(state) {
|
||||||
@ -73,27 +74,43 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setSocialActionsReachables(state, actions) {
|
setSocialActionsReachables(state, actions) {
|
||||||
console.log('set social action reachables');
|
// console.log('set social action reachables');
|
||||||
console.log(actions);
|
// console.log(actions);
|
||||||
|
|
||||||
state.socialActionsReachables = actions;
|
state.socialActionsReachables = actions;
|
||||||
},
|
},
|
||||||
setSocialAction(state, socialAction) {
|
setSocialAction(state, socialAction) {
|
||||||
console.log('socialAction', socialAction);
|
// console.log('socialAction', socialAction);
|
||||||
state.socialActionPicked = socialAction;
|
state.socialActionPicked = socialAction;
|
||||||
},
|
},
|
||||||
setSocialIssue(state, socialIssueId) {
|
setSocialIssue(state, socialIssueId) {
|
||||||
console.log('set social issue', socialIssueId);
|
// console.log('set social issue', socialIssueId);
|
||||||
if (socialIssueId === null) {
|
if (socialIssueId === null) {
|
||||||
state.socialIssuePicked = null;
|
state.socialIssuePicked = null;
|
||||||
} else {
|
} else {
|
||||||
let mapped = state.socialIssues
|
let mapped = state.socialIssues
|
||||||
.find(e => e.id === socialIssueId);
|
.find(e => e.id === socialIssueId);
|
||||||
console.log('mapped', mapped);
|
|
||||||
state.socialIssuePicked = mapped;
|
state.socialIssuePicked = mapped;
|
||||||
console.log('social issue setted', state.socialIssuePicked);
|
// console.log('social issue setted', state.socialIssuePicked);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
addIssueInList(state, issue) {
|
||||||
|
//console.log('add issue list', issue.id);
|
||||||
|
state.socialIssues.push(issue);
|
||||||
|
},
|
||||||
|
updateIssuesOther(state, payload) {
|
||||||
|
//console.log('update issues other');
|
||||||
|
state.socialIssuesOther = payload;
|
||||||
|
},
|
||||||
|
removeIssueInOther(state, issue) {
|
||||||
|
//console.log('remove issue other', issue.id);
|
||||||
|
state.socialIssuesOther = state.socialIssuesOther.filter(
|
||||||
|
(i) => i.id !== issue.id
|
||||||
|
);
|
||||||
|
},
|
||||||
|
updateSelected(state, payload) {
|
||||||
|
state.socialIssueSelected = payload;
|
||||||
|
},
|
||||||
setIsLoadingSocialActions(state, s) {
|
setIsLoadingSocialActions(state, s) {
|
||||||
state.isLoadingSocialActions = s;
|
state.isLoadingSocialActions = s;
|
||||||
},
|
},
|
||||||
@ -131,8 +148,6 @@ const store = createStore({
|
|||||||
|
|
||||||
findSocialActionsBySocialIssue(socialIssueId).then(
|
findSocialActionsBySocialIssue(socialIssueId).then(
|
||||||
(response) => {
|
(response) => {
|
||||||
console.log(response);
|
|
||||||
console.log(response.results);
|
|
||||||
commit('setSocialIssue', socialIssueId);
|
commit('setSocialIssue', socialIssueId);
|
||||||
commit('setSocialActionsReachables', response.results);
|
commit('setSocialActionsReachables', response.results);
|
||||||
commit('setIsLoadingSocialActions', false);
|
commit('setIsLoadingSocialActions', false);
|
||||||
@ -142,34 +157,34 @@ const store = createStore({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
submit({ commit, getters, state }) {
|
submit({ commit, getters, state }) {
|
||||||
console.log('submit');
|
let payload = getters.buildPayloadCreate;
|
||||||
let
|
const url = `/api/1.0/person/accompanying-course/${state.accompanyingCourse.id}/work.json`;
|
||||||
payload = getters.buildPayloadCreate,
|
|
||||||
errors = [];
|
|
||||||
|
|
||||||
commit('setPostingWork');
|
commit('setPostingWork');
|
||||||
|
|
||||||
create(state.accompanyingCourse.id, payload)
|
makeFetch('POST', url, payload)
|
||||||
.then( ({status, data}) => {
|
.then((response) => {
|
||||||
console.log('created return', { status, data});
|
window.location.assign(`/fr/person/accompanying-period/work/${response.id}/edit`)
|
||||||
if (status === 200) {
|
})
|
||||||
console.log('created, nothing to do here any more. Bye-bye!');
|
.catch((error) => {
|
||||||
window.location.assign(`/fr/person/accompanying-period/work/${data.id}/edit`);
|
throw error;
|
||||||
} else if (status === 422) {
|
|
||||||
console.log(data);
|
|
||||||
for (let i in data.violations) {
|
|
||||||
console.log(i);
|
|
||||||
console.log(data.violations[i].title);
|
|
||||||
errors.push(data.violations[i].title);
|
|
||||||
}
|
|
||||||
console.log('errors after reseponse handling', errors);
|
|
||||||
console.log({errors, cancel_posting: true});
|
|
||||||
commit('addErrors', { errors, cancel_posting: true });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
fetchOtherSocialIssues({commit}) {
|
||||||
|
const url = `/api/1.0/person/social-work/social-issue.json`;
|
||||||
|
return makeFetch('GET', url)
|
||||||
|
.then((response) => {
|
||||||
|
commit('updateIssuesOther', response.results);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
throw error;
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
store.dispatch('fetchOtherSocialIssues');
|
||||||
|
|
||||||
export { store };
|
export { store };
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
const create = (accompanying_period_id, payload) => {
|
// const create = (accompanying_period_id, payload) => {
|
||||||
const url = `/api/1.0/person/accompanying-course/${accompanying_period_id}/work.json`;
|
// const url = `/api/1.0/person/accompanying-course/${accompanying_period_id}/work.json`;
|
||||||
let status;
|
// let status;
|
||||||
console.log('create', payload);
|
// console.log('create', payload);
|
||||||
|
|
||||||
return fetch(url, {
|
// return fetch(url, {
|
||||||
method: 'POST',
|
// method: 'POST',
|
||||||
headers: {
|
// headers: {
|
||||||
'Content-Type': 'application/json',
|
// 'Content-Type': 'application/json',
|
||||||
},
|
// },
|
||||||
body: JSON.stringify(payload),
|
// body: JSON.stringify(payload),
|
||||||
})
|
// })
|
||||||
.then(response => {
|
// .then(response => {
|
||||||
if (response.ok || response.status === 422) {
|
// if (response.ok || response.status === 422) {
|
||||||
status = response.status;
|
// status = response.status;
|
||||||
|
|
||||||
return response.json();
|
// return response.json();
|
||||||
}
|
// }
|
||||||
|
|
||||||
throw new Error("Error while retrieving social actions: " + response.status +
|
// throw new Error("Error while retrieving social actions: " + response.status +
|
||||||
" " + response.statusText);
|
// " " + response.statusText);
|
||||||
})
|
// })
|
||||||
.then(data => {
|
// .then(data => {
|
||||||
return new Promise((resolve, reject) => {
|
// return new Promise((resolve, reject) => {
|
||||||
resolve({ status, data });
|
// resolve({ status, data });
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
|
|
||||||
export { create };
|
// export { create };
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<span class="firstname">{{ person.firstName }}</span>
|
<span class="firstname">{{ person.firstName }}</span>
|
||||||
<span class="lastname">{{ person.lastName }}</span>
|
<span class="lastname">{{ person.lastName }}</span>
|
||||||
|
<span v-if="person.deathdate" class="deathdate"> (‡)</span>
|
||||||
<span v-if="person.altNames && options.addAltNames == true" class="altnames">
|
<span v-if="person.altNames && options.addAltNames == true" class="altnames">
|
||||||
<span :class="'altname altname-' + altNameKey">{{ altNameLabel }}</span>
|
<span :class="'altname altname-' + altNameKey">{{ altNameLabel }}</span>
|
||||||
</span>
|
</span>
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
* addAge bool
|
* addAge bool
|
||||||
* addCenter bool
|
* addCenter bool
|
||||||
* hLevel integer
|
* hLevel integer
|
||||||
|
* addDeath bool
|
||||||
* address_multiline bool
|
* address_multiline bool
|
||||||
* customButtons [
|
* customButtons [
|
||||||
'before' Twig\Markup, (injected with macro)
|
'before' Twig\Markup, (injected with macro)
|
||||||
@ -24,7 +25,12 @@
|
|||||||
|
|
||||||
{% macro raw(person, options) %}
|
{% macro raw(person, options) %}
|
||||||
<span class="firstname">{{ person.firstName }}</span>
|
<span class="firstname">{{ person.firstName }}</span>
|
||||||
<span class="lastname">{{ person.lastName }}</span>
|
<span class="lastname">
|
||||||
|
{{ person.lastName }}
|
||||||
|
{%- if options['addDeath'] -%}
|
||||||
|
{% if person.deathdate is not null %} (‡){% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
{%- if options['addAltNames'] -%}
|
{%- if options['addAltNames'] -%}
|
||||||
<span class="altnames">
|
<span class="altnames">
|
||||||
{%- for n in person.altNames -%}
|
{%- for n in person.altNames -%}
|
||||||
@ -82,21 +88,17 @@
|
|||||||
{{ 'Date of death'|trans }}:
|
{{ 'Date of death'|trans }}:
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{#- must be on one line to avoid spaces with dash -#}
|
{#- must be on one line to avoid spaces with dash -#}
|
||||||
<time datetime="{{ person.deathdate|date('Y-m-d') }}" title="{{ 'Deathdate'|trans }}">{{ person.deathdate|format_date("medium") }}</time>
|
<time datetime="{{ person.deathdate|date('Y-m-d') }}" title="{{ 'deathdate'|trans }}">{{ person.deathdate|format_date("medium") }}</time>
|
||||||
{% if options['addAge'] %}
|
{%- if options['addAge'] -%}
|
||||||
<span class="age">
|
<span class="age">{{ 'years_old'|trans({ 'age': person.age }) }}</span>
|
||||||
({{ 'years_old'|trans({ 'age': person.age }) }})
|
{%- endif -%}
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
{%- elseif person.birthdate is not null -%}
|
{%- elseif person.birthdate is not null -%}
|
||||||
<time datetime="{{ person.birthdate|date('Y-m-d') }}" title="{{ 'Birthdate'|trans }}">
|
<time datetime="{{ person.birthdate|date('Y-m-d') }}" title="{{ 'Birthdate'|trans }}">
|
||||||
{{ 'Born the date'|trans({'gender': person.gender,
|
{{ 'Born the date'|trans({'gender': person.gender,
|
||||||
'birthdate': person.birthdate|format_date("medium") }) }}
|
'birthdate': person.birthdate|format_date("medium") }) }}
|
||||||
</time>
|
</time>
|
||||||
{%- if options['addAge'] -%}
|
{%- if options['addAge'] -%}
|
||||||
<span class="age">
|
<span class="age">{{- 'years_old'|trans({ 'age': person.age }) -}}</span>
|
||||||
{{- 'years_old'|trans({ 'age': person.age }) -}}
|
|
||||||
</span>
|
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</p>
|
</p>
|
||||||
|
@ -93,9 +93,6 @@
|
|||||||
<li>
|
<li>
|
||||||
{{ form_widget(form.createPeriod, { 'attr': { 'class': 'dropdown-item' }}) }}
|
{{ form_widget(form.createPeriod, { 'attr': { 'class': 'dropdown-item' }}) }}
|
||||||
</li>
|
</li>
|
||||||
<li>
|
|
||||||
{{ form_widget(form.createHousehold, { 'attr': { 'class': 'dropdown-item' }}) }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -106,5 +103,5 @@
|
|||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
{{ encore_entry_script_tags('mod_disablebuttons') }}
|
{# {{ encore_entry_script_tags('mod_disablebuttons') }} #}
|
||||||
{% endblock js %}
|
{% endblock js %}
|
||||||
|
@ -92,6 +92,13 @@ This view should receive those arguments:
|
|||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
|
{%- if chill_person.fields.deathdate == 'visible' -%}
|
||||||
|
{%- if person.deathdate is not null -%}
|
||||||
|
<dt>{{ 'Date of death'|trans }} :</dt>
|
||||||
|
<dd>{{ person.deathdate|format_date('long') }}</dd>
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
{%- if chill_person.fields.place_of_birth == 'visible' -%}
|
{%- if chill_person.fields.place_of_birth == 'visible' -%}
|
||||||
<dt>{{ 'Place of birth'|trans }} :</dt>
|
<dt>{{ 'Place of birth'|trans }} :</dt>
|
||||||
{% if person.placeOfBirth is not empty %}
|
{% if person.placeOfBirth is not empty %}
|
||||||
@ -111,6 +118,7 @@ This view should receive those arguments:
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endapply %}</dd>
|
{% endapply %}</dd>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
</dl>
|
</dl>
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
@ -159,12 +167,27 @@ This view should receive those arguments:
|
|||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
{%- if chill_person.fields.number_of_children == 'visible' -%}
|
||||||
|
<dl>
|
||||||
|
<dt>{{'Number of children'|trans}} :</dt>
|
||||||
|
<dd>
|
||||||
|
{% if person.numberOfChildren is not null %}
|
||||||
|
{{ person.numberOfChildren }}
|
||||||
|
{% else %}
|
||||||
|
<span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
{%- endif -%}
|
||||||
{%- if chill_person.fields.marital_status == 'visible' -%}
|
{%- if chill_person.fields.marital_status == 'visible' -%}
|
||||||
<dl>
|
<dl>
|
||||||
<dt>{{'Marital status'|trans}} :</dt>
|
<dt>{{'Marital status'|trans}} :</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{% if person.maritalStatus is not null %}
|
{% if person.maritalStatus is not null %}
|
||||||
{{ person.maritalStatus.name|localize_translatable_string }}
|
{{ person.maritalStatus.name|localize_translatable_string }}
|
||||||
|
{% if person.maritalStatusDate is not null %}
|
||||||
|
{{ 'person.from_the'|trans }} {{ person.maritalStatusDate|format_date('long') }}
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
|
<span class="chill-no-data-statement">{{ 'No data given'|trans }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -217,6 +240,7 @@ This view should receive those arguments:
|
|||||||
<dl>
|
<dl>
|
||||||
<dt>{{ 'Mobilenumber'|trans }} :</dt>
|
<dt>{{ 'Mobilenumber'|trans }} :</dt>
|
||||||
<dd>{% if person.mobilenumber is not empty %}<a href="tel:{{ person.mobilenumber }}">{{ person.mobilenumber|chill_format_phonenumber }}</a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
|
<dd>{% if person.mobilenumber is not empty %}<a href="tel:{{ person.mobilenumber }}">{{ person.mobilenumber|chill_format_phonenumber }}</a>{% else %}<span class="chill-no-data-statement">{{ 'No data given'|trans }}{% endif %}</dd>
|
||||||
|
<p>{% if person.acceptSMS %}{{ 'Accept short text message'|trans }}{% endif %}</p>
|
||||||
</dl>
|
</dl>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -11,23 +11,25 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
|
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||||
use Chill\PersonBundle\Templating\Entity\ClosingMotiveRender;
|
use Chill\PersonBundle\Templating\Entity\ClosingMotiveRender;
|
||||||
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||||
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
|
||||||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
use function array_key_exists;
|
|
||||||
use function in_array;
|
|
||||||
use function is_array;
|
use function is_array;
|
||||||
|
|
||||||
class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||||
@ -37,26 +39,31 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
|||||||
private const IGNORE_FIRST_PASS_KEY = 'acc_period_ignore_first_pass';
|
private const IGNORE_FIRST_PASS_KEY = 'acc_period_ignore_first_pass';
|
||||||
|
|
||||||
private const PERIOD_NULL = [
|
private const PERIOD_NULL = [
|
||||||
'id' => '',
|
'id',
|
||||||
'closingDate' => DateTime::class,
|
'closingDate' => DateTime::class,
|
||||||
'confidential' => '',
|
'confidential',
|
||||||
'confidentialText' => '',
|
'confidentialText',
|
||||||
'createdAt' => DateTime::class,
|
'createdAt' => DateTime::class,
|
||||||
'createdBy' => User::class,
|
'createdBy' => User::class,
|
||||||
'emergency' => '',
|
'emergency',
|
||||||
'emergencyText' => '',
|
'emergencyText',
|
||||||
'openingDate' => DateTime::class,
|
'openingDate' => DateTime::class,
|
||||||
'originText' => '',
|
'origin' => AccompanyingPeriod\Origin::class,
|
||||||
'requestorAnonymous' => false,
|
'originText',
|
||||||
'socialIssues' => [],
|
'requestorAnonymous',
|
||||||
'intensity' => '',
|
'socialIssues',
|
||||||
'step' => '',
|
'intensity',
|
||||||
'closingMotiveText' => '',
|
'step',
|
||||||
'socialIssuesText' => '',
|
'closingMotiveText',
|
||||||
'scopes' => [],
|
'socialIssuesText',
|
||||||
'scopesText' => '',
|
'scopes' => Collection::class,
|
||||||
|
'scopesText',
|
||||||
'ref' => User::class,
|
'ref' => User::class,
|
||||||
'participations' => [],
|
'participations' => Collection::class,
|
||||||
|
'currentParticipations' => Collection::class,
|
||||||
|
'requestorPerson' => Person::class,
|
||||||
|
'requestorThirdParty' => ThirdParty::class,
|
||||||
|
'resources' => Collection::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
private ClosingMotiveRender $closingMotiveRender;
|
private ClosingMotiveRender $closingMotiveRender;
|
||||||
@ -89,48 +96,70 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
|||||||
public function normalize($period, ?string $format = null, array $context = [])
|
public function normalize($period, ?string $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
if ($period instanceof AccompanyingPeriod) {
|
if ($period instanceof AccompanyingPeriod) {
|
||||||
$ignored = $context[self::IGNORE_FIRST_PASS_KEY] ?? [];
|
|
||||||
$ignored[] = spl_object_hash($period);
|
|
||||||
$initial =
|
|
||||||
$this->normalizer->normalize($period, $format, array_merge(
|
|
||||||
$context,
|
|
||||||
[self::IGNORE_FIRST_PASS_KEY => $ignored, AbstractNormalizer::GROUPS => 'docgen:read']
|
|
||||||
));
|
|
||||||
|
|
||||||
// some transformation
|
|
||||||
$user = $initial['user'];
|
|
||||||
unset($initial['user']);
|
|
||||||
|
|
||||||
$scopes = $this->scopeResolverDispatcher->isConcerned($period) ? $this->scopeResolverDispatcher->resolveScope($period) : [];
|
$scopes = $this->scopeResolverDispatcher->isConcerned($period) ? $this->scopeResolverDispatcher->resolveScope($period) : [];
|
||||||
|
|
||||||
if (!is_array($scopes)) {
|
if (!is_array($scopes)) {
|
||||||
$scopes = [$scopes];
|
$scopes = [$scopes];
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_merge(
|
$dateContext = array_merge($context, ['docgen:expects' => DateTime::class, 'groups' => 'docgen:read']);
|
||||||
// get a first default data
|
$userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']);
|
||||||
$initial,
|
$participationContext = array_merge($context, ['docgen:expects' => AccompanyingPeriodParticipation::class, 'groups' => 'docgen:read']);
|
||||||
// and add data custom
|
|
||||||
[
|
return [
|
||||||
|
'id' => $period->getId(),
|
||||||
|
'type' => 'accompanying_period',
|
||||||
|
'isNull' => false,
|
||||||
|
'closingDate' => $this->normalizer->normalize($period->getClosingDate(), $format, $dateContext),
|
||||||
|
'confidential' => $period->isConfidential(),
|
||||||
|
'createdAt' => $this->normalizer->normalize($period->getCreatedAt(), $format, $dateContext),
|
||||||
|
'createdBy' => $this->normalizer->normalize($period->getCreatedBy(), $format, $userContext),
|
||||||
|
'emergency' => $period->isEmergency(),
|
||||||
|
'openingDate' => $this->normalizer->normalize($period->getOpeningDate(), $format, $dateContext),
|
||||||
|
'origin' => $this->normalizer->normalize($period->getOrigin(), $format, array_merge($context, ['docgen:expects' => AccompanyingPeriod\Origin::class])),
|
||||||
|
'participations' => $this->normalizer->normalize($period->getParticipations(), $format, $participationContext),
|
||||||
|
'currentParticipations' => $this->normalizer->normalize($period->getCurrentParticipations(), $format, $participationContext),
|
||||||
|
'requestorAnonymous' => $period->isRequestorAnonymous(),
|
||||||
|
'requestorPerson' => $this->normalizer->normalize($period->getRequestorPerson(), $format, array_merge($context, ['docgen:expects' => Person::class])),
|
||||||
|
'hasRequestorPerson' => $period->getRequestorPerson() !== null,
|
||||||
|
'requestorThirdParty' => $this->normalizer->normalize($period->getRequestorThirdParty(), $format, array_merge($context, ['docgen:expects' => ThirdParty::class])),
|
||||||
|
'hasRequestorThirdParty' => $period->getRequestorThirdParty() !== null,
|
||||||
|
'resources' => $this->normalizer->normalize($period->getResources(), $format, $context),
|
||||||
|
'scopes' => $this->normalizer->normalize($scopes, $format, array_merge($context, ['docgen:expects' => Scope::class, 'groups' => 'docgen:read'])),
|
||||||
|
'socialIssues' => $this->normalizer->normalize($period->getSocialIssues(), $format, $context),
|
||||||
'intensity' => $this->translator->trans($period->getIntensity()),
|
'intensity' => $this->translator->trans($period->getIntensity()),
|
||||||
'step' => $this->translator->trans('accompanying_period.' . $period->getStep()),
|
'step' => $this->translator->trans('accompanying_period.' . $period->getStep()),
|
||||||
'emergencyText' => $period->isEmergency() ? $this->translator->trans('accompanying_period.emergency') : '',
|
'emergencyText' => $period->isEmergency() ? $this->translator->trans('accompanying_period.emergency') : '',
|
||||||
'confidentialText' => $period->isConfidential() ? $this->translator->trans('confidential') : '',
|
'confidentialText' => $period->isConfidential() ? $this->translator->trans('confidential') : '',
|
||||||
//'originText' => null !== $period->getOrigin() ? $this->translatableStringHelper->localize($period->getOrigin()->getLabel()) : '',
|
'originText' => null !== $period->getOrigin() ? $this->translatableStringHelper->localize($period->getOrigin()->getLabel()) : '',
|
||||||
|
'isClosed' => $period->getClosingDate() !== null,
|
||||||
'closingMotiveText' => null !== $period->getClosingMotive() ?
|
'closingMotiveText' => null !== $period->getClosingMotive() ?
|
||||||
$this->closingMotiveRender->renderString($period->getClosingMotive(), []) : '',
|
$this->closingMotiveRender->renderString($period->getClosingMotive(), []) : '',
|
||||||
'ref' => $user,
|
'ref' => $this->normalizer->normalize($period->getUser(), $format, $userContext),
|
||||||
|
'hasRef' => $period->getUser() !== null,
|
||||||
'socialIssuesText' => implode(', ', array_map(function (SocialIssue $s) {
|
'socialIssuesText' => implode(', ', array_map(function (SocialIssue $s) {
|
||||||
return $this->socialIssueRender->renderString($s, []);
|
return $this->socialIssueRender->renderString($s, []);
|
||||||
}, $period->getSocialIssues()->toArray())),
|
}, $period->getSocialIssues()->toArray())),
|
||||||
'scopesText' => implode(', ', array_map(function (Scope $s) {
|
'scopesText' => implode(', ', array_map(function (Scope $s) {
|
||||||
return $this->translatableStringHelper->localize($s->getName());
|
return $this->translatableStringHelper->localize($s->getName());
|
||||||
}, $scopes)),
|
}, $scopes)),
|
||||||
'scopes' => $scopes,
|
'hasRequestor' => $period->getRequestor() !== null,
|
||||||
|
'requestorKind' => $period->getRequestorKind(),
|
||||||
|
];
|
||||||
|
} elseif (null === $period) {
|
||||||
|
return array_merge(
|
||||||
|
(new NormalizeNullValueHelper($this->normalizer, 'type', 'accompanying_period'))
|
||||||
|
->normalize(self::PERIOD_NULL, $format, $context),
|
||||||
|
[
|
||||||
|
'hasRef' => false,
|
||||||
|
'requestorKind' => 'none',
|
||||||
|
'hasRequestor' => false,
|
||||||
|
'hasRequestorPerson' => false,
|
||||||
|
'hasRequestorThirdParty' => false,
|
||||||
|
'isClosed' => false,
|
||||||
|
'confidential' => false,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
} elseif (null === $period) {
|
|
||||||
return self::PERIOD_NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidArgumentException('this neither an accompanying period or null');
|
throw new InvalidArgumentException('this neither an accompanying period or null');
|
||||||
@ -143,11 +172,6 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($data instanceof AccompanyingPeriod) {
|
if ($data instanceof AccompanyingPeriod) {
|
||||||
if (array_key_exists(self::IGNORE_FIRST_PASS_KEY, $context)
|
|
||||||
&& in_array(spl_object_hash($data), $context[self::IGNORE_FIRST_PASS_KEY], true)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,16 +12,21 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
||||||
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
use Chill\MainBundle\Entity\Civility;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\PersonAltName;
|
use Chill\PersonBundle\Entity\PersonAltName;
|
||||||
|
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
|
||||||
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
use function array_key_exists;
|
|
||||||
use function array_map;
|
use function array_map;
|
||||||
use function implode;
|
use function implode;
|
||||||
|
|
||||||
@ -33,16 +38,20 @@ class PersonDocGenNormalizer implements
|
|||||||
|
|
||||||
private PersonRender $personRender;
|
private PersonRender $personRender;
|
||||||
|
|
||||||
|
private RelationshipRepository $relationshipRepository;
|
||||||
|
|
||||||
private TranslatableStringHelper $translatableStringHelper;
|
private TranslatableStringHelper $translatableStringHelper;
|
||||||
|
|
||||||
private TranslatorInterface $translator;
|
private TranslatorInterface $translator;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PersonRender $personRender,
|
PersonRender $personRender,
|
||||||
|
RelationshipRepository $relationshipRepository,
|
||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator,
|
||||||
TranslatableStringHelper $translatableStringHelper
|
TranslatableStringHelper $translatableStringHelper
|
||||||
) {
|
) {
|
||||||
$this->personRender = $personRender;
|
$this->personRender = $personRender;
|
||||||
|
$this->relationshipRepository = $relationshipRepository;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->translatableStringHelper = $translatableStringHelper;
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
}
|
}
|
||||||
@ -52,12 +61,20 @@ class PersonDocGenNormalizer implements
|
|||||||
/** @var Person $person */
|
/** @var Person $person */
|
||||||
$dateContext = $context;
|
$dateContext = $context;
|
||||||
$dateContext['docgen:expects'] = DateTimeInterface::class;
|
$dateContext['docgen:expects'] = DateTimeInterface::class;
|
||||||
|
$addressContext = array_merge($context, ['docgen:expects' => Address::class]);
|
||||||
|
|
||||||
if (null === $person) {
|
if (null === $person) {
|
||||||
return $this->normalizeNullValue($format, $context);
|
return $this->normalizeNullValue($format, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
if (!$person instanceof Person) {
|
||||||
|
throw new UnexpectedValueException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'type' => 'person',
|
||||||
|
'isNull' => false,
|
||||||
|
'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expect' => Civility::class])),
|
||||||
'firstname' => $person->getFirstName(),
|
'firstname' => $person->getFirstName(),
|
||||||
'lastname' => $person->getLastName(),
|
'lastname' => $person->getLastName(),
|
||||||
'altNames' => implode(
|
'altNames' => implode(
|
||||||
@ -83,7 +100,34 @@ class PersonDocGenNormalizer implements
|
|||||||
'placeOfBirth' => $person->getPlaceOfBirth(),
|
'placeOfBirth' => $person->getPlaceOfBirth(),
|
||||||
'memo' => $person->getMemo(),
|
'memo' => $person->getMemo(),
|
||||||
'numberOfChildren' => (string) $person->getNumberOfChildren(),
|
'numberOfChildren' => (string) $person->getNumberOfChildren(),
|
||||||
|
'address' => $this->normalizer->normalize($person->getCurrentPersonAddress(), $format, $addressContext),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($context['docgen:person:with-household'] ?? false) {
|
||||||
|
$data['household'] = $this->normalizer->normalize(
|
||||||
|
$person->getCurrentHousehold(),
|
||||||
|
$format,
|
||||||
|
array_merge($context, [
|
||||||
|
'docgen:expects' => Household::class,
|
||||||
|
'docgen:person:with-household' => false,
|
||||||
|
'docgen:person:with-relations' => false,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($context['docgen:person:with-relations'] ?? false) {
|
||||||
|
$data['relations'] = $this->normalizer->normalize(
|
||||||
|
new ArrayCollection($this->relationshipRepository->findByPerson($person)),
|
||||||
|
$format,
|
||||||
|
array_merge($context, [
|
||||||
|
'docgen:person:with-household' => false,
|
||||||
|
'docgen:person:with-relation' => false,
|
||||||
|
'docgen:relationship:counterpart' => $person,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function supportsNormalization($data, ?string $format = null, array $context = [])
|
public function supportsNormalization($data, ?string $format = null, array $context = [])
|
||||||
@ -95,25 +139,37 @@ class PersonDocGenNormalizer implements
|
|||||||
return
|
return
|
||||||
$data instanceof Person
|
$data instanceof Person
|
||||||
|| (
|
|| (
|
||||||
array_key_exists('docgen:expects', $context)
|
null === $data
|
||||||
&& Person::class === $context['docgen:expects']
|
&& Person::class === ($context['docgen:expects'] ?? null)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function normalizeNullValue(string $format, array $context)
|
private function normalizeNullValue(string $format, array $context)
|
||||||
{
|
{
|
||||||
$normalizer = new NormalizeNullValueHelper($this->normalizer);
|
$normalizer = new NormalizeNullValueHelper($this->normalizer, 'type', 'person');
|
||||||
|
|
||||||
$attributes = [
|
$attributes = [
|
||||||
'firstname', 'lastname', 'altNames', 'text',
|
'firstname', 'lastname', 'altNames', 'text',
|
||||||
|
'civility' => Civility::class,
|
||||||
'birthdate' => DateTimeInterface::class,
|
'birthdate' => DateTimeInterface::class,
|
||||||
'deathdate' => DateTimeInterface::class,
|
'deathdate' => DateTimeInterface::class,
|
||||||
'gender', 'maritalStatus',
|
'gender', 'maritalStatus',
|
||||||
'maritalStatusDate' => DateTimeInterface::class,
|
'maritalStatusDate' => DateTimeInterface::class,
|
||||||
'email', 'firstPhoneNumber', 'fixPhoneNumber', 'mobilePhoneNumber', 'nationality',
|
'email', 'firstPhoneNumber', 'fixPhoneNumber', 'mobilePhoneNumber', 'nationality',
|
||||||
'placeOfBirth', 'memo', 'numberOfChildren',
|
'placeOfBirth', 'memo', 'numberOfChildren',
|
||||||
|
'address' => Address::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $normalizer->normalize($attributes, $format, $context);
|
if ($context['docgen:person:with-household'] ?? false) {
|
||||||
|
$attributes['household'] = Household::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $normalizer->normalize($attributes, $format, $context);
|
||||||
|
|
||||||
|
if ($context['docgen:person:with-relations'] ?? false) {
|
||||||
|
$data['relations'] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||||
|
|
||||||
|
class RelationshipDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||||
|
{
|
||||||
|
use NormalizerAwareTrait;
|
||||||
|
|
||||||
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||||
|
|
||||||
|
public function __construct(TranslatableStringHelperInterface $translatableStringHelper)
|
||||||
|
{
|
||||||
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Relationship $relation
|
||||||
|
*/
|
||||||
|
public function normalize($relation, ?string $format = null, array $context = [])
|
||||||
|
{
|
||||||
|
$counterpart = $context['docgen:relationship:counterpart'] ?? null;
|
||||||
|
$contextPerson = array_merge($context, [
|
||||||
|
'docgen:person:with-relations' => false,
|
||||||
|
'docgen:relationship:counterpart' => null,
|
||||||
|
'docgen:expects' => Person::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (null !== $counterpart) {
|
||||||
|
$opposite = $relation->getOpposite($counterpart);
|
||||||
|
} else {
|
||||||
|
$opposite = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $relation) {
|
||||||
|
return [
|
||||||
|
'id' => '',
|
||||||
|
'fromPerson' => $nullPerson = $this->normalizer->normalize(null, $format, $contextPerson),
|
||||||
|
'toPerson' => $nullPerson,
|
||||||
|
'opposite' => $nullPerson,
|
||||||
|
'text' => '',
|
||||||
|
'relationId' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $relation->getId(),
|
||||||
|
'fromPerson' => $this->normalizer->normalize(
|
||||||
|
$relation->getFromPerson(),
|
||||||
|
$format,
|
||||||
|
$contextPerson
|
||||||
|
),
|
||||||
|
'toPerson' => $this->normalizer->normalize(
|
||||||
|
$relation->getToPerson(),
|
||||||
|
$format,
|
||||||
|
$contextPerson
|
||||||
|
),
|
||||||
|
'text' => $relation->getReverse() ?
|
||||||
|
$this->translatableStringHelper->localize($relation->getRelation()->getReverseTitle()) :
|
||||||
|
$this->translatableStringHelper->localize($relation->getRelation()->getTitle()),
|
||||||
|
'opposite' => $this->normalizer->normalize($opposite, $format, $contextPerson),
|
||||||
|
'relationId' => $relation->getRelation()->getId(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsNormalization($data, ?string $format = null, array $context = [])
|
||||||
|
{
|
||||||
|
if ('docgen' !== $format) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data instanceof Relationship || (null === $data
|
||||||
|
&& Relationship::class === ($context['docgen:expects'] ?? null));
|
||||||
|
}
|
||||||
|
}
|
@ -36,8 +36,8 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
'id' => $socialAction->getId(),
|
'id' => $socialAction->getId(),
|
||||||
'type' => 'social_work_social_action',
|
'type' => 'social_work_social_action',
|
||||||
'text' => $this->render->renderString($socialAction, []),
|
'text' => $this->render->renderString($socialAction, []),
|
||||||
'parent' => $this->normalizer->normalize($socialAction->getParent()),
|
'parent' => $this->normalizer->normalize($socialAction->getParent(), $format, $context),
|
||||||
'desactivationDate' => $this->normalizer->normalize($socialAction->getDesactivationDate()),
|
'desactivationDate' => $this->normalizer->normalize($socialAction->getDesactivationDate(), $format, $context),
|
||||||
'title' => $socialAction->getTitle(),
|
'title' => $socialAction->getTitle(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -68,6 +68,8 @@ class AccompanyingPeriodContext implements
|
|||||||
|
|
||||||
public function adminFormReverseTransform(array $data): array
|
public function adminFormReverseTransform(array $data): array
|
||||||
{
|
{
|
||||||
|
dump($data);
|
||||||
|
|
||||||
if (array_key_exists('category', $data)) {
|
if (array_key_exists('category', $data)) {
|
||||||
$data['category'] = [
|
$data['category'] = [
|
||||||
'idInsideBundle' => $data['category']->getIdInsideBundle(),
|
'idInsideBundle' => $data['category']->getIdInsideBundle(),
|
||||||
@ -80,7 +82,7 @@ class AccompanyingPeriodContext implements
|
|||||||
|
|
||||||
public function adminFormTransform(array $data): array
|
public function adminFormTransform(array $data): array
|
||||||
{
|
{
|
||||||
$data = [
|
$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,
|
'person1' => $data['person1'] ?? false,
|
||||||
@ -90,11 +92,11 @@ class AccompanyingPeriodContext implements
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (array_key_exists('category', $data)) {
|
if (array_key_exists('category', $data)) {
|
||||||
$data['category'] = array_key_exists('category', $data) ?
|
$r['category'] = array_key_exists('category', $data) ?
|
||||||
$this->documentCategoryRepository->find($data['category']) : null;
|
$this->documentCategoryRepository->find($data['category']) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildAdminForm(FormBuilderInterface $builder): void
|
public function buildAdminForm(FormBuilderInterface $builder): void
|
||||||
@ -169,11 +171,16 @@ class AccompanyingPeriodContext implements
|
|||||||
$options = $template->getOptions();
|
$options = $template->getOptions();
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$data['course'] = $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
$data['course'] = $this->normalizer->normalize($entity, 'docgen', ['docgen:expects' => AccompanyingPeriod::class, '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', ['docgen:expects' => Person::class]);
|
$data[$k] = $this->normalizer->normalize($contextGenerationData[$k], 'docgen', [
|
||||||
|
'docgen:expects' => Person::class,
|
||||||
|
'groups' => 'docgen:read',
|
||||||
|
'docgen:person:with-household' => true,
|
||||||
|
'docgen:person:with-relations' => true,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +211,7 @@ class AccompanyingPeriodContext implements
|
|||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'Accompanying Period basic';
|
return 'docgen.Accompanying Period basic';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAdminForm(): bool
|
public function hasAdminForm(): bool
|
||||||
@ -231,7 +238,7 @@ class AccompanyingPeriodContext implements
|
|||||||
->setCourse($entity)
|
->setCourse($entity)
|
||||||
->setObject($storedObject);
|
->setObject($storedObject);
|
||||||
|
|
||||||
if (array_key_exists('category', $template->getOptions()['category'])) {
|
if (array_key_exists('category', $template->getOptions())) {
|
||||||
$doc
|
$doc
|
||||||
->setCategory(
|
->setCategory(
|
||||||
$this->documentCategoryRepository->find(
|
$this->documentCategoryRepository->find(
|
||||||
|
@ -102,7 +102,7 @@ class AccompanyingPeriodWorkContext implements
|
|||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'Accompanying period work';
|
return 'docgen.Accompanying period work';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAdminForm(): bool
|
public function hasAdminForm(): bool
|
||||||
|
@ -153,7 +153,7 @@ class AccompanyingPeriodWorkEvaluationContext implements
|
|||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return 'Accompanying period work context';
|
return 'docgen.Accompanying period work context';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAdminForm(): bool
|
public function hasAdminForm(): bool
|
||||||
|
@ -51,6 +51,7 @@ class PersonRender extends AbstractChillEntityRender
|
|||||||
'hLevel' => $options['hLevel'] ?? 3,
|
'hLevel' => $options['hLevel'] ?? 3,
|
||||||
'customButtons' => $options['customButtons'] ?? [],
|
'customButtons' => $options['customButtons'] ?? [],
|
||||||
'customArea' => $options['customArea'] ?? [],
|
'customArea' => $options['customArea'] ?? [],
|
||||||
|
'addDeath' => $options['addDeath'] ?? true,
|
||||||
];
|
];
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -388,7 +388,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
|||||||
|
|
||||||
$this->assertTrue(in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
$this->assertTrue(in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
||||||
|
|
||||||
if ($response->getStatusCode() === 422) {
|
if ($this->client->getResponse()->getStatusCode() === 422) {
|
||||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +522,7 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
|
|||||||
|
|
||||||
$this->assertTrue(in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
$this->assertTrue(in_array($this->client->getResponse()->getStatusCode(), [200, 422], true));
|
||||||
|
|
||||||
if ($response->getStatusCode() === 422) {
|
if ($this->client->getResponse()->getStatusCode() === 422) {
|
||||||
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
$this->markTestSkipped('the next tests should appears only on valid accompanying period');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,19 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNormalizationNullOrNotNullHaveSameKeys()
|
||||||
|
{
|
||||||
|
$period = new AccompanyingPeriod();
|
||||||
|
$notNullData = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
||||||
|
$nullData = $this->normalizer->normalize(null, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
||||||
|
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
array_keys($notNullData),
|
||||||
|
array_keys($nullData),
|
||||||
|
'test that the data returned by null value and an accompanying period have the same keys'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testNormalize()
|
public function testNormalize()
|
||||||
{
|
{
|
||||||
$period = new AccompanyingPeriod();
|
$period = new AccompanyingPeriod();
|
||||||
@ -43,10 +56,14 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
$period->addScope((new Scope())->setName(['fr' => 'scope2']));
|
$period->addScope((new Scope())->setName(['fr' => 'scope2']));
|
||||||
$period->addSocialIssue((new SocialIssue())->setTitle(['fr' => 'issue1']));
|
$period->addSocialIssue((new SocialIssue())->setTitle(['fr' => 'issue1']));
|
||||||
$period->addSocialIssue((new SocialIssue())->setTitle(['fr' => 'issue2']));
|
$period->addSocialIssue((new SocialIssue())->setTitle(['fr' => 'issue2']));
|
||||||
|
$period->addPerson(new Person());
|
||||||
|
$period->addPerson(new Person());
|
||||||
$data = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
$data = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]);
|
||||||
|
|
||||||
$expected = [
|
$expected = [
|
||||||
'id' => null,
|
'id' => null,
|
||||||
|
'type' => 'accompanying_period',
|
||||||
|
'isNull' => false,
|
||||||
'closingDate' => '@ignored',
|
'closingDate' => '@ignored',
|
||||||
'confidential' => true,
|
'confidential' => true,
|
||||||
'confidentialText' => 'confidentiel',
|
'confidentialText' => 'confidentiel',
|
||||||
@ -56,7 +73,9 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
'emergencyText' => 'Urgent',
|
'emergencyText' => 'Urgent',
|
||||||
'openingDate' => '@ignored',
|
'openingDate' => '@ignored',
|
||||||
'originText' => 'origin',
|
'originText' => 'origin',
|
||||||
|
'origin' => '@ignored',
|
||||||
'requestorAnonymous' => false,
|
'requestorAnonymous' => false,
|
||||||
|
'resources' => [],
|
||||||
'socialIssues' => '@ignored',
|
'socialIssues' => '@ignored',
|
||||||
'intensity' => 'ponctuel',
|
'intensity' => 'ponctuel',
|
||||||
'step' => 'Brouillon',
|
'step' => 'Brouillon',
|
||||||
@ -66,10 +85,18 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
'scopesText' => 'scope1, scope2',
|
'scopesText' => 'scope1, scope2',
|
||||||
'ref' => '@ignored',
|
'ref' => '@ignored',
|
||||||
'participations' => '@ignored',
|
'participations' => '@ignored',
|
||||||
|
'currentParticipations' => '@ignored',
|
||||||
|
'isClosed' => false,
|
||||||
|
'hasRef' => false,
|
||||||
|
'hasRequestor' => false,
|
||||||
|
'requestorKind' => 'none',
|
||||||
|
'hasRequestorPerson' => false,
|
||||||
|
'hasRequestorThirdParty' => false,
|
||||||
|
'requestorPerson' => '@ignored',
|
||||||
|
'requestorThirdParty' => '@ignored',
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertIsArray($data);
|
$this->assertIsArray($data);
|
||||||
$this->markTestSkipped('still in specification');
|
|
||||||
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data));
|
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data));
|
||||||
|
|
||||||
foreach ($expected as $key => $item) {
|
foreach ($expected as $key => $item) {
|
||||||
@ -77,8 +104,10 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($item, $data[$key]);
|
$this->assertEquals($item, $data[$key], "test key {$key}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->assertCount(2, $data['participations']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNormalizeNull()
|
public function testNormalizeNull()
|
||||||
@ -87,16 +116,19 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
|
|
||||||
$expected = [
|
$expected = [
|
||||||
'id' => '',
|
'id' => '',
|
||||||
|
'type' => 'accompanying_period',
|
||||||
'closingDate' => '@ignored',
|
'closingDate' => '@ignored',
|
||||||
'confidential' => '',
|
'confidential' => false,
|
||||||
'confidentialText' => '',
|
'confidentialText' => '',
|
||||||
'createdAt' => '@ignored',
|
'createdAt' => '@ignored',
|
||||||
'createdBy' => '@ignored',
|
'createdBy' => '@ignored',
|
||||||
'emergency' => '',
|
'emergency' => false,
|
||||||
'emergencyText' => '',
|
'emergencyText' => '',
|
||||||
'openingDate' => '@ignored',
|
'openingDate' => '@ignored',
|
||||||
'originText' => '',
|
'originText' => '',
|
||||||
'requestorAnonymous' => '',
|
'origin' => '@ignored',
|
||||||
|
'requestorAnonymous' => false,
|
||||||
|
'resources' => [],
|
||||||
'socialIssues' => '@ignored',
|
'socialIssues' => '@ignored',
|
||||||
'intensity' => '',
|
'intensity' => '',
|
||||||
'step' => '',
|
'step' => '',
|
||||||
@ -106,10 +138,19 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
'scopesText' => '',
|
'scopesText' => '',
|
||||||
'ref' => '@ignored',
|
'ref' => '@ignored',
|
||||||
'participations' => '@ignored',
|
'participations' => '@ignored',
|
||||||
|
'currentParticipations' => '@ignored',
|
||||||
|
'isClosed' => false,
|
||||||
|
'hasRef' => false,
|
||||||
|
'hasRequestor' => false,
|
||||||
|
'requestorKind' => 'none',
|
||||||
|
'hasRequestorPerson' => false,
|
||||||
|
'hasRequestorThirdParty' => false,
|
||||||
|
'requestorPerson' => '@ignored',
|
||||||
|
'requestorThirdParty' => '@ignored',
|
||||||
|
'isNull' => true,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertIsArray($data);
|
$this->assertIsArray($data);
|
||||||
$this->markTestSkipped('still in specification');
|
|
||||||
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data));
|
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($data));
|
||||||
|
|
||||||
foreach ($expected as $key => $item) {
|
foreach ($expected as $key => $item) {
|
||||||
@ -117,7 +158,7 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($item, $data[$key]);
|
$this->assertEquals($item, $data[$key], "test the key {$key}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,21 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Serializer\Normalizer;
|
namespace Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
|
use Chill\PersonBundle\Entity\Household\Position;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Entity\Relationships\Relation;
|
||||||
|
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||||
|
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
|
||||||
|
use Chill\PersonBundle\Serializer\Normalizer\PersonDocGenNormalizer;
|
||||||
|
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||||
|
use Prophecy\Argument;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,9 +39,13 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
|||||||
'lastname' => '',
|
'lastname' => '',
|
||||||
'altNames' => '',
|
'altNames' => '',
|
||||||
'text' => '',
|
'text' => '',
|
||||||
|
'isNull' => true,
|
||||||
|
'type' => 'person',
|
||||||
'birthdate' => ['short' => '', 'long' => ''],
|
'birthdate' => ['short' => '', 'long' => ''],
|
||||||
'deathdate' => ['short' => '', 'long' => ''],
|
'deathdate' => ['short' => '', 'long' => ''],
|
||||||
'gender' => '',
|
'gender' => '',
|
||||||
|
'civility' => '@ignored',
|
||||||
|
'address' => '@ignored',
|
||||||
'maritalStatus' => '',
|
'maritalStatus' => '',
|
||||||
'maritalStatusDate' => ['short' => '', 'long' => ''],
|
'maritalStatusDate' => ['short' => '', 'long' => ''],
|
||||||
'email' => '',
|
'email' => '',
|
||||||
@ -69,6 +85,19 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
|||||||
yield [null, self::BLANK, 'normalization for a null person'];
|
yield [null, self::BLANK, 'normalization for a null person'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNormalizationNullOrNotNullHaveSameKeys()
|
||||||
|
{
|
||||||
|
$period = new Person();
|
||||||
|
$notNullData = $this->buildPersonNormalizer()->normalize($period, 'docgen', ['docgen:expects' => Person::class]);
|
||||||
|
$nullData = $this->buildPersonNormalizer()->normalize(null, 'docgen', ['docgen:expects' => Person::class]);
|
||||||
|
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
array_keys($notNullData),
|
||||||
|
array_keys($nullData),
|
||||||
|
'test that the data returned by null value and a Person have the same keys'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider generateData
|
* @dataProvider generateData
|
||||||
*
|
*
|
||||||
@ -77,8 +106,133 @@ final class PersonDocGenNormalizerTest extends KernelTestCase
|
|||||||
*/
|
*/
|
||||||
public function testNormalize(?Person $person, $expected, $msg)
|
public function testNormalize(?Person $person, $expected, $msg)
|
||||||
{
|
{
|
||||||
$normalized = $this->normalizer->normalize($person, 'docgen', ['docgen:expects' => Person::class]);
|
$normalized = $this->normalizer->normalize($person, 'docgen', [
|
||||||
|
'docgen:expects' => Person::class,
|
||||||
|
'groups' => 'docgen:read',
|
||||||
|
]);
|
||||||
|
|
||||||
$this->assertEquals($expected, $normalized, $msg);
|
$this->assertIsArray($normalized);
|
||||||
|
|
||||||
|
foreach ($normalized as $key => $value) {
|
||||||
|
if ('@ignored' === $value) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($value, $normalized[$key]);
|
||||||
|
}
|
||||||
|
$this->assertEqualsCanonicalizing(array_keys($expected), array_keys($normalized), $msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormalizePersonWithHousehold()
|
||||||
|
{
|
||||||
|
$household = new Household();
|
||||||
|
$person = new Person();
|
||||||
|
$person
|
||||||
|
->setFirstName('Renaud')
|
||||||
|
->setLastName('Mégane');
|
||||||
|
$householdMember = new HouseholdMember();
|
||||||
|
$householdMember
|
||||||
|
->setPosition((new Position())->setAllowHolder(true)->setLabel(['fr' => 'position'])
|
||||||
|
->setShareHousehold(true))
|
||||||
|
->setHolder(true);
|
||||||
|
$person->addHouseholdParticipation($householdMember);
|
||||||
|
$household->addMember($householdMember);
|
||||||
|
|
||||||
|
$person = new Person();
|
||||||
|
$person
|
||||||
|
->setFirstName('Citroen')
|
||||||
|
->setLastName('Xsara');
|
||||||
|
$householdMember = new HouseholdMember();
|
||||||
|
$householdMember
|
||||||
|
->setPosition((new Position())->setAllowHolder(true)->setLabel(['fr' => 'position2'])
|
||||||
|
->setShareHousehold(true))
|
||||||
|
->setHolder(false);
|
||||||
|
$person->addHouseholdParticipation($householdMember);
|
||||||
|
$household->addMember($householdMember);
|
||||||
|
|
||||||
|
$actual = $this->normalizer->normalize($person, 'docgen', [
|
||||||
|
'groups' => 'docgen:read',
|
||||||
|
'docgen:expects' => Person::class,
|
||||||
|
'docgen:person:with-household' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertCount(2, $household->getMembers());
|
||||||
|
$this->assertIsArray($actual);
|
||||||
|
$this->assertArrayHasKey('household', $actual);
|
||||||
|
$this->assertCount(2, $actual['household']['currentMembers']);
|
||||||
|
$this->assertCount(2, $actual['household']['members']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormalizePersonWithRelationships()
|
||||||
|
{
|
||||||
|
$person = (new Person())->setFirstName('Renaud')->setLastName('megane');
|
||||||
|
$father = (new Person())->setFirstName('Clément')->setLastName('megane');
|
||||||
|
$mother = (new Person())->setFirstName('Mireille')->setLastName('Mathieu');
|
||||||
|
$sister = (new Person())->setFirstName('Callie')->setLastName('megane');
|
||||||
|
|
||||||
|
$relations = [
|
||||||
|
(new Relationship())->setFromPerson($person)->setToPerson($father)
|
||||||
|
->setReverse(false)->setRelation((new Relation())->setTitle(['fr' => 'Père'])
|
||||||
|
->setReverseTitle(['fr' => 'Fils'])),
|
||||||
|
(new Relationship())->setFromPerson($person)->setToPerson($mother)
|
||||||
|
->setReverse(false)->setRelation((new Relation())->setTitle(['fr' => 'Mère'])
|
||||||
|
->setReverseTitle(['fr' => 'Fils'])),
|
||||||
|
(new Relationship())->setFromPerson($person)->setToPerson($sister)
|
||||||
|
->setReverse(true)->setRelation((new Relation())->setTitle(['fr' => 'Frère'])
|
||||||
|
->setReverseTitle(['fr' => 'Soeur'])),
|
||||||
|
];
|
||||||
|
|
||||||
|
$repository = $this->prophesize(RelationshipRepository::class);
|
||||||
|
$repository->findByPerson($person)->willReturn($relations);
|
||||||
|
|
||||||
|
$normalizer = $this->buildPersonNormalizer(null, $repository->reveal(), null, null);
|
||||||
|
|
||||||
|
$actual = $normalizer->normalize($person, 'docgen', [
|
||||||
|
'groups' => 'docgen:read',
|
||||||
|
'docgen:expects' => Person::class,
|
||||||
|
'docgen:person:with-relations' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertIsArray($actual);
|
||||||
|
$this->assertArrayHasKey('relations', $actual);
|
||||||
|
$this->assertCount(3, $actual['relations']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildPersonNormalizer(
|
||||||
|
?PersonRender $personRender = null,
|
||||||
|
?RelationshipRepository $relationshipRepository = null,
|
||||||
|
?TranslatorInterface $translator = null,
|
||||||
|
?TranslatableStringHelper $translatableStringHelper = null
|
||||||
|
): PersonDocGenNormalizer {
|
||||||
|
$normalizer = new PersonDocGenNormalizer(
|
||||||
|
$personRender ?? self::$container->get(PersonRender::class),
|
||||||
|
$relationshipRepository ?? self::$container->get(RelationshipRepository::class),
|
||||||
|
$translator ?? self::$container->get(TranslatorInterface::class),
|
||||||
|
$translatableStringHelper ?? self::$container->get(TranslatableStringHelperInterface::class)
|
||||||
|
);
|
||||||
|
$normalizerManager = $this->prophesize(NormalizerInterface::class);
|
||||||
|
$normalizerManager->supportsNormalization(Argument::any(), 'docgen', Argument::any())->willReturn(true);
|
||||||
|
$normalizerManager->normalize(Argument::type(Person::class), 'docgen', Argument::any())
|
||||||
|
->will(static function ($args) use ($normalizer) {
|
||||||
|
return $normalizer->normalize($args[0], $args[1], $args[2]);
|
||||||
|
});
|
||||||
|
$normalizerManager->normalize(Argument::any(), 'docgen', Argument::any())->will(
|
||||||
|
static function ($args) {
|
||||||
|
if (is_iterable($args[0])) {
|
||||||
|
$r = [];
|
||||||
|
|
||||||
|
foreach ($args[0] as $i) {
|
||||||
|
$r[] = ['fake' => true, 'hash' => spl_object_hash($i)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['fake' => true, 'hash' => null !== $args[0] ? spl_object_hash($args[0]) : null];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$normalizer->setNormalizer($normalizerManager->reveal());
|
||||||
|
|
||||||
|
return $normalizer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Entity\Relationships\Relation;
|
||||||
|
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||||
|
use Chill\PersonBundle\Serializer\Normalizer\RelationshipDocGenNormalizer;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
|
use function is_object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
final class RelationshipDocGenNormalizerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testNormalizeRelationshipNull()
|
||||||
|
{
|
||||||
|
$relationship = null;
|
||||||
|
|
||||||
|
$normalizer = $this->buildNormalizer();
|
||||||
|
|
||||||
|
$this->assertTrue($normalizer->supportsNormalization($relationship, 'docgen', [
|
||||||
|
'docgen:expects' => Relationship::class,
|
||||||
|
]));
|
||||||
|
$this->assertFalse($normalizer->supportsNormalization($relationship, 'docgen', [
|
||||||
|
'docgen:expects' => Person::class,
|
||||||
|
]));
|
||||||
|
|
||||||
|
$actual = $normalizer->normalize($relationship, 'docgen', [
|
||||||
|
'docgen:expects' => Relationship::class,
|
||||||
|
]);
|
||||||
|
$this->assertIsArray($actual);
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
['fromPerson', 'toPerson', 'id', 'relationId', 'text', 'opposite'],
|
||||||
|
array_keys($actual),
|
||||||
|
'check that the expected keys are present'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormalizeRelationshipWithCounterPart()
|
||||||
|
{
|
||||||
|
$relationship = new Relationship();
|
||||||
|
$relationship
|
||||||
|
->setFromPerson($person1 = new Person())
|
||||||
|
->setToPerson($person2 = new Person())
|
||||||
|
->setRelation(
|
||||||
|
(new Relation())->setTitle(['fr' => 'title'])
|
||||||
|
->setReverseTitle(['fr' => 'reverse title'])
|
||||||
|
)
|
||||||
|
->setReverse(false);
|
||||||
|
|
||||||
|
$normalizer = $this->buildNormalizer();
|
||||||
|
|
||||||
|
$this->assertTrue($normalizer->supportsNormalization($relationship, 'docgen', []));
|
||||||
|
$this->assertFalse($normalizer->supportsNormalization($person1, 'docgen', []));
|
||||||
|
|
||||||
|
$actual = $normalizer->normalize($relationship, 'docgen', [
|
||||||
|
'docgen:expects' => Relationship::class,
|
||||||
|
'docgen:relationship:counterpart' => $person1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertIsArray($actual);
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
['fromPerson', 'toPerson', 'id', 'relationId', 'text', 'opposite'],
|
||||||
|
array_keys($actual),
|
||||||
|
'check that the expected keys are present'
|
||||||
|
);
|
||||||
|
$this->assertEquals(spl_object_hash($person2), $actual['opposite']['hash']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormalizeRelationshipWithoutCounterPart()
|
||||||
|
{
|
||||||
|
$relationship = new Relationship();
|
||||||
|
$relationship
|
||||||
|
->setFromPerson($person1 = new Person())
|
||||||
|
->setToPerson($person2 = new Person())
|
||||||
|
->setRelation(
|
||||||
|
(new Relation())->setTitle(['fr' => 'title'])
|
||||||
|
->setReverseTitle(['fr' => 'reverse title'])
|
||||||
|
)
|
||||||
|
->setReverse(false);
|
||||||
|
|
||||||
|
$normalizer = $this->buildNormalizer();
|
||||||
|
|
||||||
|
$this->assertTrue($normalizer->supportsNormalization($relationship, 'docgen', []));
|
||||||
|
$this->assertFalse($normalizer->supportsNormalization($person1, 'docgen', []));
|
||||||
|
|
||||||
|
$actual = $normalizer->normalize($relationship, 'docgen', [
|
||||||
|
'docgen:expects' => Relationship::class,
|
||||||
|
]);
|
||||||
|
$this->assertIsArray($actual);
|
||||||
|
$this->assertEqualsCanonicalizing(
|
||||||
|
['fromPerson', 'toPerson', 'id', 'relationId', 'text', 'opposite'],
|
||||||
|
array_keys($actual),
|
||||||
|
'check that the expected keys are present'
|
||||||
|
);
|
||||||
|
$this->assertEquals(null, $actual['opposite']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildNormalizer(): RelationshipDocGenNormalizer
|
||||||
|
{
|
||||||
|
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
|
||||||
|
$translatableStringHelper->localize(Argument::type('array'))->will(
|
||||||
|
static function ($args) { return $args[0][array_keys($args[0])[0]]; }
|
||||||
|
);
|
||||||
|
|
||||||
|
$normalizer = new RelationshipDocGenNormalizer(
|
||||||
|
$translatableStringHelper->reveal()
|
||||||
|
);
|
||||||
|
|
||||||
|
$normalizerManager = $this->prophesize(NormalizerInterface::class);
|
||||||
|
$normalizerManager->supportsNormalization(Argument::any(), 'docgen', Argument::any())->willReturn(true);
|
||||||
|
$normalizerManager->normalize(Argument::type(Relationship::class), 'docgen', Argument::any())
|
||||||
|
->will(static function ($args) use ($normalizer) {
|
||||||
|
return $normalizer->normalize($args[0], $args[1], $args[2]);
|
||||||
|
});
|
||||||
|
$normalizerManager->normalize(Argument::any(), 'docgen', Argument::any())->will(
|
||||||
|
static function ($args) {
|
||||||
|
if (null === $args[0]) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_iterable($args[0])) {
|
||||||
|
$r = [];
|
||||||
|
|
||||||
|
foreach ($args[0] as $i) {
|
||||||
|
$r[] = ['fake' => true, 'hash' => spl_object_hash($i)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_object($args[0])) {
|
||||||
|
return ['fake' => true, 'hash' => null !== $args[0] ? spl_object_hash($args[0]) : null];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $args[0];
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$normalizer->setNormalizer($normalizerManager->reveal());
|
||||||
|
|
||||||
|
return $normalizer;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
accompanying_period_social_issue_consistency_with_action:
|
||||||
|
class: 'Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodSocialIssueConsistencyEntityListener'
|
||||||
|
tags:
|
||||||
|
-
|
||||||
|
name: 'doctrine.orm.entity_listener'
|
||||||
|
event: 'prePersist'
|
||||||
|
entity: 'Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork'
|
||||||
|
lazy: true
|
||||||
|
-
|
||||||
|
name: 'doctrine.orm.entity_listener'
|
||||||
|
event: 'preUpdate'
|
||||||
|
entity: 'Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork'
|
||||||
|
lazy: true
|
@ -19,6 +19,7 @@ person:
|
|||||||
woman {et elle-même}
|
woman {et elle-même}
|
||||||
other {et lui·elle-même}
|
other {et lui·elle-même}
|
||||||
}
|
}
|
||||||
|
from_the: depuis le
|
||||||
|
|
||||||
household:
|
household:
|
||||||
Household: Ménage
|
Household: Ménage
|
||||||
|
@ -124,8 +124,8 @@ address_country_code: Code pays
|
|||||||
|
|
||||||
'Alreay existing person': 'Dossiers déjà encodés'
|
'Alreay existing person': 'Dossiers déjà encodés'
|
||||||
'Add the person': 'Ajouter la personne'
|
'Add the person': 'Ajouter la personne'
|
||||||
'Add the person and create an accompanying period': "Créer la personne ET créer une période d'accompagnement"
|
'Add the person and create an accompanying period': "Créer la personne & créer une période d'accompagnement"
|
||||||
'Add the person and create an household': "Créer la personne ET créer un ménage"
|
'Add the person and create an household': "Créer la personne & créer un ménage"
|
||||||
Show person: Voir le dossier de la personne
|
Show person: Voir le dossier de la personne
|
||||||
'Confirm the creation': 'Confirmer la création'
|
'Confirm the creation': 'Confirmer la création'
|
||||||
'You will create this person': 'Vous allez créer le dossier suivant'
|
'You will create this person': 'Vous allez créer le dossier suivant'
|
||||||
@ -455,13 +455,15 @@ see social issues: Voir les problématiques sociales
|
|||||||
see persons associated: Voir les usagers concernés
|
see persons associated: Voir les usagers concernés
|
||||||
|
|
||||||
docgen:
|
docgen:
|
||||||
|
Accompanying Period basic: "Parcours d'accompagnement (basique)"
|
||||||
|
Accompanying period work: "Action d'accompagnement"
|
||||||
|
Accompanying period work context: "Evaluation des actions d'accompagnement"
|
||||||
Main person: Personne principale
|
Main person: Personne principale
|
||||||
person 1: Première personne
|
person 1: Première personne
|
||||||
person 2: Seconde personne
|
person 2: Seconde personne
|
||||||
Ask for main person: Demander à l'utilisateur de préciser la personne principale
|
Ask for main person: Demander à l'utilisateur de préciser la personne principale
|
||||||
Ask for person 1: Demander à l'utilisateur de préciser la première personne
|
Ask for person 1: Demander à l'utilisateur de préciser la première personne
|
||||||
Ask for person 2: Demander à l'utilisateur de préciser la seconde personne
|
Ask for person 2: Demander à l'utilisateur de préciser la seconde personne
|
||||||
Accompanying period work: Actions
|
|
||||||
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
|
||||||
|
@ -63,7 +63,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @var string
|
* @var string
|
||||||
* @ORM\Column(name="acronym", type="string", length=64, nullable=true)
|
* @ORM\Column(name="acronym", type="string", length=64, nullable=true)
|
||||||
* @Assert\Length(min="2")
|
* @Assert\Length(min="2")
|
||||||
* @Groups({"read", "write"})
|
* @Groups({"read", "write", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?string $acronym = '';
|
private ?string $acronym = '';
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
|
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
|
||||||
* cascade={"persist", "remove"})
|
* cascade={"persist", "remove"})
|
||||||
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
|
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
|
||||||
* @Groups({"read", "write"})
|
* @Groups({"read", "write", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?Address $address = null;
|
private ?Address $address = null;
|
||||||
|
|
||||||
@ -97,6 +97,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @ORM\JoinTable(name="chill_3party.thirdparty_category",
|
* @ORM\JoinTable(name="chill_3party.thirdparty_category",
|
||||||
* joinColumns={@ORM\JoinColumn(name="thirdparty_id", referencedColumnName="id")},
|
* joinColumns={@ORM\JoinColumn(name="thirdparty_id", referencedColumnName="id")},
|
||||||
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")})
|
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")})
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private Collection $categories;
|
private Collection $categories;
|
||||||
|
|
||||||
@ -121,6 +122,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @var Civility
|
* @var Civility
|
||||||
* @ORM\ManyToOne(targetEntity=Civility::class)
|
* @ORM\ManyToOne(targetEntity=Civility::class)
|
||||||
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
|
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
|
||||||
|
* @Groups({"docgen:read", "read"})
|
||||||
*/
|
*/
|
||||||
private ?Civility $civility = null;
|
private ?Civility $civility = null;
|
||||||
|
|
||||||
@ -132,7 +134,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(name="contact_data_anonymous", type="boolean", options={"default": false})
|
* @ORM\Column(name="contact_data_anonymous", type="boolean", options={"default": false})
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private bool $contactDataAnonymous = false;
|
private bool $contactDataAnonymous = false;
|
||||||
|
|
||||||
@ -150,7 +152,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
/**
|
/**
|
||||||
* @ORM\Column(name="email", type="string", length=255, nullable=true)
|
* @ORM\Column(name="email", type="string", length=255, nullable=true)
|
||||||
* @Assert\Email(checkMX=false)
|
* @Assert\Email(checkMX=false)
|
||||||
* @Groups({"read", "write"})
|
* @Groups({"read", "write", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
@ -159,6 +161,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @ORM\Column(name="id", type="integer")
|
* @ORM\Column(name="id", type="integer")
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue(strategy="AUTO")
|
* @ORM\GeneratedValue(strategy="AUTO")
|
||||||
|
* @Groups({"read", "write", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
@ -172,7 +175,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @var string
|
* @var string
|
||||||
* @ORM\Column(name="name", type="string", length=255)
|
* @ORM\Column(name="name", type="string", length=255)
|
||||||
* @Assert\Length(min="2")
|
* @Assert\Length(min="2")
|
||||||
* @Groups({"read", "write"})
|
* @Groups({"read", "write", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?string $name = '';
|
private ?string $name = '';
|
||||||
|
|
||||||
@ -182,7 +185,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @var string
|
* @var string
|
||||||
* @ORM\Column(name="name_company", type="string", length=255, nullable=true)
|
* @ORM\Column(name="name_company", type="string", length=255, nullable=true)
|
||||||
* @Assert\Length(min="3")
|
* @Assert\Length(min="3")
|
||||||
* @Groups({"read", "write"})
|
* @Groups({"read", "write", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?string $nameCompany = '';
|
private ?string $nameCompany = '';
|
||||||
|
|
||||||
@ -201,6 +204,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* @var ThirdPartyProfession
|
* @var ThirdPartyProfession
|
||||||
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
|
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
|
||||||
* ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
|
* ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
|
||||||
|
* @Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private ?ThirdPartyProfession $profession = null;
|
private ?ThirdPartyProfession $profession = null;
|
||||||
|
|
||||||
@ -210,7 +214,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
* message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789"
|
* message="Invalid phone number: it should begin with the international prefix starting with ""+"", hold only digits and be smaller than 20 characters. Ex: +33123456789"
|
||||||
* )
|
* )
|
||||||
* @PhonenumberConstraint(type="any")
|
* @PhonenumberConstraint(type="any")
|
||||||
* @Groups({"read", "write"})
|
* @Groups({"read", "write", "dogen:read"})
|
||||||
*/
|
*/
|
||||||
private ?string $telephone = null;
|
private ?string $telephone = null;
|
||||||
|
|
||||||
@ -496,7 +500,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Groups({"read"})
|
* @Groups({"read", "docgen:read"})
|
||||||
*/
|
*/
|
||||||
public function isChild(): bool
|
public function isChild(): bool
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\ThirdPartyBundle\Entity;
|
|||||||
|
|
||||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyCategoryRepository;
|
use Chill\ThirdPartyBundle\Repository\ThirdPartyCategoryRepository;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Table(name="chill_3party.party_category")
|
* @ORM\Table(name="chill_3party.party_category")
|
||||||
@ -23,19 +24,21 @@ class ThirdPartyCategory
|
|||||||
/**
|
/**
|
||||||
* @ORM\Column(type="boolean")
|
* @ORM\Column(type="boolean")
|
||||||
*/
|
*/
|
||||||
private $active = true;
|
private bool $active = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $name = [];
|
private array $name = [];
|
||||||
|
|
||||||
public function getActive(): ?bool
|
public function getActive(): ?bool
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\ThirdPartyBundle\Entity;
|
|||||||
|
|
||||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyProfessionRepository;
|
use Chill\ThirdPartyBundle\Repository\ThirdPartyProfessionRepository;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Table(name="chill_3party.party_profession")
|
* @ORM\Table(name="chill_3party.party_profession")
|
||||||
@ -23,19 +24,21 @@ class ThirdPartyProfession
|
|||||||
/**
|
/**
|
||||||
* @ORM\Column(type="boolean")
|
* @ORM\Column(type="boolean")
|
||||||
*/
|
*/
|
||||||
private $active = true;
|
private bool $active = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Id
|
* @ORM\Id
|
||||||
* @ORM\GeneratedValue
|
* @ORM\GeneratedValue
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $id;
|
private ?int $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="json")
|
* @ORM\Column(type="json")
|
||||||
|
* @Serializer\Groups({"docgen:read"})
|
||||||
*/
|
*/
|
||||||
private $name = [];
|
private array $name = [];
|
||||||
|
|
||||||
public function getActive(): ?bool
|
public function getActive(): ?bool
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,6 @@ class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterf
|
|||||||
|
|
||||||
public function supportsNormalization($data, ?string $format = null)
|
public function supportsNormalization($data, ?string $format = null)
|
||||||
{
|
{
|
||||||
return $data instanceof ThirdParty;
|
return $data instanceof ThirdParty && 'json' === $format;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\ThirdPartyBundle\Test\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Civility;
|
||||||
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
|
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @coversNothing
|
||||||
|
*/
|
||||||
|
final class ThirdpartyDocGenNormalizerTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
private NormalizerInterface $normalizer;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
$this->normalizer = self::$container->get(NormalizerInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNormalize()
|
||||||
|
{
|
||||||
|
$thirdparty = new ThirdParty();
|
||||||
|
$thirdparty
|
||||||
|
->setAcronym('ABCD')
|
||||||
|
->setName('test')
|
||||||
|
->setCivility((new Civility())->setName(['fr' => 'Monsieur'])->setAbbreviation(['fr' => 'M.']))
|
||||||
|
->setEmail('info@cl.coop')
|
||||||
|
->addTypesAndCategories('kind')
|
||||||
|
->addTypesAndCategories((new ThirdPartyCategory())->setName(['fr' => 'category']));
|
||||||
|
|
||||||
|
$actual = $this->normalizer->normalize($thirdparty, 'docgen', ['groups' => ['docgen:read']]);
|
||||||
|
|
||||||
|
var_dump($actual);
|
||||||
|
|
||||||
|
$this->assertIsArray($actual);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user