mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
fixes: add tests for generation and fix some situation
This commit is contained in:
@@ -44,6 +44,7 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* @see AccompanyingPeriodContextTest
|
||||
* @template-implements DocGeneratorContextWithPublicFormInterface<AccompanyingPeriod>
|
||||
*/
|
||||
class AccompanyingPeriodContext implements
|
||||
@@ -116,12 +117,11 @@ class AccompanyingPeriodContext implements
|
||||
'person2' => $data['person2'] ?? false,
|
||||
'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
|
||||
'thirdParty' => $data['thirdParty'] ?? false,
|
||||
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('thirdParty'),
|
||||
'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;
|
||||
@@ -214,17 +214,15 @@ class AccompanyingPeriodContext implements
|
||||
}
|
||||
|
||||
$thirdParties = array_merge(
|
||||
array_filter(array_values([$entity->getRequestorThirdParty()])),
|
||||
array_filter(
|
||||
array_values(
|
||||
array_map(
|
||||
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
|
||||
$entity->getResources()->filter(
|
||||
static fn (Resource $r): bool => null !== $r->getThirdParty()
|
||||
)->toArray()
|
||||
)
|
||||
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) {
|
||||
@@ -320,7 +318,7 @@ class AccompanyingPeriodContext implements
|
||||
$normalized[$k] = null !== ($data[$k] ?? null) ? $data[$k]->getId() : null;
|
||||
}
|
||||
|
||||
$normalized['thirdParty'] = null === $data['thirdParty'] ? null : $data['thirdParty']->getId();
|
||||
$normalized['thirdParty'] = ($data['thirdParty'] ?? null)?->getId();
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
@@ -117,10 +117,10 @@ class AccompanyingPeriodWorkEvaluationContext implements
|
||||
$this->accompanyingPeriodWorkContext->buildPublicForm($builder, $template, $entity->getAccompanyingPeriodWork());
|
||||
|
||||
$thirdParties = array_merge(
|
||||
array_filter(array_values($entity->getAccompanyingPeriodWork()->getThirdParties()->toArray())),
|
||||
array_filter(array_values([$entity->getAccompanyingPeriodWork()->getHandlingThierParty()])),
|
||||
array_filter(
|
||||
array_values(
|
||||
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(
|
||||
|
@@ -38,6 +38,7 @@ 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;
|
||||
@@ -50,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;
|
||||
@@ -130,12 +134,11 @@ final class PersonContext implements PersonContextInterface
|
||||
'mainPerson' => $data['mainPerson'] ?? false,
|
||||
'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
|
||||
'thirdParty' => $data['thirdParty'] ?? false,
|
||||
'thirdPartyLabel' => $data['thirdPartyLabel'] ?? $this->translator->trans('thirdParty'),
|
||||
'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;
|
||||
@@ -177,8 +180,8 @@ final class PersonContext implements PersonContextInterface
|
||||
]);
|
||||
|
||||
$thirdParties = array_merge(
|
||||
array_filter(
|
||||
array_values(
|
||||
array_values(
|
||||
array_filter(
|
||||
array_map(
|
||||
fn (ResidentialAddress $r): ?ThirdParty => $r->getHostThirdParty(),
|
||||
$this
|
||||
@@ -187,8 +190,8 @@ final class PersonContext implements PersonContextInterface
|
||||
)
|
||||
)
|
||||
),
|
||||
array_filter(
|
||||
array_values(
|
||||
array_values(
|
||||
array_filter(
|
||||
array_map(
|
||||
fn (PersonResource $r): ?ThirdParty => $r->getThirdParty(),
|
||||
$entity->getResources()->filter(
|
||||
@@ -223,10 +226,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', [
|
||||
@@ -297,7 +296,7 @@ final class PersonContext implements PersonContextInterface
|
||||
return [
|
||||
'title' => $data['title'] ?? '',
|
||||
'scope_id' => $scope instanceof Scope ? $scope->getId() : null,
|
||||
'thirdParty' => null === $data['thirdParty'] ? null : $data['thirdParty']->getId(),
|
||||
'thirdParty' => ($data['thirdParty'] ?? null)?->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user