Merge remote-tracking branch 'origin/master' into 103-document-page

This commit is contained in:
2023-06-13 15:14:17 +02:00
30 changed files with 1695 additions and 101 deletions

View File

@@ -22,10 +22,14 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Repository\DocumentCategoryRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
@@ -40,6 +44,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
/**
* @see AccompanyingPeriodContextTest
* @template-implements DocGeneratorContextWithPublicFormInterface<AccompanyingPeriod>
*/
class AccompanyingPeriodContext implements
@@ -62,6 +67,10 @@ class AccompanyingPeriodContext implements
private TranslatorInterface $translator;
private ThirdPartyRender $thirdPartyRender;
private ThirdPartyRepository $thirdPartyRepository;
public function __construct(
DocumentCategoryRepository $documentCategoryRepository,
NormalizerInterface $normalizer,
@@ -70,7 +79,9 @@ class AccompanyingPeriodContext implements
PersonRenderInterface $personRender,
PersonRepository $personRepository,
TranslatorInterface $translator,
BaseContextData $baseContextData
BaseContextData $baseContextData,
ThirdPartyRender $thirdPartyRender,
ThirdPartyRepository $thirdPartyRepository
) {
$this->documentCategoryRepository = $documentCategoryRepository;
$this->normalizer = $normalizer;
@@ -80,6 +91,8 @@ class AccompanyingPeriodContext implements
$this->personRepository = $personRepository;
$this->translator = $translator;
$this->baseContextData = $baseContextData;
$this->thirdPartyRender = $thirdPartyRender;
$this->thirdPartyRepository = $thirdPartyRepository;
}
public function adminFormReverseTransform(array $data): array
@@ -103,11 +116,12 @@ class AccompanyingPeriodContext implements
'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'),
'person2' => $data['person2'] ?? false,
'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
'thirdParty' => $data['thirdParty'] ?? false,
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('Third party'),
];
if (array_key_exists('category', $data)) {
$r['category'] = array_key_exists('category', $data) ?
$this->documentCategoryRepository->find($data['category']) : null;
$r['category'] = $this->documentCategoryRepository->find($data['category']);
}
return $r;
@@ -140,6 +154,14 @@ class AccompanyingPeriodContext implements
'label' => 'person 2 label',
'required' => true,
])
->add('thirdParty', CheckboxType::class, [
'required' => false,
'label' => 'docgen.Ask for thirdParty',
])
->add('thirdPartyLabel', TextType::class, [
'label' => 'docgen.thirdParty label',
'required' => true,
])
->add('category', EntityType::class, [
'placeholder' => 'Choose a document category',
'class' => DocumentCategory::class,
@@ -190,6 +212,28 @@ class AccompanyingPeriodContext implements
]);
}
}
$thirdParties = [...array_values(array_filter([$entity->getRequestorThirdParty()])), ...array_values(array_filter(
array_map(
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getResources()->filter(
static fn (Resource $r): bool => null !== $r->getThirdParty()
)->toArray()
)
))];
if ($options['thirdParty'] ?? false) {
$builder->add('thirdParty', EntityType::class, [
'class' => ThirdParty::class,
'choices' => $thirdParties,
'choice_label' => fn (ThirdParty $p) => $this->thirdPartyRender->renderString($p, []),
'multiple' => false,
'required' => false,
'expanded' => true,
'label' => $options['thirdPartyLabel'],
'placeholder' => $this->translator->trans('Any third party selected'),
]);
}
}
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
@@ -215,6 +259,13 @@ class AccompanyingPeriodContext implements
}
}
if ($options['thirdParty']) {
$data['thirdParty'] = $this->normalizer->normalize($contextGenerationData['thirdParty'], 'docgen', [
'docgen:expects' => ThirdParty::class,
'groups' => 'docgen:read'
]);
}
return $data;
}
@@ -254,7 +305,7 @@ class AccompanyingPeriodContext implements
{
$options = $template->getOptions();
return $options['mainPerson'] || $options['person1'] || $options['person2'];
return $options['mainPerson'] || $options['person1'] || $options['person2'] || $options ['thirdParty'];
}
public function contextGenerationDataNormalize(DocGeneratorTemplate $template, $entity, array $data): array
@@ -264,6 +315,8 @@ class AccompanyingPeriodContext implements
$normalized[$k] = null !== ($data[$k] ?? null) ? $data[$k]->getId() : null;
}
$normalized['thirdParty'] = ($data['thirdParty'] ?? null)?->getId();
return $normalized;
}
@@ -279,6 +332,12 @@ class AccompanyingPeriodContext implements
}
}
if (null !== ($id = ($data['thirdParty'] ?? null))) {
$denormalized['thirdParty'] = $this->thirdPartyRepository->find($id);
} else {
$denormalized['thirdParty'] = null;
}
return $denormalized;
}

