mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
various improvements
This commit is contained in:
@@ -15,7 +15,6 @@ use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\MainBundle\Serializer\Normalizer\CollectionNormalizer;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@@ -23,15 +22,17 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use function count;
|
||||
use function in_array;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationApiController
|
||||
{
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
public function __construct(
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
SerializerInterface $serializer,
|
||||
@@ -44,21 +45,22 @@ class AccompanyingPeriodWorkEvaluationApiController
|
||||
|
||||
/**
|
||||
* @Route("/api/1.0/person/docgen/template/by-evaluation/{id}.{_format}",
|
||||
* requirements={"format": "json"})
|
||||
* requirements={"format": "json"})
|
||||
*/
|
||||
public function listTemplateByEvaluation(Evaluation $evaluation, string $_format): JsonResponse
|
||||
{
|
||||
if ('json' !== $_format) {
|
||||
throw new BadRequestHttpException("format not supported");
|
||||
throw new BadRequestHttpException('format not supported');
|
||||
}
|
||||
|
||||
$evaluations =
|
||||
array_filter(
|
||||
$this->docGeneratorTemplateRepository
|
||||
->findByEntity(AccompanyingPeriodWorkEvaluation::class),
|
||||
function (DocGeneratorTemplate $t) use ($evaluation) {
|
||||
static function (DocGeneratorTemplate $t) use ($evaluation) {
|
||||
$ids = $t->getOptions()['evaluations'] ?? [];
|
||||
return in_array($evaluation->getId(), $ids);
|
||||
|
||||
return in_array($evaluation->getId(), $ids, true);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -66,8 +68,10 @@ class AccompanyingPeriodWorkEvaluationApiController
|
||||
$paginator->setItemsPerPage(count($evaluations));
|
||||
|
||||
return new JsonResponse($this->serializer->serialize(
|
||||
new Collection($evaluations, $paginator), 'json', [
|
||||
AbstractNormalizer::GROUPS => ['read']
|
||||
new Collection($evaluations, $paginator),
|
||||
'json',
|
||||
[
|
||||
AbstractNormalizer::GROUPS => ['read'],
|
||||
]
|
||||
), JsonResponse::HTTP_OK, [], true);
|
||||
}
|
||||
|
@@ -239,11 +239,6 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
|
||||
return $this->updatedBy;
|
||||
}
|
||||
|
||||
public function getWarningInterval(): ?DateInterval
|
||||
{
|
||||
return $this->warningInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Serializer\Groups({"docgen:read"})
|
||||
*/
|
||||
@@ -256,6 +251,11 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
|
||||
return $this->getEndDate()->sub($this->getWarningInterval());
|
||||
}
|
||||
|
||||
public function getWarningInterval(): ?DateInterval
|
||||
{
|
||||
return $this->warningInterval;
|
||||
}
|
||||
|
||||
public function removeDocument(AccompanyingPeriodWorkEvaluationDocument $document): self
|
||||
{
|
||||
$this->documents->removeElement($document);
|
||||
|
@@ -28,7 +28,7 @@ class Evaluation
|
||||
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private ?\DateInterval $delay = null;
|
||||
private ?DateInterval $delay = null;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
@@ -42,7 +42,7 @@ class Evaluation
|
||||
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private ?\DateInterval $notificationDelay = null;
|
||||
private ?DateInterval $notificationDelay = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(
|
||||
|
@@ -195,15 +195,17 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<pick-template
|
||||
entityClass="Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork"
|
||||
:templates="this.templatesAvailablesForAction"
|
||||
:entityId="work.id"
|
||||
:beforeMove="beforeGenerateTemplate">
|
||||
<template v-slot:title>
|
||||
<h3>{{ $t('Generate doc') }}</h3>
|
||||
</template>
|
||||
</pick-template>
|
||||
<div>
|
||||
<pick-template
|
||||
entityClass="Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork"
|
||||
:templates="this.templatesAvailablesForAction"
|
||||
:entityId="work.id"
|
||||
:beforeMove="beforeGenerateTemplate">
|
||||
<template v-slot:title>
|
||||
<h3>{{ $t('Generate doc') }}</h3>
|
||||
</template>
|
||||
</pick-template>
|
||||
</div>
|
||||
|
||||
<div v-if="errors.length > 0" id="errors" class="alert alert-danger flashbag">
|
||||
<p>{{ $t('fix_these_errors') }}</p>
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Service\DocGenerator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
|
||||
@@ -29,8 +28,10 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_key_exists;
|
||||
|
||||
class AccompanyingPeriodContext implements
|
||||
@@ -47,28 +48,26 @@ class AccompanyingPeriodContext implements
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
DocumentCategoryRepository $documentCategoryRepository,
|
||||
NormalizerInterface $normalizer,
|
||||
TranslatableStringHelperInterface $translatableStringHelper,
|
||||
EntityManagerInterface $em,
|
||||
PersonRender $personRender
|
||||
PersonRender $personRender,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->documentCategoryRepository = $documentCategoryRepository;
|
||||
$this->normalizer = $normalizer;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->em = $em;
|
||||
$this->personRender = $personRender;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function adminFormReverseTransform(array $data): array
|
||||
{
|
||||
$data = [
|
||||
'mainPerson' => $data['mainPerson'],
|
||||
'person1' => $data['person1'],
|
||||
'person2' => $data['person2'],
|
||||
];
|
||||
|
||||
if (array_key_exists('category', $data)) {
|
||||
$data['category'] = [
|
||||
'idInsideBundle' => $data['category']->getIdInsideBundle(),
|
||||
@@ -83,8 +82,11 @@ class AccompanyingPeriodContext implements
|
||||
{
|
||||
$data = [
|
||||
'mainPerson' => $data['mainPerson'] ?? false,
|
||||
'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
|
||||
'person1' => $data['person1'] ?? false,
|
||||
'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'),
|
||||
'person2' => $data['person2'] ?? false,
|
||||
'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
|
||||
];
|
||||
|
||||
if (array_key_exists('category', $data)) {
|
||||
@@ -100,12 +102,27 @@ class AccompanyingPeriodContext implements
|
||||
$builder
|
||||
->add('mainPerson', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Ask for main person',
|
||||
])
|
||||
->add('mainPersonLabel', TextType::class, [
|
||||
'label' => 'main person label',
|
||||
'required' => true,
|
||||
])
|
||||
->add('person1', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Ask for person 1'
|
||||
])
|
||||
->add('person1Label', TextType::class, [
|
||||
'label' => 'person 1 label',
|
||||
'required' => true,
|
||||
])
|
||||
->add('person2', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Ask for person 2'
|
||||
])
|
||||
->add('person2Label', TextType::class, [
|
||||
'label' => 'person 2 label',
|
||||
'required' => true,
|
||||
])
|
||||
->add('category', EntityType::class, [
|
||||
'placeholder' => 'Choose a document category',
|
||||
@@ -138,6 +155,7 @@ class AccompanyingPeriodContext implements
|
||||
'choice_label' => function (Person $p) { return $this->personRender->renderString($p, []); },
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'label' => $options[$key.'Label'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -175,7 +193,7 @@ class AccompanyingPeriodContext implements
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array
|
||||
{
|
||||
return [
|
||||
'course' => $entity
|
||||
'course' => $entity,
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -51,6 +51,8 @@ class AccompanyingPeriodWorkContext implements
|
||||
public function buildAdminForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
$this->periodContext->buildAdminForm($builder);
|
||||
|
||||
$builder->remove('category');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -100,7 +100,6 @@ class AccompanyingPeriodWorkEvaluationContext implements
|
||||
|
||||
/**
|
||||
* @param AccompanyingPeriodWorkEvaluation $entity
|
||||
* @return void
|
||||
*/
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||
{
|
||||
@@ -141,8 +140,10 @@ class AccompanyingPeriodWorkEvaluationContext implements
|
||||
*/
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array
|
||||
{
|
||||
return $this->accompanyingPeriodWorkContext->getFormData($template,
|
||||
$entity->getAccompanyingPeriodWork());
|
||||
return $this->accompanyingPeriodWorkContext->getFormData(
|
||||
$template,
|
||||
$entity->getAccompanyingPeriodWork()
|
||||
);
|
||||
}
|
||||
|
||||
public static function getKey(): string
|
||||
|
@@ -448,3 +448,8 @@ Household addresses: Adresses de domicile
|
||||
Insert an address: Insérer une adresse
|
||||
see social issues: Voir les problématiques sociales
|
||||
see persons associated: Voir les usagers concernés
|
||||
|
||||
docgen:
|
||||
Main person: Personne principale
|
||||
person 1: Première personne
|
||||
person 2: Deuxième personne
|
||||
|
Reference in New Issue
Block a user