View File

@@ -18,13 +18,18 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @implements DocGeneratorContextWithPublicFormInterface<AccompanyingPeriodWorkEvaluation>
@@ -43,18 +48,26 @@ class AccompanyingPeriodWorkEvaluationContext implements
private TranslatableStringHelperInterface $translatableStringHelper;
private ThirdPartyRender $thirdPartyRender;
private TranslatorInterface $translator;
public function __construct(
AccompanyingPeriodWorkContext $accompanyingPeriodWorkContext,
EntityManagerInterface $em,
EvaluationRepository $evaluationRepository,
NormalizerInterface $normalizer,
TranslatableStringHelperInterface $translatableStringHelper
TranslatableStringHelperInterface $translatableStringHelper,
ThirdPartyRender $thirdPartyRender,
TranslatorInterface $translator
) {
$this->accompanyingPeriodWorkContext = $accompanyingPeriodWorkContext;
$this->em = $em;
$this->evaluationRepository = $evaluationRepository;
$this->normalizer = $normalizer;
$this->translatableStringHelper = $translatableStringHelper;
$this->thirdPartyRender = $thirdPartyRender;
$this->translator = $translator;
}
public function adminFormReverseTransform(array $data): array
@@ -102,6 +115,31 @@ class AccompanyingPeriodWorkEvaluationContext implements
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
{
$this->accompanyingPeriodWorkContext->buildPublicForm($builder, $template, $entity->getAccompanyingPeriodWork());
$thirdParties = [...array_values(array_filter($entity->getAccompanyingPeriodWork()->getThirdParties()->toArray())), ...array_values(array_filter([$entity->getAccompanyingPeriodWork()->getHandlingThierParty()])), ...array_values(
array_filter(
array_map(
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getAccompanyingPeriodWork()->getAccompanyingPeriod()->getResources()->filter(
static fn (Resource $r): bool => null !== $r->getThirdParty()
)->toArray()
)
)
)];
$options = $template->getOptions();
if ($options['thirdParty'] ?? false) {
$builder->add('thirdParty', EntityType::class, [
'class' => ThirdParty::class,
'choices' => $thirdParties,
'choice_label' => fn (ThirdParty $p) => $this->thirdPartyRender->renderString($p, []),
'multiple' => false,
'required' => false,
'expanded' => true,
'label' => $options['thirdPartyLabel'],
'placeholder' => $this->translator->trans('Any third party selected'),
]);
}
}
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
@@ -116,7 +154,6 @@ class AccompanyingPeriodWorkEvaluationContext implements
AbstractNormalizer::GROUPS => ['docgen:read'],
]
);
return $data;
}

View File

@@ -26,14 +26,22 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Person\PersonResource;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use LogicException;
use Service\DocGenerator\PersonContextTest;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
@@ -43,6 +51,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
use function count;
/**
* @see PersonContextTest
*/
final class PersonContext implements PersonContextInterface
{
private AuthorizationHelperInterface $authorizationHelper;
@@ -67,6 +78,12 @@ final class PersonContext implements PersonContextInterface
private TranslatorInterface $translator;
private ThirdPartyRender $thirdPartyRender;
private ThirdPartyRepository $thirdPartyRepository;
private ResidentialAddressRepository $residentialAddressRepository;
public function __construct(
AuthorizationHelperInterface $authorizationHelper,
BaseContextData $baseContextData,
@@ -78,7 +95,10 @@ final class PersonContext implements PersonContextInterface
ScopeRepositoryInterface $scopeRepository,
Security $security,
TranslatorInterface $translator,
TranslatableStringHelperInterface $translatableStringHelper
TranslatableStringHelperInterface $translatableStringHelper,
ThirdPartyRender $thirdPartyRender,
ThirdPartyRepository $thirdPartyRepository,
ResidentialAddressRepository $residentialAddressRepository
) {
$this->authorizationHelper = $authorizationHelper;
$this->centerResolverManager = $centerResolverManager;
@@ -91,6 +111,9 @@ final class PersonContext implements PersonContextInterface
$this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes'];
$this->translator = $translator;
$this->translatableStringHelper = $translatableStringHelper;
$this->thirdPartyRender = $thirdPartyRender;
$this->thirdPartyRepository = $thirdPartyRepository;
$this->residentialAddressRepository = $residentialAddressRepository;
}
public function adminFormReverseTransform(array $data): array
@@ -110,11 +133,12 @@ final class PersonContext implements PersonContextInterface
$r = [
'mainPerson' => $data['mainPerson'] ?? false,
'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
'thirdParty' => $data['thirdParty'] ?? false,
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('Third party'),
];
if (array_key_exists('category', $data)) {
$r['category'] = array_key_exists('category', $data) ?
$this->documentCategoryRepository->find($data['category']) : null;
$r['category'] = $this->documentCategoryRepository->find($data['category']);
}
return $r;
@@ -131,6 +155,14 @@ final class PersonContext implements PersonContextInterface
->setParameter('docClass', PersonDocument::class),
'choice_label' => fn ($entity = null) => $entity ? $this->translatableStringHelper->localize($entity->getName()) : '',
'required' => true,
])
->add('thirdParty', CheckboxType::class, [
'required' => false,
'label' => 'docgen.Ask for thirdParty',
])
->add('thirdPartyLabel', TextType::class, [
'label' => 'docgen.thirdParty label',
'required' => true,
]);
}
@@ -139,12 +171,47 @@ final class PersonContext implements PersonContextInterface
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
{
$options = $template->getOptions();
$builder->add('title', TextType::class, [
'required' => true,
'label' => 'docgen.Document title',
'data' => $this->translatableStringHelper->localize($template->getName()),
]);
$thirdParties = [...array_values(
array_filter(
array_map(
fn (ResidentialAddress $r): ?ThirdParty => $r->getHostThirdParty(),
$this
->residentialAddressRepository
->findCurrentResidentialAddressByPerson($entity)
)
)
), ...array_values(
array_filter(
array_map(
fn (PersonResource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getResources()->filter(
static fn (PersonResource $r): bool => null !== $r->getThirdParty()
)->toArray()
)
)
)];
if ($options['thirdParty'] ?? false) {
$builder->add('thirdParty', EntityType::class, [
'class' => ThirdParty::class,
'choices' => $thirdParties,
'choice_label' => fn (ThirdParty $p) => $this->thirdPartyRender->renderString($p, []),
'multiple' => false,
'required' => false,
'expanded' => true,
'label' => $options['thirdPartyLabel'],
'placeholder' => $this->translator->trans('Any third party selected'),
]);
}
if ($this->isScopeNecessary($entity)) {
$builder->add('scope', ScopePickerType::class, [
'center' => $this->centerResolverManager->resolveCenters($entity),
@@ -156,10 +223,6 @@ final class PersonContext implements PersonContextInterface
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
{
if (!$entity instanceof Person) {
throw new UnexpectedTypeException($entity, Person::class);
}
$data = [];
$data = array_merge($data, $this->baseContextData->getData($contextGenerationData['creator'] ?? null));
$data['person'] = $this->normalizer->normalize($entity, 'docgen', [
@@ -170,6 +233,13 @@ final class PersonContext implements PersonContextInterface
'docgen:person:with-budget' => true,
]);
if ($template->getOptions()['thirdParty']) {
$data['thirdParty'] = $this->normalizer->normalize($contextGenerationData['thirdParty'], 'docgen', [
'docgen:expects' => ThirdParty::class,
'groups' => 'docgen:read'
]);
}
return $data;
}
@@ -223,6 +293,7 @@ final class PersonContext implements PersonContextInterface
return [
'title' => $data['title'] ?? '',
'scope_id' => $scope instanceof Scope ? $scope->getId() : null,
'thirdParty' => ($data['thirdParty'] ?? null)?->getId(),
];
}
@@ -242,6 +313,7 @@ final class PersonContext implements PersonContextInterface
return [
'title' => $data['title'] ?? '',
'scope' => $scope,
'thirdParty' => null !== ($id = ($data['thirdParty'] ?? null)) ? $this->thirdPartyRepository->find($id) : null,
];
}

View File

@@ -19,7 +19,8 @@ use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @template-extends DocGeneratorContextWithPublicFormInterface<Person>
* @template-extends DocGeneratorContextWithPublicFormInterface<Person>
* @template-extends DocGeneratorContextWithAdminFormInterface<Person>
*/
interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
{